diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/__init__.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..5bbb84cf8fa1a2029e0dd7f06215749f55bb2833 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/__init__.py @@ -0,0 +1,39 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# 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 . + +"""Contexts allow you to classify when geometry should be used in different +purposes + +For example, a door may have many geometries assigned to it: a 3D body +geometry, a clearance zone for disabled access and egress, and a 2D top down +plan view representation annotating swing extents. Each geometry is assigned to +a context to distinguish its purpose and level of detail. +""" + +from .. import wrap_usecases +from .add_context import add_context +from .edit_context import edit_context +from .remove_context import remove_context + +wrap_usecases(__path__, __name__) + +__all__ = [ + "add_context", + "edit_context", + "remove_context", +] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/add_context.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/add_context.py new file mode 100644 index 0000000000000000000000000000000000000000..a1a7839e09598603c8e27e5654c63fbb617a964f --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/add_context.py @@ -0,0 +1,239 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.representation +from typing import Optional, Any + + +def add_context( + file: ifcopenshell.file, + context_type: Optional[ifcopenshell.util.representation.CONTEXT_TYPE] = None, + context_identifier: Optional[ifcopenshell.util.representation.REPRESENTATION_IDENTIFIER] = None, + target_view: Optional[ifcopenshell.util.representation.TARGET_VIEW] = None, + target_scale: Optional[float] = None, + parent: Optional[ifcopenshell.entity_instance] = None, +) -> ifcopenshell.entity_instance: + """Adds a new geometric representation context + + In IFC, physical objects may have zero, one, or multiple geometric + representations associated with it. For example, a building storey might + not have any geometry, but simply be a coordinate in space. + Alternatively, a wall might have a 3D body representation in the form of + a cuboid. As a final example, a door might also have a 3D body + representation of a 3D door panel and door frame, but may additionally + have a 2D door plan view representation of the door swing, and even a 2D + elevation view of the door, a 3D box representing the disabled clearance + zone of the door, a 2D profile representing the profile of the door to + cut out in a wall, and so on. In this situation, a door will have + multiple geometric representations. + + To distinguish between the different purposes of multiple geometric + representations, each geometric representation must belong to a + geometric representation "context". There are typically always 2 + contexts, one for 3D representations and one for 2D representations. + These 2 contexts then have subcontexts for things like the 3D body + representation, clearance representations, annotation representations, + and so on. Each representation of a physical IFC product (e.g. a door) + must be assigned to one of these subcontexts. Therefore setting up + appropriate contexts is critical prior to authoring any IFC model which + contains geometry. + + There are two steps to setting up appropriate subcontexts. First, a 2D + and/or 3D context must be added. These must be always called the "Model" + context for 3D and the "Plan" context for 2D (even if the 2D geometry is + not a plan view). Then, one or more subcontexts are added using either + the "Model" or "Plan" as their parent. These subcontexts are further + distinguished using an "identifier" and "target view". The "identifier" + describes the purpose of the representation, and the "target view" + describes the typical diagrammatic presentation that context's geometry + should be viewed in. The most common identifiers you might use are: + + - Body: for the actual shape of the object + - Box: the bounding box of the object (useful for shape analytics) + - Axis: the parametric line determining the shape of the object + - Profile: the elevation silhouette of the object, useful for cutting + out holes for the object to fit into host elements + - Footprint: the plan view silhouette of the object, useful for certain + quantity take-off rules + - Clearance: the clearance zone of the object + - Annotation: symbolic annotations typically used in diagrams or + drawings + + The most common "target views" you might use are: + + - MODEL_VIEW: for 3D geometry you might see in a BIM viewer + - PLAN_VIEW: for 2D geometry you might see in a plan representation + - ELEVATION_VIEW: for 2D geometry you might see in an elevation representation + - SECTION_VIEW: for 2D geometry you might see in a section representation + - GRAPH_VIEW: for 2D or 3D line or frame or path connectivity diagrams + you might use for structural frame analysis, axis-based parametric + modeling + - SKETCH_VIEW: for viewing abstract high-level representations such as + in bubble diagrams of spatial topology + + This may sound like a lot, but after a few typical contexts are set up + at the beginning, it becomes easy to navigate and isolate geometry for + different purposes. There is also the concept of a target scale, which + represents the zoom level detail of geometry, but this is not currently + supported by this API. Setting up all these contexts are also optional, + and you may only use a single Model context and Body subcontext for + simple models, but this simplification sacrifices the ability of more + parametric or analytical usecases. + + :param context_type: The type of the context, must be one of "Model" or + "Plan" only. + :param context_identifier: The identifier of the context, chosen from + one of the common identifiers above or consult the IFC documentation + (under the IfcShapeRepresentation page) for more details. Optional + for contexts, but mandatory for subcontexts. + :param target_view: the target view of the context, chosen from one of + the common target views above or consult the IFC documentation + (under the IfcShapeRepresentation page) for more details. Optional + for contexts, but mandatory for subcontexts. + :param target_scale: It defines the intended scale at which the representation + is designed to be viewed or printed + :param parent: the parent context. Must be left as None (the default) + for contexts, and only set for subcontexts. Note that there are only + contexts and subcontexts, a subcontext cannot have any children. + :return: the newly created IfcGeometricRepresentationContext or + IfcGeometricRepresentationSubContext entity + + Example: + + .. code:: python + + # If we plan to store 3D geometry in our IFC model, we have to setup + # a "Model" context. + model3d = ifcopenshell.api.context.add_context(model, context_type="Model") + + # And/Or, if we plan to store 2D geometry, we need a "Plan" context + plan = ifcopenshell.api.context.add_context(model, context_type="Plan") + + # Now we setup the subcontexts with each of the geometric "purposes" + # we plan to store in our model. "Body" is by far the most important + # and common context, as most IFC models are assumed to be viewable + # in 3D. + body = ifcopenshell.api.context.add_context(model, + context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d) + + # The 3D Axis subcontext is important if any "axis-based" parametric + # geometry is going to be created. For example, a beam, or column + # may be drawn using a single 3D axis line, and for this we need an + # Axis subcontext. + ifcopenshell.api.context.add_context(model, + context_type="Model", context_identifier="Axis", target_view="GRAPH_VIEW", parent=model3d) + + # The 3D Box subcontext is useful for clash detection or shape + # analysis, or even lazy-loading of large models. + ifcopenshell.api.context.add_context(model, + context_type="Model", context_identifier="Box", target_view="MODEL_VIEW", parent=model3d) + + # It's also important to have a 2D Axis subcontext for things like + # walls and claddings which can be drawn using a 2D axis line. + ifcopenshell.api.context.add_context(model, + context_type="Plan", context_identifier="Axis", target_view="GRAPH_VIEW", parent=plan) + + # A 2D annotation subcontext for plan views are important for door + # swings, window cuts, and symbols for equipment like GPOs, fire + # extinguishers, and so on. + ifcopenshell.api.context.add_context(model, + context_type="Plan", context_identifier="Annotation", target_view="PLAN_VIEW", parent=plan) + + # You may also create 2D annotation subcontexts for sections and + # elevation views. + ifcopenshell.api.context.add_context(model, + context_type="Plan", context_identifier="Annotation", target_view="SECTION_VIEW", parent=plan) + ifcopenshell.api.context.add_context(model, + context_type="Plan", context_identifier="Annotation", target_view="ELEVATION_VIEW", parent=plan) + + # Let's create a new wall. The wall does not have any geometry yet. + wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") + + # Let's use the "3D Body" representation we created earlier to add a + # new wall-like body geometry, 5 meters long, 3 meters high, and + # 200mm thick + representation = ifcopenshell.api.geometry.add_wall_representation(model, + context=body, length=5, height=3, thickness=0.2) + + # Assign our new body geometry back to our wall + ifcopenshell.api.geometry.assign_representation(model, + product=wall, representation=representation) + + # Place our wall at the origin + ifcopenshell.api.geometry.edit_object_placement(model, product=wall) + """ + usecase = Usecase() + usecase.file = file + usecase.settings = { + "context_type": context_type, + "parent": parent, + "context_identifier": context_identifier, + "target_view": target_view, + "target_scale": target_scale, + } + return usecase.execute() + + +class Usecase: + file: ifcopenshell.file + settings: dict[str, Any] + + def execute(self): + if not self.settings["parent"]: + if self.settings["context_type"] == "Plan": + self.create_2d_origin() + context = self.file.createIfcGeometricRepresentationContext(None, "Plan", 2, 1.0e-05, self.origin) + else: + self.create_3d_origin() + context = self.file.createIfcGeometricRepresentationContext( + None, self.settings["context_type"], 3, 1.0e-05, self.origin + ) + + project = self.file.by_type("IfcProject")[0] + + if project.RepresentationContexts: + contexts = list(project.RepresentationContexts) + else: + contexts = [] + contexts.append(context) + project.RepresentationContexts = contexts + return context + return self.file.create_entity( + "IfcGeometricRepresentationSubContext", + **{ + "ContextIdentifier": self.settings["context_identifier"], + "ContextType": self.settings["context_type"], + "ParentContext": self.settings["parent"], + "TargetView": self.settings["target_view"], + "TargetScale": self.settings["target_scale"], + } + ) + + def create_3d_origin(self): + self.origin = self.file.createIfcAxis2Placement3D( + self.file.createIfcCartesianPoint((0.0, 0.0, 0.0)), + self.file.createIfcDirection((0.0, 0.0, 1.0)), + self.file.createIfcDirection((1.0, 0.0, 0.0)), + ) + + def create_2d_origin(self): + self.origin = self.file.createIfcAxis2Placement2D( + self.file.createIfcCartesianPoint((0.0, 0.0)), + self.file.createIfcDirection((1.0, 0.0)), + ) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/edit_context.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/edit_context.py new file mode 100644 index 0000000000000000000000000000000000000000..1a7d567c58799d762fa6caa1959ef2fbfd135094 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/edit_context.py @@ -0,0 +1,48 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +from typing import Any + + +def edit_context(file: ifcopenshell.file, context: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcGeometricRepresentationContext + + For more information about the attributes and data types of an + IfcGeometricRepresentationContext, consult the IFC documentation. + + :param context: The IfcGeometricRepresentationContext entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + model = ifcopenshell.api.context.add_context(model, context_type="Model") + # Revit had a bug where they incorrectly called the body representation a "Facetation" + body = ifcopenshell.api.context.add_context(model, + context_type="Model", context_identifier="Facetation", target_view="MODEL_VIEW", parent=model + ) + + # Let's fix it! + ifcopenshell.api.context.edit_context(model, + context=body, attributes={"ContextIdentifier": "Body"}) + """ + for name, value in attributes.items(): + setattr(context, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/remove_context.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/remove_context.py new file mode 100644 index 0000000000000000000000000000000000000000..bb4dcff79a1a4a8079c6404cbd8701693d48dffa --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/remove_context.py @@ -0,0 +1,65 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.context +import ifcopenshell.api.geometry +import ifcopenshell.util.element + + +def remove_context(file: ifcopenshell.file, context: ifcopenshell.entity_instance) -> None: + """Removes an IfcGeometricRepresentationContext + + Any representation geometry that is assigned to the context is also + removed. If a context is removed, then any subcontexts are also removed. + + :param context: The IfcGeometricRepresentationContext entity to remove + :return: None + + Example: + + .. code:: python + + model = ifcopenshell.api.context.add_context(model, context_type="Model") + # Revit had a bug where they incorrectly called the body representation a "Facetation" + body = ifcopenshell.api.context.add_context(model, + context_type="Model", context_identifier="Facetation", target_view="MODEL_VIEW", parent=model + ) + + # Let's just get rid of it completely + ifcopenshell.api.context.remove_context(model, context=body) + """ + for subcontext in context.HasSubContexts: + ifcopenshell.api.context.remove_context(file, context=subcontext) + + if getattr(context, "ParentContext", None): + new = context.ParentContext + for inverse in file.get_inverse(context): + if inverse.is_a("IfcCoordinateOperation"): + inverse.SourceCRS = inverse.TargetCRS + ifcopenshell.util.element.remove_deep(file, inverse) + else: + ifcopenshell.util.element.replace_attribute(inverse, context, new) + file.remove(context) + else: + representations_in_context = context.RepresentationsInContext + file.remove(context) + for rep in representations_in_context: + for element in ifcopenshell.util.element.get_elements_by_representation(file, rep): + ifcopenshell.api.geometry.unassign_representation(file, product=element, representation=rep) + ifcopenshell.api.geometry.remove_representation(file, representation=rep) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/__init__.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..a70ffb0c4c7e76004568106bbd86827f7cd919aa --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/__init__.py @@ -0,0 +1,47 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# 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 . + +"""Manage references to external libraries + +An external library is any system which uses a key to store information. This +allows you to associate IFC entities with any arbitrary external database, API, +system, and so on. This is typically useful in smart building systems. +""" + +from .. import wrap_usecases +from .add_library import add_library +from .add_reference import add_reference +from .assign_reference import assign_reference +from .edit_library import edit_library +from .edit_reference import edit_reference +from .remove_library import remove_library +from .remove_reference import remove_reference +from .unassign_reference import unassign_reference + +wrap_usecases(__path__, __name__) + +__all__ = [ + "add_library", + "add_reference", + "assign_reference", + "edit_library", + "edit_reference", + "remove_library", + "remove_reference", + "unassign_reference", +] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_library.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_library.py new file mode 100644 index 0000000000000000000000000000000000000000..a8ce0690d493d71fc919cc747891d07e1fc42fa8 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_library.py @@ -0,0 +1,61 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.schema +import ifcopenshell.util.date + + +def add_library(file: ifcopenshell.file, name: str) -> ifcopenshell.entity_instance: + """Adds a new library to the project + + A library is an external data source that is related to the project. It + may be a database, a spreadsheet, an API, or even a stack of papers in a + filing cabinet. This allows IFC data to store relationships to these + external data sources. + + For example, you may have a list of laser scans of a site stored in an + online platform, which can be queried using an API. Or, you might have a + database of live building sensor data. So long as there is a clear + identifier you can use to link the two datasets together, you can create + a relationship. + + Note that IFC does not store any instructions on how to access the + library. It does not specify whether a HTTP request or database + connection needs to be made or what protocol the library operates with. + Until this is fleshed out further, it is the users responsibility to + name the libraries consistently and use appropriate identifiers. For + example, if you are linking IFC data and Brickschema data, use a full + URI for the identifier with no abbreviation (e.g. + 'http://example.org/digitaltwin#AHU01', not 'digitaltwin:AHU01'). + + A library will then contain a list of references within that library. + These references will then be related to IFC elements. For example, a + library will represent an external database, and a reference will point + to a particular table and row within that database. + + :param name: The name of the library + :return: The newly created IfcLibraryInformation + + Example: + + .. code:: python + + ifcopenshell.api.library.add_library(model, name="Brickschema") + """ + return file.create_entity("IfcLibraryInformation", Name=name) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_reference.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_reference.py new file mode 100644 index 0000000000000000000000000000000000000000..4f340768241e989952f79598f9f892eda37fa50a --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_reference.py @@ -0,0 +1,57 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell + + +def add_reference(file: ifcopenshell.file, library: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + """Adds a new reference to a library + + A library represents an external data source, such as a database, + spreadsheet, API, or something else that contains information related to + the IFC project. Within a library, there will be one or more references, + such as reference to a particular table or row in a database, or a sheet + and row or column in a spreadsheet, a URI in a linked data Brickschema + file, 32-bit decimal BACnetObjectIdentifier in a BACnet system, IP + address in a network, and so on. + + These references can then be related to IFC elements. You cannot relate + an IFC element directly to a library, it must be related to one of the + library's references. + + :param library: The IfcLibraryInformation element to add a reference to + :return: The newly created IfcLibraryReference element + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + + # Let's create a reference to a single AHU in our Brickschema dataset + reference = ifcopenshell.api.library.add_reference(model, library=library) + ifcopenshell.api.library.edit_reference(model, + reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"}) + """ + if file.schema == "IFC2X3": + reference = file.createIfcLibraryReference() + references = list(library.LibraryReference or []) + references.append(reference) + library.LibraryReference = references + return reference + return file.createIfcLibraryReference(ReferencedLibrary=library) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/assign_reference.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/assign_reference.py new file mode 100644 index 0000000000000000000000000000000000000000..a9b616930498009356f6a9a837f9fce9cf47f363 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/assign_reference.py @@ -0,0 +1,89 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.owner +import ifcopenshell.guid +import ifcopenshell.util.element +from typing import Union + + +def assign_reference( + file: ifcopenshell.file, products: ifcopenshell.entity_instance, reference: ifcopenshell.entity_instance +) -> Union[ifcopenshell.entity_instance, None]: + """Associates a list products with a library reference + + A product may be associated with zero, one, or many references across + multiple libraries. See ifcopenshell.api.library.add_reference for more + detail about how references work. + + :param products: The list of IfcProducts you want to associate with the reference + :param reference: The IfcLibraryReference you want the product to be + associated with. + :return: The IfcRelAssociatesLibrary relationship entity + or `None` if `products` was an empty list or all products were + already assigned to the `reference`. + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + + # Let's create a reference to a single AHU in our Brickschema dataset + reference = ifcopenshell.api.library.add_reference(model, library=library) + ifcopenshell.api.library.edit_reference(model, + reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"}) + + # Let's assume we have an AHU in our model. + ahu = ifcopenshell.api.root.create_entity(model, + ifc_class="IfcUnitaryEquipment", predefined_type="AIRHANDLER") + + # And now assign the IFC model's AHU with its Brickschema counterpart + ifcopenshell.api.library.assign_reference(model, reference=reference, products=[ahu]) + """ + # TODO: do we need to support non-ifcroot elements like we do in classification.add_reference? + + referenced_elements = ifcopenshell.util.element.get_referenced_elements(reference) + products_set: set[ifcopenshell.entity_instance] = set(products) + products_set = products_set - referenced_elements + + if not products_set: + return + + if file.schema == "IFC2X3": + rel = next( + (r for r in file.by_type("IfcRelAssociatesLibrary") if r.RelatingLibrary == reference), + None, + ) + else: + rel = next(iter(reference.LibraryRefForObjects), None) + + if not rel: + return file.create_entity( + "IfcRelAssociatesLibrary", + GlobalId=ifcopenshell.guid.new(), + OwnerHistory=ifcopenshell.api.owner.create_owner_history(file), + RelatedObjects=list(products_set), + RelatingLibrary=reference, + ) + + related_objects = set(rel.RelatedObjects) | products_set + rel.RelatedObjects = list(related_objects) + ifcopenshell.api.owner.update_owner_history(file, element=rel) + return rel diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_library.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_library.py new file mode 100644 index 0000000000000000000000000000000000000000..4e12195bda237da37f36d2996399819748111428 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_library.py @@ -0,0 +1,55 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +import ifcopenshell.util.date +import datetime +from typing import Any + + +def edit_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcLibraryInformation + + For more information about the attributes and data types of an + IfcLibraryInformation, consult the IFC documentation. + + :param library: The IfcLibraryInformation entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + ifcopenshell.api.library.edit_library(model, library=library, + attributes={"Description": "A Brickschema TTL including only mechanical distribution systems."}) + """ + + if "VersionDate" in attributes: + dt = attributes["VersionDate"] + if isinstance(dt, datetime.datetime): + if file.schema != "IFC2X3": + dt = ifcopenshell.util.date.datetime2ifc(dt, "IfcDateTime") + else: + calendar_date = ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate") + dt = file.create_entity("IfcCalendarDate", **calendar_date) + attributes = attributes.copy() + attributes["VersionDate"] = dt + + for name, value in attributes.items(): + setattr(library, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_reference.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_reference.py new file mode 100644 index 0000000000000000000000000000000000000000..e6acacbd8f97ea766373320a11515e3ac999c08c --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_reference.py @@ -0,0 +1,45 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_reference( + file: ifcopenshell.file, reference: ifcopenshell.entity_instance, attributes: dict[str, Any] +) -> None: + """Edits the attributes of an IfcLibraryReference + + For more information about the attributes and data types of an + IfcLibraryReference, consult the IFC documentation. + + :param reference: The IfcLibraryReference entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + # Let's create a reference to a single AHU in our Brickschema dataset + reference = ifcopenshell.api.library.add_reference(model, library=library) + ifcopenshell.api.library.edit_reference(model, + reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"}) + """ + for name, value in attributes.items(): + setattr(reference, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_library.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_library.py new file mode 100644 index 0000000000000000000000000000000000000000..da86935830142e754026d8596bdd86e6ddaaf57e --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_library.py @@ -0,0 +1,58 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.element + + +def remove_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance) -> None: + """Removes a library + + All references along with their relationships will also be removed. Any + products which have relationships to this library will not be removed. + + :param library: The IfcLibraryInformation entity you want to remove + :return: None + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + ifcopenshell.api.library.remove_library(model, library=library) + """ + + if file.schema != "IFC2X3": + rels = [] + for reference in set(library.HasLibraryReferences): + rels.extend(reference.LibraryRefForObjects) + file.remove(reference) + rels.extend(library.LibraryInfoForObjects) + file.remove(library) + else: + for reference in set(library.LibraryReference or []): + file.remove(reference) + file.remove(library) + # RelatingLibrary could either be library itself or library reference we removed + rels = [rel for rel in file.by_type("IfcRelAssociatesLibrary") if rel.RelatingLibrary is None] + + for rel in rels: + history = rel.OwnerHistory + file.remove(rel) + if history: + ifcopenshell.util.element.remove_deep2(file, history) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_reference.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_reference.py new file mode 100644 index 0000000000000000000000000000000000000000..7c7027cf5952ac51293de794620473c23741c66b --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_reference.py @@ -0,0 +1,51 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.element + + +def remove_reference(file: ifcopenshell.file, reference: ifcopenshell.entity_instance) -> None: + """Removes a library reference + + Any products which have relationships to this reference will not be + removed. + + :param reference: The IfcLibraryReference entity you want to remove + :return: None + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + reference = ifcopenshell.api.library.add_reference(model, library=library) + # Let's change our mind and remove it. + ifcopenshell.api.library.remove_reference(model, reference=reference) + """ + if file.schema != "IFC2X3": + rels = reference.LibraryRefForObjects + else: + rels = [rel for rel in file.by_type("IfcRelAssociatesLibrary") if rel.RelatingLibrary == reference] + + for rel in rels: + history = rel.OwnerHistory + file.remove(rel) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + file.remove(reference) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/unassign_reference.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/unassign_reference.py new file mode 100644 index 0000000000000000000000000000000000000000..5dd40749b9625ed92e928083a7f1e17125f5028b --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/unassign_reference.py @@ -0,0 +1,78 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.element +import ifcopenshell.api.owner + + +def unassign_reference( + file: ifcopenshell.file, + reference: ifcopenshell.entity_instance, + products: list[ifcopenshell.entity_instance], +) -> None: + """Unassigns a product of products from a reference + + If the product isn't assigned to the reference, nothing will happen. + + :param reference: The IfcLibraryReference to unassign from + :param products: A list of IfcProduct elements to unassign from the reference + :return: None + + Example: + + .. code:: python + + library = ifcopenshell.api.library.add_library(model, name="Brickschema") + + # Let's create a reference to a single AHU in our Brickschema dataset + reference = ifcopenshell.api.library.add_reference(model, library=library) + ifcopenshell.api.library.edit_reference(model, + reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"}) + + # Let's assume we have an AHU in our model. + ahu = ifcopenshell.api.root.create_entity(model, + ifc_class="IfcUnitaryEquipment", predefined_type="AIRHANDLER") + + # And now assign the IFC model's AHU with its Brickschema counterpart + ifcopenshell.api.library.assign_reference(model, reference=reference, products=[ahu]) + + # Let's change our mind and unassign it. + ifcopenshell.api.library.unassign_reference(model, reference=reference, products=[ahu]) + """ + # TODO: do we need to support non-ifcroot elements like we do in classification.add_reference? + + reference_rels: set[ifcopenshell.entity_instance] = set() + products_set = set(products) + for product in products_set: + reference_rels.update(product.HasAssociations) + + reference_rels = { + rel for rel in reference_rels if rel.is_a("IfcRelAssociatesLibrary") and rel.RelatingLibrary == reference + } + + for rel in reference_rels: + related_objects = set(rel.RelatedObjects) - products_set + if related_objects: + rel.RelatedObjects = list(related_objects) + ifcopenshell.api.owner.update_owner_history(file, element=rel) + else: + history = rel.OwnerHistory + file.remove(rel) + if history: + ifcopenshell.util.element.remove_deep2(file, history) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/__init__.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..f836c5bd4f61d7e20de50b1dfb95f6d6956f4dc9 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/__init__.py @@ -0,0 +1,89 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# 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 . + +"""Manage physical materials (concrete, steel, etc) and their association to +elements + +IFC supports both simple materials and parametric materials (materials that +have layered thicknesses or cross sectional profiles). + +Parametric materials will include parametric constraints on the geometry of +the element. These API functions do not cover that responsibility. See +:mod:`ifcopenshell.api.geometry`. + +Note that this API only covers physical materials, not visual styles. If you +want to look at visual styles such as colours, transparency, shading, or +rendering options, see :mod:`ifcopenshell.api.style`. +""" + +from .. import wrap_usecases +from .add_constituent import add_constituent +from .add_layer import add_layer +from .add_list_item import add_list_item +from .add_material import add_material +from .add_material_set import add_material_set +from .add_profile import add_profile +from .assign_material import assign_material +from .assign_profile import assign_profile +from .copy_material import copy_material +from .edit_assigned_material import edit_assigned_material +from .edit_constituent import edit_constituent +from .edit_layer import edit_layer +from .edit_layer_usage import edit_layer_usage +from .edit_material import edit_material +from .edit_profile import edit_profile +from .edit_profile_usage import edit_profile_usage +from .remove_constituent import remove_constituent +from .remove_layer import remove_layer +from .remove_list_item import remove_list_item +from .remove_material import remove_material +from .remove_material_set import remove_material_set +from .remove_profile import remove_profile +from .reorder_set_item import reorder_set_item +from .set_shape_aspect_constituents import set_shape_aspect_constituents +from .unassign_material import unassign_material + +wrap_usecases(__path__, __name__) + +__all__ = [ + "add_constituent", + "add_layer", + "add_list_item", + "add_material", + "add_material_set", + "add_profile", + "assign_material", + "assign_profile", + "copy_material", + "edit_assigned_material", + "edit_constituent", + "edit_layer", + "edit_layer_usage", + "edit_material", + "edit_profile", + "edit_profile_usage", + "remove_constituent", + "remove_layer", + "remove_list_item", + "remove_material", + "remove_material_set", + "remove_profile", + "reorder_set_item", + "set_shape_aspect_constituents", + "unassign_material", +] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_constituent.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_constituent.py new file mode 100644 index 0000000000000000000000000000000000000000..3a2dad4ba280d530fc7767dac7b4eebd8adc9810 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_constituent.py @@ -0,0 +1,91 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Optional + + +def add_constituent( + file: ifcopenshell.file, + constituent_set: ifcopenshell.entity_instance, + material: ifcopenshell.entity_instance, + name: Optional[str] = None, +) -> ifcopenshell.entity_instance: + """Adds a new constituent to a constituent set + + A constituent describes how a portion of an object is made out of a + material whereas other portions of the object is made out of other + materials. For example, a window might be made out of an aluminium frame + and a glass panel. The aluminium used for the frame is one constituent + of the material, and glass would be another constituent. Another example + might be concrete, where one constituent might be cement, and another + constituent might be binder. In the case of the window, the constituent + is represented explicitly by the geometry of the window frame and the + geometry of the window panel. In the case of a concrete slab, the + constituents might be represented in terms of percentages. + + Constituents are not available in IFC2X3. + + :param constituent_set: The IfcMaterialConstituentSet that the + constituent is part of. The constituent set represents a group of + constituents. See ifcopenshell.api.material.add_material_set for + information on how to add a constituent set. + :param material: The IfcMaterial that the constituent is made out of. + :param name: An optional name of the constituent. + :return: The newly created IfcMaterialConstituent + + Example: + + .. code:: python + + # Let's imagine we have a window type that has an aluminium frame + # and a glass glazing panel. Notice we are assigning to the type + # only, as all occurrences of that type will automatically inherit + # the material. + window_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWindowType") + + # First, let's create a constituent set. This will later be assigned + # to our window element. + material_set = ifcopenshell.api.material.add_material_set(model, + name="Window", set_type="IfcMaterialConstituentSet") + + # Let's create a few materials, it's important to also give them + # categories. This makes it easy for model recipients to do things + # like "show me everything made out of aluminium / concrete / steel + # / glass / etc". The IFC specification states a list of categories + # you can use. + aluminium = ifcopenshell.api.material.add_material(model, name="AL01", category="aluminium") + glass = ifcopenshell.api.material.add_material(model, name="GLZ01", category="glass") + + # Now let's use those materials as two constituents in our set. + ifcopenshell.api.material.add_constituent(model, + constituent_set=material_set, material=aluminium, name="Framing") + ifcopenshell.api.material.add_constituent(model, + constituent_set=material_set, material=glass, name="Glazing") + + # Great! Let's assign our material set to our window type. + # We're technically not done here, we might want to add geometry to + # our window too, but to keep this example simple, geometry is + # optional and it is enough to say that this window is made out of + # aluminium and glass. + ifcopenshell.api.material.assign_material(model, products=[window_type], material=material_set) + """ + constituents = list(constituent_set.MaterialConstituents or []) + constituent = file.create_entity("IfcMaterialConstituent", Material=material, Name=name) + constituents.append(constituent) + constituent_set.MaterialConstituents = constituents + return constituent diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_material.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_material.py new file mode 100644 index 0000000000000000000000000000000000000000..6b04f78be298dde308a5bbe9640238cc266cc3c9 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_material.py @@ -0,0 +1,85 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Optional + + +def add_material( + file: ifcopenshell.file, + name: Optional[str] = None, + category: Optional[str] = None, + description: Optional[str] = None, +) -> ifcopenshell.entity_instance: + """Adds a new material + + A material in IFC represents a physical material, such as timber, steel, + concrete, aluminium, etc. It may also contain physical properties used + for structural or lighting simulation. Note that unlike the computer + graphics industry, a material by itself does not define any colour or + lighting information. Colours in IFC are known as "styles", and an IFC + material may or may not have any style information associated with it. + See ifcopenshell.api.style for more information. + + A material is typically given a code name which is used by architects in + elevations and details when tagging finishes. Materials are also useful + to structural engineers in specifying the exact types of concrete and + steel to be used in structural simulations. + + In addition, materials can belong to a category. Specifying this + category is critical to allow model recipients to make simple queries + like "show me all concrete / steel" elements in the model. Without + standardised category naming of all materials, this type of query + becomes a bespoke and inefficient task. A list of categories are: + 'concrete', 'steel', 'aluminium', 'block', 'brick', 'stone', 'wood', + 'glass', 'gypsum', 'plastic', and 'earth'. The user is allowed to + specify their own category instead if none of these categories are + appropriate. + + Note that categories are not available in IFC2X3. This shortcoming is + one of the big reasons projects should upgrade to IFC4. + + Additionally, a material's description provides more information beyond + its name or category. + + :param name: The name of the material, typically tagged in a finishes + drawing or schedule. + :param category: The category of the material. + :param description: A description of the material. + :return: The newly created IfcMaterial + + Example: + + .. code:: python + + # Let's create two materials with their respective categories + concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete", description="Garage Slab") + steel = ifcopenshell.api.material.add_material(model, name="ST01", category="steel", description="Corten Steel") + + # Let's imagine an urban concrete bench which is purely made out of concrete + concrete_bench = ifcopenshell.api.root.create_entity(model, ifc_class="IfcFurnitureType") + + # Assign the concrete material to that bench. Note that no colour + # "Style" has been specified. + ifcopenshell.api.material.assign_material(model, products=[concrete_bench], material=concrete) + """ + material = file.create_entity("IfcMaterial", **{"Name": name or "Unnamed"}) + if category: + material.Category = category + if description: + material.Description = description + return material diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/copy_material.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/copy_material.py new file mode 100644 index 0000000000000000000000000000000000000000..d250ac742bcfc0df43cc8b1ec23d58ea85905046 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/copy_material.py @@ -0,0 +1,103 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.element + + +def copy_material(file: ifcopenshell.file, material: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + """Copies a material or material set + + All material psets and styles are copied. The copied material is not + associated to any elements. + + If a material set is copied, the set items are also copied. However the + underlying materials (and profiles) used within the set items are reused. + + If a material is associated with a presentation style, that presentation + style is reused. + + :param material: The IfcMaterialDefinition to copy + :return: The new copy of the material + + Example: + + .. code:: python + + concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete") + + # Let's duplicate the concrete material + concrete_copy = ifcopenshell.api.material.copy_material(model, material=concrete) + """ + if material.is_a("IfcMaterial"): + return _copy_material_with_inverses(file, material) + elif material.is_a("IfcMaterialConstituentSet"): + new = _copy_material_with_inverses(file, material) + new.MaterialConstituents = [copy_material(file, i) for i in material.MaterialConstituents] + return new + elif material.is_a("IfcMaterialConstituent"): + return _copy_material_with_inverses(file, material) + elif material.is_a("IfcMaterialLayerSet"): + new = _copy_material_with_inverses(file, material) + new.MaterialLayers = [copy_material(file, i) for i in material.MaterialLayers] + return new + elif material.is_a("IfcMaterialLayer"): + return _copy_material_with_inverses(file, material) + elif material.is_a("IfcMaterialProfileSet"): + new = _copy_material_with_inverses(file, material) + new.MaterialProfiles = [copy_material(file, i) for i in material.MaterialProfiles] + return new + elif material.is_a("IfcMaterialProfile"): + return _copy_material_with_inverses(file, material) + elif material.is_a("IfcMaterialList"): + return _copy_material_with_inverses(file, material) + else: + raise Exception(f"Unexpected material type: '{material.is_a()}' ({material}).") + + +def _copy_material_with_inverses( + file: ifcopenshell.file, material: ifcopenshell.entity_instance +) -> ifcopenshell.entity_instance: + new = ifcopenshell.util.element.copy(file, material) + for inverse in file.get_inverse(material): + if inverse.is_a("IfcMaterialProperties"): + # Properties must not be shared between objects for convenience of authoring + inverse = ifcopenshell.util.element.copy(file, inverse) + inverse.Material = new + + props_attribute = "Properties" + if file.schema == "IFC2X3": + if not inverse.is_a("IfcExtendedMaterialProperties"): + continue + props_attribute = "ExtendedProperties" + + props = getattr(inverse, props_attribute) + if not props: + continue + + copied_props = [] + for pset in props: + copied_props.append(ifcopenshell.util.element.copy_deep(file, pset)) + setattr(inverse, props_attribute, copied_props) + + elif inverse.is_a("IfcMaterialDefinitionRepresentation"): + inverse = ifcopenshell.util.element.copy_deep( + file, inverse, exclude=["IfcRepresentationContext", "IfcMaterial", "IfcPresentationStyle"] + ) + inverse.RepresentedMaterial = new + return new diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_constituent.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_constituent.py new file mode 100644 index 0000000000000000000000000000000000000000..a7398ca5f0b39c943be7870f8b6138dced001ef4 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_constituent.py @@ -0,0 +1,66 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Optional, Any + + +def edit_constituent( + file: ifcopenshell.file, + constituent: ifcopenshell.entity_instance, + attributes: Optional[dict[str, Any]] = None, + material: Optional[ifcopenshell.entity_instance] = None, +) -> None: + """Edits the attributes of an IfcMaterialConstituent + + For more information about the attributes and data types of an + IfcMaterialConstituent, consult the IFC documentation. + + :param constituent: The IfcMaterialConstituent entity you want to edit + :param attributes: a dictionary of attribute names and values. + :param material: The IfcMaterial entity you want to change the constituent to + :return: None + + Example: + + .. code:: python + + # Let's add two materials + aluminium1 = ifcopenshell.api.material.add_material(model, name="AL01", category="aluminium") + aluminium2 = ifcopenshell.api.material.add_material(model, name="AL02", category="aluminium") + glass = ifcopenshell.api.material.add_material(model, name="GLZ01", category="glass") + + material_set = ifcopenshell.api.material.add_material_set(model, + name="Window", set_type="IfcMaterialConstituentSet") + + # Set up two constituents, one for the frame and the other for the glazing. + framing = ifcopenshell.api.material.add_constituent(model, + constituent_set=material_set, material=aluminium1) + glazing = ifcopenshell.api.material.add_constituent(model, + constituent_set=material_set, material=glass) + + # Let's make sure this constituent refers to the framing of the + # window and uses the second aluminium material instead. + ifcopenshell.api.material.edit_constituent(model, + constituent=framing, attributes={"Name": "Framing"}, material=aluminium2) + + ifcopenshell.api.material.edit_constituent(model, + constituent=constituent, attributes={"Name": "Glazing"}) + """ + for name, value in (attributes or {}).items(): + setattr(constituent, name, value) + constituent.Material = material diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer.py new file mode 100644 index 0000000000000000000000000000000000000000..68f3c6d832f586a32b73cc6b0e2f55b6e29ff1d5 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer.py @@ -0,0 +1,65 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Optional, Any + + +def edit_layer( + file: ifcopenshell.file, + layer: ifcopenshell.entity_instance, + attributes: Optional[dict[str, Any]] = None, + material: Optional[ifcopenshell.entity_instance] = None, +) -> None: + """Edits the attributes of an IfcMaterialLayer + + For more information about the attributes and data types of an + IfcMaterialLayer, consult the IFC documentation. + + :param layer: The IfcMaterialLayer entity you want to edit + :param attributes: a dictionary of attribute names and values. + :param material: The IfcMaterial entity you want the layer to be made + from. + :return: None + + Example: + + .. code:: python + + # Let's create two materials typically used for steel stud partition + # walls with gypsum lining. + gypsum = ifcopenshell.api.material.add_material(model, name="PB01", category="gypsum") + steel = ifcopenshell.api.material.add_material(model, name="ST01", category="steel") + + # Create a material layer set to contain our layers. + material_set = ifcopenshell.api.material.add_material_set(model, + name="GYP-ST-GYP", set_type="IfcMaterialLayerSet") + + # Now let's use those materials as three layers in our set, such + # that the steel studs are sandwiched by the gypsum. Let's imagine + # we're setting the layer thickness in millimeters. + layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=gypsum) + ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 13}) + layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=steel) + ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 92}) + layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=gypsum) + ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 13}) + """ + for name, value in (attributes or {}).items(): + setattr(layer, name, value) + if material: + layer.Material = material diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer_usage.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer_usage.py new file mode 100644 index 0000000000000000000000000000000000000000..9d1ffb14ec94c57b97801d411dd71fd11119ec5a --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer_usage.py @@ -0,0 +1,76 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_layer_usage(file: ifcopenshell.file, usage: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcMaterialLayerSetUsage + + This is typically used to change the offset from the reference line to + the layers. + + For more information about the attributes and data types of an + IfcMaterialLayerSetUsage, consult the IFC documentation. + + :param usage: The IfcMaterialLayerSetUsage entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + # Let's start with a simple concrete material + concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete") + + # If we have a concrete wall, we should use a layer set. Again, + # let's start with a wall type, not occurrences. + wall_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType", name="WAL01") + + # Even though there is only one layer in our layer set, we still use + # a layer set because it makes it clear that this is a layered + # construction. Let's say it's a 200mm thick concrete layer. + material_set = ifcopenshell.api.material.add_material_set(model, + name="CON200", set_type="IfcMaterialLayerSet") + layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=steel) + ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 200}) + + # Our wall type now has the layer set assigned to it + ifcopenshell.api.material.assign_material(model, + products=[wall_type], type="IfcMaterialLayerSet", material=material_set) + + # Let's imagine an occurrence of this wall type. + wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") + ifcopenshell.api.type.assign_type(model, related_objects=[wall], relating_type=wall_type) + + # Our wall occurrence needs to have a "set usage" which describes + # how the layers relate to a reference line (typically a 2D line + # representing the extents of the wall). Usages are special since + # they automatically detect the inherited material set from the + # type. You'd write similar code for a profile set. + rel = ifcopenshell.api.material.assign_material(model, + products=[wall], type="IfcMaterialLayerSetUsage") + + # Let's change the offset from the reference line to be 200mm + # instead of the default of 0mm. + ifcopenshell.api.material.edit_layer_usage(model, + usage=rel.RelatingMaterial, attributes={"OffsetFromReferenceLine": 200}) + """ + for name, value in attributes.items(): + setattr(usage, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/remove_profile.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/remove_profile.py new file mode 100644 index 0000000000000000000000000000000000000000..1314bf209e09e0fc6f4a4e9bf347022e7466245a --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/remove_profile.py @@ -0,0 +1,80 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + + +import ifcopenshell.util.element + + +def remove_profile( + file: ifcopenshell.file, + profile: ifcopenshell.entity_instance, + should_remove_profile_def: bool = False, + should_remove_material: bool = False, +) -> None: + """Removes a profile item from a profile set + + Note that it is invalid to have zero items in a set, so you should leave + at least one profile to ensure a valid IFC dataset. + + :param profile: The IfcMaterialProfile entity you want to remove + :param should_remove_profile_def: If true, profile defs with no users will be removed + :param should_remove_material: If true, materials with no users will be removed + + Example: + + .. code:: python + + # First, let's create a material set. + material_set = ifcopenshell.api.material.add_material_set(model, + name="B1", set_type="IfcMaterialProfileSet") + + # Create a steel material. + steel = ifcopenshell.api.material.add_material(model, name="ST01", category="steel") + + # Create an I-beam profile curve. Notice how we name our profiles + # based on standardised steel profile names. + hea100 = file.create_entity( + "IfcIShapeProfileDef", ProfileName="HEA100", ProfileType="AREA", + OverallWidth=100, OverallDepth=96, WebThickness=5, FlangeThickness=8, FilletRadius=12, + ) + + # Define that steel material and cross section as a single profile item. + ifcopenshell.api.material.add_profile(model, + profile_set=material_set, material=steel, profile=hea100) + + # Imagine a welded square along the length of the profile. + welded_square = ifcopenshell.api.profile.add_arbitrary_profile(model, + profile=[(.0025, .0025), (.0325, .0025), (.0325, -.0025), (.0025, -.0025), (.0025, .0025)]) + weld_profile = ifcopenshell.api.material.add_profile(model, + profile_set=material_set, material=steel, profile=welded_square) + + # Let's remove our welded square. + ifcopenshell.api.material.remove_profile(model, profile=weld_profile) + """ + + subelements = set() + for attribute in profile: + if isinstance(attribute, ifcopenshell.entity_instance): + subelements.add(attribute) + file.remove(profile) + for subelement in subelements: + if subelement.is_a("IfcMaterial") and not should_remove_material: + continue + elif subelement.is_a("IfcProfileDef") and not should_remove_profile_def: + continue + ifcopenshell.util.element.remove_deep2(file, subelement) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/reorder_set_item.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/reorder_set_item.py new file mode 100644 index 0000000000000000000000000000000000000000..fd1ffc585ce157830bdbc7775bb138a96245edc0 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/reorder_set_item.py @@ -0,0 +1,69 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell + + +def reorder_set_item( + file: ifcopenshell.file, material_set: ifcopenshell.entity_instance, old_index: int = 0, new_index: int = 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. + + :param material_set: The IfcMaterialSet which you want to reorder an + item in. + :param old_index: The index of the item you want to move. This starts + counting from 0. + :param new_index: The index of the new position the item will move to. + This starts counting from 0. + :return: None + + Example: + + .. code:: python + + material_set = ifcopenshell.api.material.add_material_set(model, + name="Window", set_type="IfcMaterialList") + + aluminium = ifcopenshell.api.material.add_material(model, name="AL01", category="aluminium") + glass = ifcopenshell.api.material.add_material(model, name="GLZ01", category="glass") + + # Now let's use those materials as two items in our list. + ifcopenshell.api.material.add_list_item(model, material_list=material_set, material=aluminium) + ifcopenshell.api.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.material.reorder_set_item(model, + material_set=material_set, old_index=0, new_index=1) + """ + if material_set.is_a("IfcMaterialConstituentSet"): + set_name = "MaterialConstituents" + elif material_set.is_a("IfcMaterialLayerSet"): + set_name = "MaterialLayers" + elif material_set.is_a("IfcMaterialProfileSet"): + set_name = "MaterialProfiles" + elif material_set.is_a("IfcMaterialList"): + set_name = "Materials" + else: + raise ValueError(f"Unexpected material set type: '{material_set.is_a()}'.") + + items = list(getattr(material_set, set_name) or []) + items.insert(new_index, items.pop(old_index)) + setattr(material_set, set_name, items) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/__init__.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..6ecc13baf483143c345d9693a42423d1d394617b --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/__init__.py @@ -0,0 +1,55 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# 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 . + +"""Manage construction and maintenance resources + +Resources include equipment (cranes, etc), labour, material, and products. They +are typically referenced in construction planning, maintenance schedules, or +cost items. +""" + +from .. import wrap_usecases +from .add_resource import add_resource +from .add_resource_quantity import add_resource_quantity +from .add_resource_time import add_resource_time +from .assign_resource import assign_resource +from .calculate_resource_usage import calculate_resource_usage +from .calculate_resource_work import calculate_resource_work +from .edit_resource import edit_resource +from .edit_resource_quantity import edit_resource_quantity +from .edit_resource_time import edit_resource_time +from .remove_resource import remove_resource +from .remove_resource_quantity import remove_resource_quantity +from .unassign_resource import unassign_resource + +wrap_usecases(__path__, __name__) + +__all__ = [ + "add_resource", + "add_resource_quantity", + "add_resource_time", + "assign_resource", + "calculate_resource_usage", + "calculate_resource_work", + "edit_resource", + "edit_resource_quantity", + "edit_resource_time", + "remove_resource", + "remove_resource_quantity", + "unassign_resource", +] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..691ad2ec6aa174fffd756e3ab78a7a61e2d9b342 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource.py @@ -0,0 +1,88 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.api.root +import ifcopenshell.api.nest +import ifcopenshell.api.project +from typing import Optional + + +def add_resource( + file: ifcopenshell.file, + parent_resource: Optional[ifcopenshell.entity_instance] = None, + ifc_class: str = "IfcCrewResource", + name: Optional[str] = None, + predefined_type: str = "NOTDEFINED", +) -> ifcopenshell.entity_instance: + """Add a new construction resource + + Construction resources may be managed and connected to cost schedules + and construction schedules. This allows calculations to be done on + resource utilisation, cost optimisation (e.g. labour rates), and + optioneering on build strategies. + + There are typically two types of resources. Crew resources are resources + where you manage your own crew and you have full control over the + equipment, labour, products, and materials used by your crew. + Alternatively, there are subcontractor resources, where you simply + delegate all the details to a subcontractor and it is not decomposed + into further levels of detail. + + This means when adding resources, you'd first either add a crew or + subcontract resource. If it is a crew resource, you'd then add child + resources to that crew, such as equipment (cranes, excavators, hoists, + etc), material (wood, concrete, etc), and labour (rigging crews, + formworkers, etc). + + :param parent_resource: If this is a child resource (typically to a crew + resource), then nominate the parent IfcConstructionResource here. + :param ifc_class: The class of resource chosen from + IfcConstructionEquipmentResource, IfcConstructionMaterialResource, + IfcConstructionProductResource, IfcCrewResource, IfcLaborResource, + or IfcSubContractResource. + :param name: The name of the resource + :param predefined_type: Consult the IFC documentation for the valid + predefined types for each type of resource class. + :return: The newly created resource depending on the nominated IFC + class. + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some labour to our crew. + ifcopenshell.api.resource.add_resource(model, parent_resource=crew, ifc_class="IfcLaborResource") + """ + + resource = ifcopenshell.api.root.create_entity( + file, + ifc_class=ifc_class, + predefined_type=predefined_type, + name=name or "Unnamed", + ) + # TODO: this is an ambiguity by buildingSMART: Can we nest an IfcCrewResource under an IfcCrewResource ? + # https://forums.buildingsmart.org/t/what-are-allowed-to-be-root-level-construction-resources/3550 + if parent_resource: + ifcopenshell.api.nest.assign_object(file, related_objects=[resource], relating_object=parent_resource) + elif file.schema != "IFC2X3": + context = file.by_type("IfcContext")[0] + ifcopenshell.api.project.assign_declaration(file, definitions=[resource], relating_context=context) + return resource diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_quantity.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_quantity.py new file mode 100644 index 0000000000000000000000000000000000000000..fc67a8d3c7a963938c27d8d0dbd8d4f4672b641a --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_quantity.py @@ -0,0 +1,83 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.util.element +import ifcopenshell.util.resource + + +def add_resource_quantity( + file: ifcopenshell.file, resource: ifcopenshell.entity_instance, ifc_class: str = "IfcQuantityCount" +) -> ifcopenshell.entity_instance: + """Adds a quantity to a resource + + The quantity of a resource represents the "unit quantity" of that + resource. For example, labour might be hired on a daily basis (8 hours). + There are different types of quantities (e.g. volume, count, or time). + Which quantity is used depends on the type of resource. Material + resources may be quantified in terms of length, area, volume, or weight. + Equipment and labour resources are quantified in terms of time. Products + resources are quantified in terms of counts. + + This base quantity is then used in other calculations. + + :param resource: The IfcConstructionResource to add a quantity to. + :param ifc_class: The type of quantity to add, chosen from + IfcQuantityArea (for material), IfcQuantityCount (for products), + IfcQuantityLength (for material), IfcQuantityTime (for equipment or + labour), IfcQuantityVolume (for material), and IfcQuantityWeight + (for material). + :return: The newly created quantity depending on the IFC class + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some labour to our crew. + labour = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcLaborResource") + + # Labour resource is quantified in terms of time. + quantity = ifcopenshell.api.resource.add_resource_quantity(model, + resource=labour, ifc_class="IfcQuantityTime") + + # Store the time used in hours + ifcopenshell.api.resource.edit_resource_quantity(model, + physical_quantity=quantity, attributes={"TimeValue": 8.0}) + """ + resource_type = resource.is_a() + supported_quantities = ifcopenshell.util.resource.RESOURCES_TO_QUANTITIES[resource_type] + if ifc_class not in supported_quantities: + raise ValueError( + f"Resource type '{resource_type}' does not support quantity type '{ifc_class}'. " + f"Supported quantities: {','.join(supported_quantities)}" + ) + + quantity = file.create_entity(ifc_class, Name="Unnamed") + # 3 IfcPhysicalSimpleQuantity Value + if ifc_class == "IfcQuantityCount": + quantity[3] = 0 + else: + quantity[3] = 0.0 + old_quantity = resource.BaseQuantity + resource.BaseQuantity = quantity + if old_quantity: + ifcopenshell.util.element.remove_deep(file, old_quantity) + return quantity diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_time.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_time.py new file mode 100644 index 0000000000000000000000000000000000000000..a01405d9c6195df767356c6ab76d607f4d60ea33 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_time.py @@ -0,0 +1,59 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.util.date + + +def add_resource_time(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + """Adds the time that a resource is used for + + For labour and equipment resources, the total duration that the resource + is used for may be stored. This may either be input manually or + calculated parametrically. This is known as the resource time, and may + be used to calculate other parameters like resource utilisation. + + :param resource: The IfcConstructionResource to record time for. + :return: The newly created IfcResourceTime + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some labour to our crew. + labour = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcLaborResource") + + # Labour resource is quantified in terms of time. + quantity = ifcopenshell.api.resource.add_resource_quantity(model, + resource=labour, ifc_class="IfcQuantityTime") + + # Store the unit time used in hours + ifcopenshell.api.resource.edit_resource_quantity(model, + physical_quantity=quantity, attributes={"TimeValue": 8.0}) + + # Let's imagine we've used the resource for 2 days. + time = ifcopenshell.api.resource.add_resource_time(model, resource=labour) + ifcopenshell.api.resource.edit_resource_time(model, + resource_time=time, attributes={"ScheduleWork": "PT16H"}) + """ + resource_time = file.create_entity("IfcResourceTime") + resource.Usage = resource_time + return resource_time diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/assign_resource.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/assign_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..8ba19a650d3836ac4af0950171852beb23f31ad9 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/assign_resource.py @@ -0,0 +1,106 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.owner +import ifcopenshell.guid + + +def assign_resource( + file: ifcopenshell.file, + relating_resource: ifcopenshell.entity_instance, + related_object: ifcopenshell.entity_instance, +) -> ifcopenshell.entity_instance: + """Assigns a resource to an object + + Two types of objects are typically assigned to resources: products and + actors. + + If a product is assigned to a resource, that means that the product + represents the resource on site. This may be represented via material + handling zones on a construction site, or equipment like cranes and + their physical locations. + + If an actor is assigned to a resource, that means that the actor (person + or organisation) is the actor consuming the resource (e.g. if the + resource is material or equipment) or the actor performing the work + (e.g. if the resource is a labour resource). + + :param relating_resource: The IfcResource to assign the object to. + :param related_object: The IfcProduct or IfcActor to assign to the + object. + :return: The newly created IfcRelAssignsToResource + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some a tower crane to our crew. + crane = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcConstructionEquipmentResource", name="Tower Crane 01") + + # Our tower crane will be placed via this physical product. + product = ifcopenshell.api.root.create_entity(model, + ifc_class="IfcBuildingElementProxy", predefined_type="CRANE") + + # Let's place our crane at some X, Y coordinates. + matrix = numpy.eye(4) + matrix[0][3], matrix[1][3] = 3.0, 4.0 + ifcopenshell.api.geometry.edit_object_placement(model, product=crane, matrix=matrix) + + # Let's assign our crane to the resource. The crane now represents + # the resource. + ifcopenshell.api.resource.assign_resource(model, relating_resource=crane, related_object=product) + + # Setup an organisation actor who will operate the crane + organisation = ifcopenshell.api.owner.add_organisation(model, + identification="UCO", name="Unionised Crane Operators Pty Ltd") + role = ifcopenshell.api.owner.add_role(model, assigned_object=organisation, role="CREW") + actor = ifcopenshell.api.owner.add_actor(model, actor=organisation) + + # This means that UCO is now our crane operator. + ifcopenshell.api.resource.assign_resource(model, relating_resource=crane, related_object=actor) + """ + if related_object.HasAssignments: + for assignment in related_object.HasAssignments: + if assignment.is_a("IfclRelAssignsToResource") and assignment.RelatingResource == relating_resource: + return assignment + + resource_of = None + if relating_resource.ResourceOf: + resource_of = relating_resource.ResourceOf[0] + + if resource_of: + related_objects = list(resource_of.RelatedObjects) + related_objects.append(related_object) + resource_of.RelatedObjects = related_objects + ifcopenshell.api.owner.update_owner_history(file, element=resource_of) + else: + resource_of = file.create_entity( + "IfcRelAssignsToResource", + **{ + "GlobalId": ifcopenshell.guid.new(), + "OwnerHistory": ifcopenshell.api.owner.create_owner_history(file), + "RelatedObjects": [related_object], + "RelatingResource": relating_resource, + } + ) + return resource_of diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_usage.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_usage.py new file mode 100644 index 0000000000000000000000000000000000000000..545016bfd2fecf96b4059c237b163219fb9fe5cb --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_usage.py @@ -0,0 +1,55 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import math +import ifcopenshell.api +import ifcopenshell.util.constraint +import ifcopenshell.util.date +import ifcopenshell.util.element +import ifcopenshell.util.resource + + +def calculate_resource_usage(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None: + """Calculates the number of resources required to perform scheduled work on a task. + + :param resource: The IfcConstructionResource to calculate the usage for. + :return: None + """ + + if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleUsage"): + return + if not resource.Usage or not resource.Usage.ScheduleWork: + return + + task = ifcopenshell.util.resource.get_task_assignments(resource) + if not task or not task.TaskTime: + return + + if not task.TaskTime.DurationType or task.TaskTime.DurationType == "WORKTIME": + hours_per_day = 8 + else: + hours_per_day = 24 + + task_duration = ifcopenshell.util.date.ifc2datetime(task.TaskTime.ScheduleDuration) + seconds = task_duration.days * hours_per_day * 60 * 60 + seconds += task_duration.seconds + + person_hours = ifcopenshell.util.date.ifc2datetime(resource.Usage.ScheduleWork) + + required_resources = person_hours.total_seconds() / seconds + resource.Usage.ScheduleUsage = float(required_resources) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_work.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_work.py new file mode 100644 index 0000000000000000000000000000000000000000..0ec5f56fe41ec0c9f4326b9dc98d7d18012cd5ed --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_work.py @@ -0,0 +1,63 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.api.resource +import ifcopenshell.util.constraint +import ifcopenshell.util.date +import ifcopenshell.util.element +import ifcopenshell.util.resource + + +def calculate_resource_work(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None: + """Calculates the work that a resource is used for + + This is an unofficial parametric calculation that may be done on a + resource based on careful analysis of the relationships between the + costing, scheduling, and resource domains in IFC. + + A resource may store a productivity rate in a property set called + EPset_Productivity. This stores three properties: + + * BaseQuantityConsumed - a duration that the resource is consumed for. + * BaseQuantityProducedName - what quantity the resource can produce, + such as area or volume. + * BaseQuantityProducedValue - what value of that quantity the resource + can produce during that duration. + + For example, a labour or equipment resource might produce 100m3 of + NetVolume every day (i.e. 8 hours are consumed). + + Then, if a resource is assigned to a construction task, and that + construction task is assigned to concrete slabs totalling 200m3, we can + calculate that the resource consumes 16 hours of work. + + This calculated work is stored against the resource as scheduled work + under the resource time data. + + :param resource: The IfcConstructionResource that you want to calculate + the work performed. + :return None: + """ + if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleWork"): + return + amount_worked = ifcopenshell.util.resource.get_resource_required_work(resource) + if not amount_worked: + return + if not resource.Usage: + ifcopenshell.api.resource.add_resource_time(file, resource=resource) + resource.Usage.ScheduleWork = amount_worked diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..3476032c1abb72adca171941ca91fe3393bf25a4 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource.py @@ -0,0 +1,43 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcResource + + For more information about the attributes and data types of an + IfcResource, consult the IFC documentation. + + :param resource: The IfcResource entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Change the name of the resource to "Zone A Crew" + ifcopenshell.api.resource.edit_resource(model, resource=resource, attributes={"Name": "Foo"}) + """ + for name, value in attributes.items(): + setattr(resource, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_quantity.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_quantity.py new file mode 100644 index 0000000000000000000000000000000000000000..87a14774d8ef0a3e6e7a0ac23cf105315f51eacb --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_quantity.py @@ -0,0 +1,54 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_resource_quantity( + file: ifcopenshell.file, physical_quantity: ifcopenshell.entity_instance, attributes: dict[str, Any] +) -> None: + """Edits the attributes of an IFC quantity + + For more information about the attributes and data types of an + IfC quantity, consult the IFC documentation. + + :param physical_quantity: The IfC quantity entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some labour to our crew. + labour = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcLaborResource") + + # Labour resource is quantified in terms of time. + ifcopenshell.api.resource.add_resource_quantity(model, + resource=labour, ifc_class="IfcQuantityTime") + + # Store the time used in hours + ifcopenshell.api.resource.edit_resource_quantity(model, + physical_quantity=time, attributes={"TimeValue": 8.0}) + """ + for name, value in attributes.items(): + setattr(physical_quantity, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_time.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_time.py new file mode 100644 index 0000000000000000000000000000000000000000..7326a5fd906dff8ed99d7ac84d9eee67ad87240c --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_time.py @@ -0,0 +1,98 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.sequence +import ifcopenshell.util.constraint +import ifcopenshell.util.date +import ifcopenshell.util.resource +from typing import Any + + +def edit_resource_time( + file: ifcopenshell.file, resource_time: ifcopenshell.entity_instance, attributes: dict[str, Any] +) -> None: + """Edits the attributes of an IfcResourceTime + + For more information about the attributes and data types of an + IfcResourceTime, consult the IFC documentation. + + :param resource_time: The IfcResourceTime entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some labour to our crew. + labour = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcLaborResource") + + # Labour resource is quantified in terms of time. + ifcopenshell.api.resource.add_resource_quantity(model, + resource=labour, ifc_class="IfcQuantityTime") + + # Store the unit time used in hours + ifcopenshell.api.resource.edit_resource_quantity(model, + physical_quantity=time, attributes={"TimeValue": 8.0}) + + # Let's imagine we've used the resource for 2 days. + time = ifcopenshell.api.resource.add_resource_time(model, resource=labour) + ifcopenshell.api.resource.edit_resource_time(model, + resource_time=time, attributes={"ScheduleWork": "P16H"}) + """ + usecase = Usecase() + usecase.file = file + return usecase.execute(resource_time, attributes) + + +class Usecase: + file: ifcopenshell.file + + def execute(self, resource_time: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + resource = self.get_resource(resource_time) + + # If the user specifies both an end date and a duration, the duration takes priority + if attributes.get("ScheduleWork", None) and "ScheduleFinish" in attributes.keys(): + del attributes["ScheduleFinish"] + if attributes.get("ActualWork", None) and "ActualFinish" in attributes.keys(): + del attributes["ActualFinish"] + + for name, value in attributes.items(): + metrics = ifcopenshell.util.constraint.get_metric_constraints(resource, "Usage." + name) + if metrics and ifcopenshell.util.constraint.is_hard_constraint(metrics[0]): + continue + if value: + if "Start" in name or "Finish" in name or name == "StatusTime": + value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime") + elif name == "ScheduleWork" or name == "ActualWork" or name == "RemainingTime": + value = ifcopenshell.util.date.datetime2ifc(value, "IfcDuration") + setattr(resource_time, name, value) + if name == "ScheduleUsage" and ifcopenshell.util.constraint.get_metric_constraints( + resource, "Usage.ScheduleWork" + ): + task = ifcopenshell.util.resource.get_task_assignments(resource) + if task: + ifcopenshell.api.sequence.calculate_task_duration(self.file, task=task) + + def get_resource(self, resource_time: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + return next(e for e in self.file.get_inverse(resource_time) if e.is_a("IfcResource")) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..41f34292454107c6e63f78d1d12692ce8f7f52c9 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource.py @@ -0,0 +1,78 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021-2022, Dion Moult , Yassine Oualid +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.resource +import ifcopenshell.util.element + + +def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None: + """Removes a resource and all relationships + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Fire our crew + ifcopenshell.api.resource.remove_resource(model, resource=crew) + """ + settings = {"resource": resource} + + def remove_consider_history(root: ifcopenshell.entity_instance) -> None: + history = root.OwnerHistory + file.remove(root) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + + # TODO: review deep purge + for inverse in file.get_inverse(settings["resource"]): + if inverse.is_a("IfcRelNests"): + if inverse.RelatingObject == settings["resource"]: + # Remove rel before iteration over objects + # to simplify removal of nested resources and avoid crashes. + related_objects = inverse.RelatedObjects + remove_consider_history(inverse) + for related_object in related_objects: + ifcopenshell.api.resource.remove_resource(file, resource=related_object) + elif inverse.RelatedObjects == (resource,): + remove_consider_history(inverse) + + elif inverse.is_a("IfcRelAssignsToControl"): + if len(inverse.RelatedObjects) == 1: + remove_consider_history(inverse) + else: + related_objects = list(inverse.RelatedObjects) + related_objects.remove(settings["resource"]) + inverse.RelatedObjects = related_objects + elif inverse.is_a("IfcRelAssignsToResource"): + if inverse.RelatingResource == settings["resource"]: + for related_object in inverse.RelatedObjects: + ifcopenshell.api.resource.unassign_resource( + file, related_object=related_object, relating_resource=settings["resource"] + ) + elif inverse.RelatedObjects == (resource,): + remove_consider_history(inverse) + # Usage was added in IFC4. + if usage := getattr(settings["resource"], "Usage", None): + file.remove(usage) + if settings["resource"].BaseQuantity: + ifcopenshell.api.resource.remove_resource_quantity(file, resource=settings["resource"]) + remove_consider_history(resource) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource_quantity.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource_quantity.py new file mode 100644 index 0000000000000000000000000000000000000000..a6b014e1db869bef3fe3cbc0c08e7996a8e9d9b9 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource_quantity.py @@ -0,0 +1,50 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.util.element + + +def remove_resource_quantity(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None: + """Removes the base quantity of a resource + + :param resource: The IfcConstructionResource to remove the quantity from. + :return: None + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some labour to our crew. + labour = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcLaborResource") + + # Labour resource is quantified in terms of time. + ifcopenshell.api.resource.add_resource_quantity(model, + resource=labour, ifc_class="IfcQuantityTime") + + # Let's say we only want to store the resource but no quantities, + # let's clean up our mess and remove the quantity. + ifcopenshell.api.resource.remove_resource_quantity(model, resource=labour) + """ + old_quantity = resource.BaseQuantity + resource.BaseQuantity = None + if old_quantity: + ifcopenshell.util.element.remove_deep(file, old_quantity) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/unassign_resource.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/unassign_resource.py new file mode 100644 index 0000000000000000000000000000000000000000..c3a1fd39cf0b7f8d4fad1f89f9dee2e273bd32c3 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/unassign_resource.py @@ -0,0 +1,72 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.owner +import ifcopenshell.util.element + + +def unassign_resource( + file: ifcopenshell.file, + relating_resource: ifcopenshell.entity_instance, + related_object: ifcopenshell.entity_instance, +) -> None: + """Removes the relationship between a resource and object + + :param relating_resource: The IfcResource to assign the object to. + :param related_object: The IfcProduct or IfcActor to assign to the + object. + :return: None + + Example: + + .. code:: python + + # Add our own crew + crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource") + + # Add some a tower crane to our crew. + crane = ifcopenshell.api.resource.add_resource(model, + parent_resource=crew, ifc_class="IfcConstructionEquipmentResource", name="Tower Crane 01") + + # Our tower crane will be placed via this physical product. + product = ifcopenshell.api.root.create_entity(model, + ifc_class="IfcBuildingElementProxy", predefined_type="CRANE") + + # Let's assign our crane to the resource. The crane now represents + # the resource. + ifcopenshell.api.resource.assign_resource(model, + relating_resource=crane, related_object=product) + + # Undo it. + ifcopenshell.api.resource.unassign_resource(model, + relating_resource=crane, related_object=product) + """ + for rel in related_object.HasAssignments or []: + if not rel.is_a("IfcRelAssignsToResource") or rel.RelatingResource != relating_resource: + continue + if len(rel.RelatedObjects) == 1: + history = rel.OwnerHistory + file.remove(rel) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + return + related_objects = list(rel.RelatedObjects) + related_objects.remove(related_object) + rel.RelatedObjects = related_objects + ifcopenshell.api.owner.update_owner_history(file, element=rel) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/__init__.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..ede54387e46c4a84aa2216153296946e6d4bdf9f --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/__init__.py @@ -0,0 +1,42 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# 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 . + +"""Create, copy, or remove physical elements such as walls, doors, slabs, etc + +This is one of the most used API modules and should be used any time you want +to create, remove, copy, or change a physical or spatial element. See +:func:`create_entity` to get started. + +This module should also be used to create types. To then associate types with +elements, see :mod:`ifcopenshell.api.type`. +""" + +from .. import wrap_usecases +from .copy_class import copy_class +from .create_entity import create_entity +from .reassign_class import reassign_class +from .remove_product import remove_product + +wrap_usecases(__path__, __name__) + +__all__ = [ + "copy_class", + "create_entity", + "reassign_class", + "remove_product", +] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/copy_class.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/copy_class.py new file mode 100644 index 0000000000000000000000000000000000000000..167680bd78c9234d3e7a81b42754fd57d9c051c7 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/copy_class.py @@ -0,0 +1,194 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.material +import ifcopenshell.api.root +import ifcopenshell.api.system +import ifcopenshell.api.geometry +import ifcopenshell.util.system +import ifcopenshell.util.element +import ifcopenshell.util.placement +from typing import Any + + +def copy_class(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + """Copies a product + + The following relationships are also duplicated: + + * The copy will have the same object placement coordinates as the + original. + * The copy will have duplicated property sets, properties, and quantities + * The copy will have all nested distribution ports copied too + * The copy will be part of the same aggregate + * The copy will be contained in the same spatial structure + * The copy, if it is an occurrence, will have the same type + * Voids are duplicated too + * The copy will have the same material as the original. Parametric + material set usages will be copied. + * The copy will be part of the same groups as the original. + + Be warned that: + + * Representations are _not_ copied. Copying representations is an + expensive operation so for now the user is responsible for handling + representations. + * Filled voids are not copied, as there is no guarantee that the filling + will also be copied. + * Path connectivity is not copied, as there is no guarantee that the + connections are still valid. + + :param product: The IfcProduct to copy. + :return: The copied product + + Example: + + .. code:: python + + # We have a wall + wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") + + # And now we have two + wall_copy = ifcopenshell.api.root.copy_class(model, product=wall) + """ + usecase = Usecase() + usecase.file = file + return usecase.execute(product) + + +class Usecase: + file: ifcopenshell.file + + def execute(self, product: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + result = ifcopenshell.util.element.copy(self.file, product) + self.copy_direct_attributes(result) + self.copy_indirect_attributes(product, result) + return result + + def copy_direct_attributes(self, to_element: ifcopenshell.entity_instance) -> None: + self.remove_representations(to_element) + self.copy_object_placements(to_element) + self.copy_psets(to_element) + + def copy_indirect_attributes( + self, from_element: ifcopenshell.entity_instance, to_element: ifcopenshell.entity_instance + ) -> None: + for inverse in self.file.get_inverse(from_element): + if inverse.is_a("IfcRelDefinesByProperties"): + # Properties must not be shared between objects for convenience of authoring + inverse = ifcopenshell.util.element.copy(self.file, inverse) + inverse.RelatedObjects = [to_element] + pset = ifcopenshell.util.element.copy_deep(self.file, inverse.RelatingPropertyDefinition) + inverse.RelatingPropertyDefinition = pset + elif ( + inverse.is_a("IfcRelNests") + and inverse.RelatingObject == from_element + or inverse.is_a("IfcRelConnectsPortToElement") + and inverse.RelatedElement == from_element + ): + # IfcRelConnectsPortToElement was used in IFC2X3 + if inverse.is_a("IfcRelNests"): + ports = [e for e in inverse.RelatedObjects if e.is_a("IfcDistributionPort")] + else: # IfcRelConnectsPortToElement + ports = [inverse.RelatingPort] + if not ports: + continue + new_ports = [ifcopenshell.api.root.copy_class(self.file, product=p) for p in ports] + inverse = ifcopenshell.util.element.copy(self.file, inverse) + + if inverse.is_a("IfcRelNests"): + inverse.RelatingObject = to_element + inverse.RelatedObjects = new_ports + else: + inverse.RelatedElement = to_element + inverse.RelatingPort = new_ports[0] + + for port in new_ports: + ifcopenshell.api.system.unassign_port(self.file, element=from_element, port=port) + ifcopenshell.api.system.disconnect_port(self.file, port=port) + matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement) + ifcopenshell.api.geometry.edit_object_placement( + self.file, + product=port, + matrix=matrix, + is_si=False, + should_transform_children=False, + ) + elif inverse.is_a("IfcRelAggregates") and inverse.RelatingObject == from_element: + continue + elif inverse.is_a("IfcRelContainedInSpatialStructure") and inverse.RelatingStructure == from_element: + continue + elif inverse.is_a("IfcRelDefinesByType") and inverse.RelatingType == from_element: + continue + elif inverse.is_a("IfcRelVoidsElement") and inverse.RelatingBuildingElement == from_element: + opening = inverse.RelatedOpeningElement + # We don't copy filled openings, since there is no guarantee the filling is also copied + if not opening.is_a("IfcOpeningElement") or not opening.HasFillings: + new_opening = ifcopenshell.api.root.copy_class(self.file, product=opening) + new_opening.VoidsElements[0].RelatingBuildingElement = to_element + if new_opening.ObjectPlacement and new_opening.ObjectPlacement.is_a("IfcLocalPlacement"): + if to_element.ObjectPlacement: + new_opening.ObjectPlacement.PlacementRelTo = to_element.ObjectPlacement + # For now, we do copy opening representations + if opening.Representation: + new_opening.Representation = ifcopenshell.util.element.copy_deep( + self.file, opening.Representation, exclude=["IfcGeometricRepresentationContext"] + ) + elif inverse.is_a("IfcRelFillsElement"): + continue + elif inverse.is_a("IfcRelConnectsPathElements"): + continue + elif inverse.is_a("IfcRelAssociatesMaterial") and "Usage" in inverse.RelatingMaterial.is_a(): + inverse = ifcopenshell.util.element.copy(self.file, inverse) + inverse.RelatingMaterial = ifcopenshell.util.element.copy(self.file, inverse.RelatingMaterial) + inverse.RelatedObjects = [to_element] + elif inverse.is_a("IfcRelAssociatesMaterial") and "Set" in inverse.RelatingMaterial.is_a(): + inverse = ifcopenshell.util.element.copy(self.file, inverse) + inverse.RelatingMaterial = ifcopenshell.api.material.copy_material(self.file, inverse.RelatingMaterial) + inverse.RelatedObjects = [to_element] + else: + for i, value in enumerate(inverse): + if value == from_element: + new_inverse = ifcopenshell.util.element.copy(self.file, inverse) + new_inverse[i] = to_element + elif isinstance(value, (tuple, list)) and from_element in value: + new_value = list(value) + new_value.append(to_element) + inverse[i] = new_value + + def remove_representations(self, element: ifcopenshell.entity_instance) -> None: + if element.is_a("IfcProduct"): + element.Representation = None + elif element.is_a("IfcTypeProduct"): + element.RepresentationMaps = None + + def copy_object_placements(self, element: ifcopenshell.entity_instance) -> None: + if not element.is_a("IfcProduct") or not element.ObjectPlacement: + return + element.ObjectPlacement = ifcopenshell.util.element.copy(self.file, element.ObjectPlacement) + element.ObjectPlacement.RelativePlacement = ifcopenshell.util.element.copy_deep( + self.file, element.ObjectPlacement.RelativePlacement + ) + + def copy_psets(self, element: ifcopenshell.entity_instance) -> None: + if not element.is_a("IfcTypeObject") or not element.HasPropertySets: + return + element.HasPropertySets = [ + ifcopenshell.util.element.copy_deep(self.file, pset) for pset in element.HasPropertySets + ] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/create_entity.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/create_entity.py new file mode 100644 index 0000000000000000000000000000000000000000..96a3b130be5c2169432c26e30577fd2d31de042e --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/create_entity.py @@ -0,0 +1,139 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.owner +import ifcopenshell.guid +from typing import Optional, Any + + +def create_entity( + file: ifcopenshell.file, + ifc_class: str = "IfcBuildingElementProxy", + predefined_type: Optional[str] = None, + name: Optional[str] = None, +) -> ifcopenshell.entity_instance: + """Create a new rooted product + + This is a critical function used to create almost any rooted product or + product type. If you want to create walls, spaces, buildings, wall + types, and so on, use this function. + + Just specify the class you want to create, as well as the predefined + type and name. It will handle the storage of the predefined type and + check whether the predefined type is built-in or custom. It will also + generate a valid GlobalId and store ownership history. It will also + handle some edge cases for default validity where users might forget to + populate some mandatory attributes. For example, doors must define an + operation type but many people forget. + + :param ifc_class: Any rooted IFC class. + :param predefined_type: Any built-in or user-defined predefined type that + is applicable to that IFC class. For user-defined predefined types + just enter in any value and the API will handle it automatically. + :param name: The name of the new element. + :return: The newly created element based on the specified IFC class. + + Example: + + .. code:: python + + # We have a project. + ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject") + + # We have a building. + ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuilding") + + # We have a wall. + ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") + + # We have a wall type. + ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType") + """ + usecase = Usecase() + usecase.file = file + return usecase.execute(ifc_class, predefined_type, name) + + +class Usecase: + file: ifcopenshell.file + + def execute( + self, ifc_class: str, predefined_type: Optional[str] = None, name: Optional[str] = None + ) -> ifcopenshell.entity_instance: + element = self.file.create_entity( + ifc_class, + **{ + "GlobalId": ifcopenshell.guid.new(), + "OwnerHistory": ifcopenshell.api.owner.create_owner_history(self.file), + } + ) + element.Name = name or None + if predefined_type: + if hasattr(element, "PredefinedType"): + try: + element.PredefinedType = predefined_type + except: + element.PredefinedType = "USERDEFINED" + if hasattr(element, "ObjectType"): + element.ObjectType = predefined_type + elif hasattr(element, "ElementType"): + element.ElementType = predefined_type + elif hasattr(element, "ProcessType"): + element.ProcessType = predefined_type + elif hasattr(element, "ObjectType"): + element.ObjectType = predefined_type + if self.file.schema == "IFC2X3": + self.handle_2x3_defaults(element) + else: + self.handle_4_defaults(element) + return element + + def handle_2x3_defaults(self, element: ifcopenshell.entity_instance) -> None: + if element.is_a("IfcElementType"): + if hasattr(element, "PredefinedType") and not element.PredefinedType: + element.PredefinedType = "NOTDEFINED" + + if element.is_a("IfcSpatialStructureElement"): + element.CompositionType = "ELEMENT" + elif element.is_a("IfcRoof"): + element.ShapeType = "NOTDEFINED" + elif element.is_a("IfcFurnitureType"): + element.AssemblyPlace = "NOTDEFINED" + elif element.is_a("IfcDoorStyle") or element.is_a("IfcWindowStyle"): + element.OperationType = "NOTDEFINED" + element.ConstructionType = "NOTDEFINED" + element.ParameterTakesPrecedence = False + element.Sizeable = False + + def handle_4_defaults(self, element: ifcopenshell.entity_instance) -> None: + if element.is_a("IfcElementType"): + if hasattr(element, "PredefinedType") and not element.PredefinedType: + element.PredefinedType = "NOTDEFINED" + + if element.file.schema == "IFC4" and (element.is_a("IfcDoorStyle") or element.is_a("IfcWindowStyle")): + element.OperationType = "NOTDEFINED" + element.ConstructionType = "NOTDEFINED" + element.ParameterTakesPrecedence = False + element.Sizeable = False + elif element.is_a("IfcDoorType"): + element.OperationType = "NOTDEFINED" + elif element.is_a("IfcWindowType"): + element.PartitioningType = "NOTDEFINED" + elif element.is_a("IfcFurnitureType"): + element.AssemblyPlace = "NOTDEFINED" diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/reassign_class.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/reassign_class.py new file mode 100644 index 0000000000000000000000000000000000000000..18ff02b199aee162c656c0be2aa73c4545238d01 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/reassign_class.py @@ -0,0 +1,236 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.api.aggregate +import ifcopenshell.api.geometry +import ifcopenshell.api.pset +import ifcopenshell.api.spatial +import ifcopenshell.api.type +import ifcopenshell.guid +import ifcopenshell.util.representation +import ifcopenshell.util.type +import ifcopenshell.util.schema +import ifcopenshell.util.element +from typing import Optional, Union, Literal + + +def reassign_class( + file: ifcopenshell.file, + product: ifcopenshell.entity_instance, + ifc_class: str = "IfcBuildingElementProxy", + predefined_type: Optional[str] = None, + occurrence_class: Optional[str] = None, +) -> ifcopenshell.entity_instance: + """Changes the class of a product + + If you ever created a wall then realised it's meant to be something + else, this function lets you change the IFC class whilst retaining all + other geometry and relationships. + + This is especially useful when dealing with poorly classified data from + proprietary software with limited IFC capabilities. + + If you are reassigning a type, the occurrence classes are also + reassigned to maintain validity. + + Vice versa, if you are reassigning an occurrence, the type is also + reassigned in IFC4 and up. In IFC2X3, this may not occur if the type + cannot be unambiguously derived, so you are required to manually check + this. + + Reassigning type class to occurrence (and vice versa) is supported. + + :param product: The IfcProduct that you want to change the class of. + :param ifc_class: The new IFC class you want to change it to. + :param predefined_type: In case you want to change the predefined type + too. User defined types are also allowed, just type what you want. + :param occurrence_class: IFC class to assign to occurrences in case + if provided ``ifc_class`` is IfcTypeProduct. + If omitted, class will be deduced automatically from the type. + Only really needed in IFC2X3, since in IFC4+ there is no ambiguity on + what class to assign to occurrences. + :return: The newly modified product. + + Example: + + .. code:: python + + # We have a wall. + wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") + + # Oh, did I say wall? I meant slab. + slab = ifcopenshell.api.root.reassign_class(model, product=wall, ifc_class="IfcSlab") + + # Warning: this will crash since wall doesn't exist any more. + print(wall) # Kaboom. + """ + usecase = Usecase() + usecase.file = file + return usecase.execute(product, ifc_class, predefined_type, occurrence_class) + + +class Usecase: + file: ifcopenshell.file + + def execute( + self, + product: ifcopenshell.entity_instance, + ifc_class: str, + predefined_type: Union[str, None], + occurrence_class: Union[str, None], + ) -> ifcopenshell.entity_instance: + self.occurrence_class = occurrence_class + was_type_product_before = product.is_a("IfcTypeProduct") + self.schema = schema = ifcopenshell.schema_by_name(self.file.schema) + is_type_product_after: bool + is_type_product_after = schema.declaration_by_name(ifc_class)._is("IfcTypeProduct") + + if was_type_product_before == is_type_product_after: + return self.simple_reassignment(product, ifc_class, predefined_type) + + switch_type = "occurrence_to_type" if is_type_product_after else "type_to_occurrence" + + return self.switch_between_class_types( + product, + switch_type, + ifc_class, + predefined_type, + ) + + def switch_between_class_types( + self, + element: ifcopenshell.entity_instance, + switch_type: Literal["occurrence_to_type", "type_to_occurrence"], + ifc_class: str, + predefined_type: Union[str, None], + ) -> ifcopenshell.entity_instance: + + psets_to_reassign: list[ifcopenshell.entity_instance] = [] + + representations = list(ifcopenshell.util.representation.get_representations_iter(element)) + for rep in representations: + if switch_type == "type_to_occurrence": + rep = ifcopenshell.util.representation.resolve_representation(rep) + ifcopenshell.api.geometry.unassign_representation(self.file, product=element, representation=rep) + + if switch_type == "type_to_occurrence": + occurrences = ifcopenshell.util.element.get_types(element) + # Don't need to reassign as psets are linked to type directly, without rel. + psets_to_reassign = element.HasPropertySets or [] + + element = self.reassign_class(element, ifc_class, predefined_type) + ifcopenshell.api.type.unassign_type(self.file, occurrences) + + else: # occurrence_to_type + element_type = ifcopenshell.util.element.get_type(element) + # Handle element type. + if element_type: + ifcopenshell.api.type.unassign_type(self.file, [element]) + + # Handle containers and aggregates. + if ifcopenshell.util.element.get_container(element): + ifcopenshell.api.spatial.unassign_container(self.file, [element]) + elif ifcopenshell.util.element.get_aggregate(element): + ifcopenshell.api.aggregate.unassign_object(self.file, [element]) + + psets = ifcopenshell.util.element.get_psets(element) + for pset_name in psets: + pset = self.file.by_id(psets[pset_name]["id"]) + psets_to_reassign.append(pset) + ifcopenshell.api.pset.unassign_pset(self.file, [element], pset) + + element = self.reassign_class(element, ifc_class, predefined_type) + + # Reassign psets. + for pset in psets_to_reassign: + ifcopenshell.api.pset.assign_pset(self.file, [element], pset) + + # Reassign representations. + for rep in representations: + ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=rep) + + # Keep IFC valid (PlacementForShapeRepresentation). + if switch_type == "type_to_occurrence" and representations: + ifcopenshell.api.geometry.edit_object_placement(self.file, product=element) + + return element + + def simple_reassignment( + self, + element: ifcopenshell.entity_instance, + ifc_class: str, + predefined_type: Union[str, None], + ) -> ifcopenshell.entity_instance: + """ + Simple class reassignment doesn't involve changing class type. + + E.g. IfcWindow (IfcProduct class) -> IfcWall (other IfcProduct class). + + Changing class type (e.g. IfcWindowType -> IfcWindow) is more complex + as it requires to recreate some entities / assign them in different way + (e.g. representations, property sets and their rels). + """ + element = self.reassign_class(element, ifc_class, predefined_type) + if element.is_a("IfcTypeProduct"): + + if self.occurrence_class: + occurrence_class = self.occurrence_class + else: + # NOTE: in theory we can skip reassignment in IFC2X3 in some cases + # e.g. if occurrence is IfcRoof and we're reassigning to IfcBuildingElementProxyType + # but currently type_to_entity_map doesn't completely match entity_to_type_map, + # see type.py for more details. + occurrence_class = next( + iter(ifcopenshell.util.type.get_applicable_entities(ifc_class, self.file.schema)) + ) + assert not self.schema.declaration_by_name(occurrence_class)._is( + "IfcTypeProduct" + ), f"Unexpected occurrence_class: '{occurrence_class}' / '{self.occurrence_class}'." + + for occurrence in ifcopenshell.util.element.get_types(element): + self.reassign_class(occurrence, occurrence_class, predefined_type) + else: + element_type = ifcopenshell.util.element.get_type(element) + if element_type: + ifc_class_ = next(iter(ifcopenshell.util.type.get_applicable_types(ifc_class, self.file.schema))) + element_type = self.reassign_class(element_type, ifc_class_, predefined_type) + ifc_class = element.is_a() + for occurrence in ifcopenshell.util.element.get_types(element_type): + if occurrence == element: + continue + self.reassign_class(occurrence, ifc_class, predefined_type) + return element + + def reassign_class( + self, element: ifcopenshell.entity_instance, ifc_class: str, predefined_type: Union[str, None] + ) -> ifcopenshell.entity_instance: + element = ifcopenshell.util.schema.reassign_class(self.file, element, ifc_class) + if predefined_type and hasattr(element, "PredefinedType"): + try: + element.PredefinedType = predefined_type + except: + # PredefinedType wasn't in the respective enum, assume it's actually USERDEFINED + # and set .ElementType / .ObjectType to the provided predefined type + element.PredefinedType = "USERDEFINED" + if element.is_a("IfcTypeProduct"): + element.ElementType = predefined_type + else: + element.ObjectType = predefined_type + + return element diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/remove_product.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/remove_product.py new file mode 100644 index 0000000000000000000000000000000000000000..df17e3bb699a58039927bfbfc14789756c690052 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/remove_product.py @@ -0,0 +1,223 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.api.type +import ifcopenshell.api.grid +import ifcopenshell.api.feature +import ifcopenshell.api.root +import ifcopenshell.api.pset +import ifcopenshell.api.boundary +import ifcopenshell.api.material +import ifcopenshell.api.geometry +import ifcopenshell.util.element + + +def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -> None: + """Removes a product + + This is effectively a smart delete function that not only removes a + product, but also all of its relationships. It is always recommended to + use this function to prevent orphaned data in your IFC model. + + This is intended to be used for removing: + + - IfcAnnotation + - IfcElement + - IfcElementType + - IfcSpatialElement + - IfcSpatialElementType + + For example, geometric representations are removed. Placement + coordinates are also removed. Properties are removed. Material, type, + containment, aggregation, and nesting relationships are removed (but + naturally, the materials, types, containers, etc themselves remain). + + :param product: The element to remove. + :return: None + + Example: + + .. code:: python + + # We have a wall. + wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") + + # No we don't. + ifcopenshell.api.root.remove_product(model, product=wall) + """ + representations: list[ifcopenshell.entity_instance] = [] + if product.is_a("IfcProduct"): + if product.Representation: + representations = product.Representation.Representations or [] + else: + representations = [] + + # remove object placements + object_placement = product.ObjectPlacement + if object_placement: + if file.get_total_inverses(object_placement) == 1: + product.ObjectPlacement = None # remove the inverse for remove_deep2 to work + ifcopenshell.util.element.remove_deep2(file, object_placement) + + elif product.is_a("IfcTypeProduct"): + representations = [rm.MappedRepresentation for rm in product.RepresentationMaps or []] + + # remove psets + psets = product.HasPropertySets or [] + for pset in psets: + if file.get_total_inverses(pset) != 1: + continue + ifcopenshell.api.pset.remove_pset(file, product=product, pset=pset) + + for representation in representations: + ifcopenshell.api.geometry.unassign_representation(file, product=product, representation=representation) + ifcopenshell.api.geometry.remove_representation(file, representation=representation) + for opening in getattr(product, "HasOpenings", []) or []: + ifcopenshell.api.feature.remove_feature(file, feature=opening.RelatedOpeningElement) + + if product.is_a("IfcGrid"): + for axis in product.UAxes + product.VAxes + (product.WAxes or ()): + ifcopenshell.api.grid.remove_grid_axis(file, axis=axis) + + def element_exists(element_id): + try: + file.by_id(element_id) + return True + except RuntimeError: + return False + + # TODO: remove object placement and other relationships + for inverse_id in [i.id() for i in file.get_inverse(product)]: + try: + inverse = file.by_id(inverse_id) + except: + continue + if inverse.is_a("IfcRelDefinesByProperties"): + ifcopenshell.api.pset.remove_pset(file, product=product, pset=inverse.RelatingPropertyDefinition) + elif inverse.is_a("IfcRelAssociatesMaterial"): + ifcopenshell.api.material.unassign_material(file, products=[product]) + elif inverse.is_a("IfcRelDefinesByType"): + if inverse.RelatingType == product: + ifcopenshell.api.type.unassign_type(file, related_objects=inverse.RelatedObjects) + else: + ifcopenshell.api.type.unassign_type(file, related_objects=[product]) + elif inverse.is_a("IfcRelSpaceBoundary"): + ifcopenshell.api.boundary.remove_boundary(file, boundary=inverse) + elif inverse.is_a("IfcRelFillsElement"): + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelVoidsElement"): + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelServicesBuildings"): + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelNests"): + if inverse.RelatingObject == product: + inverse_id = inverse.id() + for subelement in inverse.RelatedObjects: + if subelement.is_a("IfcDistributionPort"): + ifcopenshell.api.root.remove_product(file, product=subelement) + # IfcRelNests could have been already deleted after removing one of the products + if element_exists(inverse_id): + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.RelatedObjects == (product,): + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelAggregates"): + if inverse.RelatingObject == product or len(inverse.RelatedObjects) == 1: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelContainedInSpatialStructure"): + if inverse.RelatingStructure == product or len(inverse.RelatedElements) == 1: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelConnectsElements"): + if inverse.is_a("IfcRelConnectsWithRealizingElements"): + if product not in (inverse.RelatingElement, inverse.RelatedElement) and any( + el for el in inverse.RealizingElements if el != product + ): + continue + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelConnectsPortToElement"): + if inverse.RelatedElement == product: + ifcopenshell.api.root.remove_product(file, product=inverse.RelatingPort) + elif inverse.RelatingPort == product: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelConnectsPorts"): + if product not in (inverse.RelatingPort, inverse.RelatedPort): + # if it's not RelatingPort/RelatedPort then it's optional RealizingElement + # so we keep the relationship + continue + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelAssignsToGroup"): + if len(inverse.RelatedObjects) == 1: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelAssignsToProduct"): + if inverse.RelatingProduct == product: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif len(inverse.RelatedObjects) == 1: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.is_a("IfcRelFlowControlElements"): + if inverse.RelatingFlowElement == product: + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + elif inverse.RelatedControlElements == (product,): + history = inverse.OwnerHistory + file.remove(inverse) + if history: + ifcopenshell.util.element.remove_deep2(file, history) + history = product.OwnerHistory + file.remove(product) + if history: + ifcopenshell.util.element.remove_deep2(file, history) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/assign_recurrence_pattern.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/assign_recurrence_pattern.py new file mode 100644 index 0000000000000000000000000000000000000000..7f74fb300b7eabbbae13262d17e50efe8dedeb45 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/assign_recurrence_pattern.py @@ -0,0 +1,118 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +import ifcopenshell.util.sequence + + +def assign_recurrence_pattern( + file: ifcopenshell.file, + parent: ifcopenshell.entity_instance, + recurrence_type: ifcopenshell.util.sequence.RECURRENCE_TYPE = "WEEKLY", +) -> ifcopenshell.entity_instance: + """Define a time to recur at a particular interval + + There are two scenarios where you might want to define a recurring time + pattern. + + You might want a task to be scheduled at a recurring interval, + this is common for maintenance tasks which need to be performed monthly, + every 6 months, every year, etc. + + Alternatively, you might be defining a work calendar, which defines + working days or holidays. The working days might be every week from + monday to friday ("every" week means it recurs every week), or the + holidays might be the same every year. + + The types of recurrence are: + + - DAILY: every Nth (interval) day for up to X (Occurrences) occurrences. + e.g. Every day, every 2 days, every day up to 5 times, etc + - WEEKLY: every Nth (interval) MTWTFSS (WeekdayComponent) for up to X + (Occurrences) occurrences. e.g. Every Monday, every weekday, every + other saturday, etc + - MONTHLY_BY_DAY_OF_MONTH: every Nth (DayComponent) of every Xth + (Interval) Month up to Y (Occurrences) occurrences. e.g. Every 15th of + the Month. + - MONTHLY_BY_POSITION: Every Nth (Position) MTWTFSS (WeekdayComponent) + of every Xth (Interval) Month up to Y (Occurrences) occurrences. e.g. + Every second Tuesday of the Month. + - YEARLY_BY_DAY_OF_MONTH: every Nth (DayComponent) of every JFMAMJJASOND + (MonthComponent) month of every Yth (Interval) Year up to Z + (Occurrences) occurrences. e.g. every 25th of December. + - YEARLY_BY_POSITION: every Nth (Position) MTWTFSS (WeekdayComponent) of + every JFMAMJJASOND (MonthComponent) month of every Yth (Interval) + Year up to Z (Occurrences) occurrences. e.g. every third Wednesday + of January. + + These recurrence patterns are fairly standard in all calendar and + scheduling applications. + + :param parent: Either an IfcTaskTimeRecurring if you are defining a + recurring schedule for a task, or IfcWorkTime if you are defining a + recurring pattern for a workdays or holidays in a calendar. + :param recurrence_type: One of the types of recurrences. + :return: The newly created IfcRecurrencePattern + + Example: + + .. code:: python + + # Let's create a new calendar. + calendar = ifcopenshell.api.sequence.add_work_calendar(model) + + # Let's start defining the times that we work during the week. + work_time = ifcopenshell.api.sequence.add_work_time(model, + work_calendar=calendar, time_type="WorkingTimes") + + # We create a weekly recurrence + pattern = ifcopenshell.api.sequence.assign_recurrence_pattern(model, + parent=work_time, recurrence_type="WEEKLY") + + # State that we work from weekdays 1 to 5 (i.e. Monday to Friday) + ifcopenshell.api.sequence.edit_recurrence_pattern(model, + recurrence_pattern=pattern, attributes={"WeekdayComponent": [1, 2, 3, 4, 5]}) + + # Let's imagine we are creating a maintenance schedule. + schedule = ifcopenshell.api.sequence.add_work_schedule(model, name="Equipment Maintenance") + + # Now let's imagine we have a task to maintain the chillers + task = ifcopenshell.api.sequence.add_task(model, + work_schedule=schedule, name="Chiller maintenance") + + # Because it is a maintenance task, we must schedule a recurring time + time = ifcopenshell.api.sequence.add_task_time(model, task=task, is_recurring=True) + + # We create a monthly recurrence + pattern = ifcopenshell.api.sequence.assign_recurrence_pattern(model, + parent=work_time, recurrence_type="MONTHLY_BY_DAY_OF_MONTH") + + # Specifically, the maintenance task must occur every 6 months + ifcopenshell.api.sequence.edit_recurrence_pattern(model, + recurrence_pattern=pattern, attributes={"DayComponent": [1], "Interval": 6}) + """ + recurrence = file.create_entity("IfcRecurrencePattern", recurrence_type) + + if parent.is_a("IfcWorkTime"): + if (old_recurrence := parent.RecurrencePattern) and file.get_total_inverses(old_recurrence) == 1: + file.remove(old_recurrence) + parent.RecurrencePattern = recurrence + elif parent.is_a("IfcTaskTimeRecurring"): + if (recurrence_old := parent.Recurrence) and file.get_total_inverses(recurrence_old) == 1: + file.remove(recurrence_old) + parent.Recurrence = recurrence + return recurrence diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/remove_work_time.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/remove_work_time.py new file mode 100644 index 0000000000000000000000000000000000000000..d5b7b69c7101b2c9d7db13cb8b667e6c152db29e --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/remove_work_time.py @@ -0,0 +1,48 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +import ifcopenshell.api.sequence + + +def remove_work_time(file: ifcopenshell.file, work_time: ifcopenshell.entity_instance) -> None: + """Removes a work time + + :param work_time: The IfcWorkTime to remove. + :return: None + + Example: + + .. code:: python + + # Let's create a new calendar. + calendar = ifcopenshell.api.sequence.add_work_calendar(model) + + # Let's start defining the times that we work during the week. + work_time = ifcopenshell.api.sequence.add_work_time(model, + work_calendar=calendar, time_type="WorkingTimes") + + # And remove it immediately + ifcopenshell.api.sequence.remove_work_time(model, work_time=work_time) + """ + + # Currently in API recurrence patterns are created during assignment + # and removed during unassignment, so they are never reused. + if recurrence_pattern := work_time.RecurrencePattern: + ifcopenshell.api.sequence.unassign_recurrence_pattern(file, recurrence_pattern) + + file.remove(work_time) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/__init__.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..4245b49c37e612dbad88c44cb10277372e95d135 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/__init__.py @@ -0,0 +1,53 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# 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 . + +"""Define units (length, area, monetary, pressure, etc) + +Units can be defined as a default project unit or used specifically for certain +properties. Units may be especially complex when dealing with services and +equipment. +""" + +from .. import wrap_usecases +from .add_context_dependent_unit import add_context_dependent_unit +from .add_conversion_based_unit import add_conversion_based_unit +from .add_monetary_unit import add_monetary_unit +from .add_si_unit import add_si_unit +from .add_derived_unit import add_derived_unit +from .assign_unit import assign_unit +from .edit_derived_unit import edit_derived_unit +from .edit_monetary_unit import edit_monetary_unit +from .edit_named_unit import edit_named_unit +from .remove_unit import remove_unit +from .unassign_unit import unassign_unit + +wrap_usecases(__path__, __name__) + +__all__ = [ + "add_context_dependent_unit", + "add_conversion_based_unit", + "add_derived_unit", + "add_monetary_unit", + "add_si_unit", + "assign_unit", + "edit_derived_unit", + "edit_monetary_unit", + "edit_named_unit", + "remove_unit", + "unassign_unit", +] diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_context_dependent_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_context_dependent_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..f9c76f9072ae01df1dcc2d2816d3062220e9423a --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_context_dependent_unit.py @@ -0,0 +1,61 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell + + +def add_context_dependent_unit( + file: ifcopenshell.file, + unit_type: str = "USERDEFINED", + name: str = "THINGAMAJIG", + dimensions: tuple[int, int, int, int, int, int, int] = (0, 0, 0, 0, 0, 0, 0), +) -> ifcopenshell.entity_instance: + """Add a new arbitrary unit that can only be interpreted in a project specific context + + Occasionally the construction industry uses arbitrary units to quantify + objects, like "pairs" of door hardware, "palettes" or "boxes" of fixings + or equipment. + + :param unit_type: Typically should be left as USERDEFINED, unless for + some bizarre reason you are redefining something you could use a + sensible normal unit for. In that case, firstly stop whatever you're + doing and have a hard think about your life, and then if life really + is going that badly for you, check out the IFC docs for IfcUnitEnum. + :param name: Give your unit a name. X what? X bananas? + :param dimensions: Units typically measure one of 7 fundamental physical + dimensions: length, mass, time, electric current, temperature, + substance amount, or luminous intensity. These are represented as a + list of 7 integers, representing the exponents of each one of these + dimensions. For example, a length unit is (1, 0, 0, 0, 0, 0, 0), + where as an area unit is (2, 0, 0, 0, 0, 0, 0). A unit of meters per + second is (1, 0, -1, 0, 0, 0, 0). For context dependent units, it is + recommended to leave this as the default of (0, 0, 0, 0, 0, 0, 0). + :return: The new IfcContextDependentUnit + + Example: + + .. code:: python + + # Boxes of things + ifcopenshell.api.unit.add_context_dependent_unit(model, name="BOXES") + """ + return file.create_entity( + "IfcContextDependentUnit", + Dimensions=file.createIfcDimensionalExponents(*dimensions), + UnitType=unit_type, + Name=name, + ) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_conversion_based_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_conversion_based_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..bb1e9202572c15af37bad9782cfd67341bc87fd4 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_conversion_based_unit.py @@ -0,0 +1,81 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.unit +from typing import Optional + + +def add_conversion_based_unit( + file: ifcopenshell.file, name: str = "foot", conversion_offset: Optional[float] = None +) -> ifcopenshell.entity_instance: + """Add a conversion based unit + + If you're in one of those countries who don't use SI units, you're + probably simply using SI units converted into another unit. If you want + to use _those_ units, you can create a conversion based unit with this + function. You can choose from one of: inch, foot, yard, mile, square + inch, square foot, square yard, acre, square mile, cubic inch, cubic + foot, cubic yard, litre, fluid ounce UK, fluid ounce US, pint UK, pint + US, gallon UK, gallon US, degree, ounce, pound, ton UK, ton US, lbf, + kip, psi, ksi, minute, hour, day, btu, and fahrenheit. + + :param name: A converted name chosen from the list above. + :param conversion_offset: If you want to offset the conversion further + by a set number, you may specify it here. For example, fahrenheit is + 1.8 * kelvin - 459.67. The -459.67 is the conversion offset. Note + that this is just an example and you don't actually need to specify + that for fahrenheit as it's built into this API function. For + advanced users only. + :return: The new IfcConversionBasedUnit or + IfcConversionBasedUnitWithOffset + + Example: + + .. code:: python + + # Some common imperial measurements + length = ifcopenshell.api.unit.add_conversion_based_unit(model, name="inch") + area = ifcopenshell.api.unit.add_conversion_based_unit(model, name="square foot") + + # Make it our default units, if we are doing an imperial building + ifcopenshell.api.unit.assign_unit(model, units=[length, area]) + """ + + unit_type = ifcopenshell.util.unit.imperial_types.get(name, "USERDEFINED") + dimensions = ifcopenshell.util.unit.named_dimensions[unit_type] + exponents = file.createIfcDimensionalExponents(*dimensions) + si_name = ifcopenshell.util.unit.si_type_names[unit_type] + si_unit = file.createIfcSIUnit(UnitType=unit_type, Name=si_name) + + conversion_real = ifcopenshell.util.unit.si_conversions.get(name, 1) + value_component = file.create_entity("IfcReal", **{"wrappedValue": conversion_real}) + conversion_factor = file.createIfcMeasureWithUnit(value_component, si_unit) + + if not conversion_offset: + conversion_offset = ifcopenshell.util.unit.si_offsets.get(name, 0) + + if conversion_offset: + return file.createIfcConversionBasedUnitWithOffset( + exponents, + unit_type, + name, + conversion_factor, + conversion_offset, + ) + return file.createIfcConversionBasedUnit(exponents, unit_type, name, conversion_factor) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_derived_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_derived_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..aba4388010ae5ab536e71c1bcf562ae83e6d8f3a --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_derived_unit.py @@ -0,0 +1,77 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.util.unit +from typing import Any, Optional + + +def add_derived_unit( + file: ifcopenshell.file, unit_type: str, userdefinedtype: str, attributes: dict[ifcopenshell.entity_instance, int] +) -> ifcopenshell.entity_instance: + """Add a new Derive unit + + The supported types are ANGULARVELOCITYUNIT, AREADENSITYUNIT, COMPOUNDPLANEANGLEUNIT, + DYNAMICVISCOSITYUNIT, HEATFLUXDENSITYUNIT, INTEGERCOUNTRATEUNIT, ISOTHERMALMOISTURECAPACITYUNIT, + KINEMATICVISCOSITYUNIT, LINEARVELOCITYUNIT, MASSDENSITYUNIT, MASSFLOWRATEUNIT, MOISTUREDIFFUSIVITYUNIT, + MOLECULARWEIGHTUNIT, SPECIFICHEATCAPACITYUNIT, THERMALADMITTANCEUNIT, THERMALCONDUCTANCEUNIT, + THERMALRESISTANCEUNIT, THERMALTRANSMITTANCEUNIT, VAPORPERMEABILITYUNIT, VOLUMETRICFLOWRATEUNIT, + ROTATIONALFREQUENCYUNIT, TORQUEUNIT, MOMENTOFINERTIAUNIT, LINEARMOMENTUNIT, LINEARFORCEUNIT, + PLANARFORCEUNIT, MODULUSOFELASTICITYUNIT, SHEARMODULUSUNIT, LINEARSTIFFNESSUNIT, ROTATIONALSTIFFNESSUNIT, + MODULUSOFSUBGRADEREACTIONUNIT, ACCELERATIONUNIT, CURVATUREUNIT, HEATINGVALUEUNIT, IONCONCENTRATIONUNIT, + LUMINOUSINTENSITYDISTRIBUTIONUNIT, MASSPERLENGTHUNIT, MODULUSOFLINEARSUBGRADEREACTIONUNIT, + MODULUSOFROTATIONALSUBGRADEREACTIONUNIT, PHUNIT, ROTATIONALMASSUNIT, SECTIONAREAINTEGRALUNIT, + SECTIONMODULUSUNIT, SOUNDPOWERLEVELUNIT, SOUNDPOWERUNIT, SOUNDPRESSURELEVELUNIT, SOUNDPRESSUREUNIT, + TEMPERATUREGRADIENTUNIT, TEMPERATURERATEOFCHANGEUNIT, THERMALEXPANSIONCOEFFICIENTUNIT, WARPINGCONSTANTUNIT, + WARPINGMOMENTUNIT, USERDEFINED. + + In case of choosing USERDEFINED, the UserDefinedType parameter needs to be provided + + :param unit_type: A type of unit chosen from the list above. For + example, choosing THERMALCONDUCTANCEUNIT will give you a Thermal conductance. + :param userdefinedtype: The user defined type in case of choosing USERDEFINED, or None for no + user defined type. + :param attributes: a dictionary of attribute names and values. + :return: The newly created IfcDerivedUnit + + Example: + + .. code:: python + + # Linear velocity in m/s + length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT") + #2=IfcSIUnit(*,.LENGTHUNIT.,$,.METRE.) + + time = ifcopenshell.api.unit.add_si_unit(model, unit_type="TIMEUNIT") + #4=IfcSIUnit(*,.TIMEUNIT.,$,.SECOND.) + + linear_velocity = ifcopenshell.api.unit.add_derived_unit(model, 'LINEARVELOCITY', None, {length : 1, time : -1}) + #10=IfcDerivedUnitElement(#2, 1) + #11=IfcDerivedUnitElement(#4, -1) + #12=IfcDerivedUnit((#10,#11),.LINEARVELOCITY.,$) + + """ + derive_unit_elements = [] + + for named_unit in attributes: + derive_unit_elements.append( + file.create_entity("IfcDerivedUnitElement", Unit=named_unit, Exponent=attributes[named_unit]) + ) + + return file.create_entity( + "IfcDerivedUnit", Elements=derive_unit_elements, UnitType=unit_type, UserDefinedType=userdefinedtype + ) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_monetary_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_monetary_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..6c5a90e12d72715c2beeb80c0f74d474e5feba91 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_monetary_unit.py @@ -0,0 +1,42 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell + + +def add_monetary_unit(file: ifcopenshell.file, currency: str = "DOLLARYDOO") -> ifcopenshell.entity_instance: + """Add a new currency + + Currency units are useful in cost plans to know in what currency the + costs are calculated in. The currencies should follow ISO 4217, like + USD, GBP, AUD, MYR, etc. + + :param currency: The currency code + :return: The newly created IfcMonetaryUnit + + Example: + + .. code:: python + + # If you do all your cost plans in Zimbabwean dollars then nobody + # knows how accurate the numbers are. + zwl = ifcopenshell.api.unit.add_monetary_unit(model, currency="ZWL") + + # Make it our default currency + ifcopenshell.api.unit.assign_unit(model, units=[zwl]) + """ + return file.create_entity("IfcMonetaryUnit", currency) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_si_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_si_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..50da1c10f2d22f50e045f0ddd281516e480e3d52 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_si_unit.py @@ -0,0 +1,59 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.util.unit +from typing import Optional + + +def add_si_unit( + file: ifcopenshell.file, unit_type: str = "LENGTHUNIT", prefix: Optional[str] = None +) -> ifcopenshell.entity_instance: + """Add a new SI unit + + The supported types are ABSORBEDDOSEUNIT, AMOUNTOFSUBSTANCEUNIT, + AREAUNIT, DOSEEQUIVALENTUNIT, ELECTRICCAPACITANCEUNIT, + ELECTRICCHARGEUNIT, ELECTRICCONDUCTANCEUNIT, ELECTRICCURRENTUNIT, + ELECTRICRESISTANCEUNIT, ELECTRICVOLTAGEUNIT, ENERGYUNIT, FORCEUNIT, + FREQUENCYUNIT, ILLUMINANCEUNIT, INDUCTANCEUNIT, LENGTHUNIT, + LUMINOUSFLUXUNIT, LUMINOUSINTENSITYUNIT, MAGNETICFLUXDENSITYUNIT, + MAGNETICFLUXUNIT, MASSUNIT, PLANEANGLEUNIT, POWERUNIT, PRESSUREUNIT, + RADIOACTIVITYUNIT, SOLIDANGLEUNIT, THERMODYNAMICTEMPERATUREUNIT, + TIMEUNIT, VOLUMEUNIT. + + Prefixes supported are ATTO, CENTI, DECA, DECI, EXA, FEMTO, GIGA, HECTO, + KILO, MEGA, MICRO, MILLI, NANO, PETA, PICO, TERA. + + :param unit_type: A type of unit chosen from the list above. For + example, choosing LENGTHUNIT will give you a metre. + :param prefix: A prefix chosen from the list above, or None for no + prefix. + :return: The newly created IfcSIUnit + + Example: + + .. code:: python + + # Millimeters and square meters + length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI") + area = ifcopenshell.api.unit.add_si_unit(model, unit_type="AREAUNIT") + + # Make it our default units, if we are doing a metric building + ifcopenshell.api.unit.assign_unit(model, units=[length, area]) + """ + name = ifcopenshell.util.unit.si_type_names.get(unit_type, None) + return file.create_entity("IfcSIUnit", UnitType=unit_type, Name=name, Prefix=prefix) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/assign_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/assign_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..d57acbd43572f3d72ecc516adb958065e0191f45 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/assign_unit.py @@ -0,0 +1,162 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell +import ifcopenshell.util.unit +from typing import Optional, Any + + +def assign_unit( + file: ifcopenshell.file, + units: Optional[list[ifcopenshell.entity_instance]] = None, + length: Optional[dict] = None, + area: Optional[dict] = None, + volume: Optional[dict] = None, +) -> ifcopenshell.entity_instance: + """Assign default project units + + Whenever a unitised quantity is specified, such as a length, area, + voltage, pressure, etc, these project units are used by default. + + It is also possible to override units for specific properties. For + example, generally you might want square metres for area measurements, + but you might want square millimeters for the measurements of the cross + sectional area of cables in cable trays. However, this function only + deals with the default project units. + + :param units: A list of units to assign as project defaults. See + ifcopenshell.api.unit.add_si_unit, unit.add_conversion_based_unit, + and unit.add_monetary_unit for information on how to create units. + :return: The IfcUnitAssignment element + + Example: + + .. code:: python + + # You need a project before you can assign units. + ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject") + + # Millimeters and square meters + length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI") + area = ifcopenshell.api.unit.add_si_unit(model, unit_type="AREAUNIT") + + # Make it our default units, if we are doing a metric building + ifcopenshell.api.unit.assign_unit(model, units=[length, area]) + + # Alternatively, you may specify without any arguments to + # automatically create millimeters, square meters, and cubic meters + # as a convenience for testing purposes. Sorry imperial folks, we + # prioritise metric here. + ifcopenshell.api.unit.assign_unit(model) + """ + usecase = Usecase() + usecase.file = file + usecase.settings = {"units": units} + # This is a convenience function, likely to be deprecated in the future. + usecase.settings["length"] = length or {"is_metric": True, "raw": "MILLIMETERS"} + usecase.settings["area"] = area or {"is_metric": True, "raw": "METERS"} + usecase.settings["volume"] = volume or {"is_metric": True, "raw": "METERS"} + return usecase.execute() + + +class Usecase: + file: ifcopenshell.file + settings: dict[str, Any] + + def execute(self): + # We're going to refactor this to split unit creation and assignment + if self.settings["units"]: + units = self.settings["units"] + else: + del self.settings["units"] # TODO refactor + units = [] + for unit_type, data in self.settings.items(): + if data["is_metric"]: + units.append(self.create_metric_unit(unit_type, data)) + else: + units.append(self.create_imperial_unit(unit_type, data)) + + unit_assignment = self.get_unit_assignment() + self.assign_units(unit_assignment, units) + return unit_assignment + + def get_unit_assignment(self) -> ifcopenshell.entity_instance: + if not (unit_assignment := ifcopenshell.util.unit.get_unit_assignment(self.file)): + unit_assignment = self.file.createIfcUnitAssignment() + self.file.by_type("IfcProject")[0].UnitsInContext = unit_assignment + return unit_assignment + + def assign_units( + self, unit_assignment: ifcopenshell.entity_instance, new_units: list[ifcopenshell.entity_instance] + ) -> None: + new_unit_types = [u.UnitType if not u.is_a("IfcMonetaryUnit") else u.is_a() for u in new_units] + units = set( + [ + u + for u in (unit_assignment.Units or []) + if u.is_a() not in new_unit_types and getattr(u, "UnitType", None) not in new_unit_types + ] + ) + for unit in new_units: + units.add(unit) + unit_assignment.Units = list(units) + + def create_metric_unit(self, unit_type: str, data: dict) -> ifcopenshell.entity_instance: + type_prefix = "" + if unit_type == "area": + type_prefix = "SQUARE_" + elif unit_type == "volume": + type_prefix = "CUBIC_" + return self.file.createIfcSIUnit( + None, + "{}UNIT".format(unit_type.upper()), + ifcopenshell.util.unit.get_prefix(data["raw"]), + type_prefix + ifcopenshell.util.unit.get_unit_name(data["raw"]), + ) + + def create_imperial_unit(self, unit_type: str, data: dict) -> ifcopenshell.entity_instance: + if unit_type == "length": + dimensional_exponents = self.file.createIfcDimensionalExponents(1, 0, 0, 0, 0, 0, 0) + name_prefix = "" + elif unit_type == "area": + dimensional_exponents = self.file.createIfcDimensionalExponents(2, 0, 0, 0, 0, 0, 0) + name_prefix = "square" + elif unit_type == "volume": + dimensional_exponents = self.file.createIfcDimensionalExponents(3, 0, 0, 0, 0, 0, 0) + name_prefix = "cubic" + si_unit = self.file.createIfcSIUnit( + None, + "{}UNIT".format(unit_type.upper()), + None, + "{}METRE".format(name_prefix.upper() + "_" if name_prefix else ""), + ) + if data["raw"] == "INCHES": + name = "{}inch".format(name_prefix + " " if name_prefix else "") + elif data["raw"] == "FEET": + name = "{}foot".format(name_prefix + " " if name_prefix else "") + elif data["raw"] == "MILES": + name = "{}mile".format(name_prefix + " " if name_prefix else "") + elif data["raw"] == "THOU": + name = "{}thou".format(name_prefix + " " if name_prefix else "") + value_component = self.file.create_entity( + "IfcReal", **{"wrappedValue": ifcopenshell.util.unit.si_conversions[name]} + ) + conversion_factor = self.file.createIfcMeasureWithUnit(value_component, si_unit) + return self.file.createIfcConversionBasedUnit( + dimensional_exponents, "{}UNIT".format(unit_type.upper()), name, conversion_factor + ) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_derived_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_derived_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..5bc9bbd3162a05a39bf1b0e7670d7950e3a15e2c --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_derived_unit.py @@ -0,0 +1,33 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_derived_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcDerivedUnit + + For more information about the attributes and data types of an + IfcDerivedUnit, consult the IFC documentation. + + :param unit: The IfcDerivedUnit entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + """ + for name, value in attributes.items(): + setattr(unit, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_monetary_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_monetary_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..bccc61afc070b856eb4e83fdd3d82584bda878cd --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_monetary_unit.py @@ -0,0 +1,44 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_monetary_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcMonetaryUnit + + For more information about the attributes and data types of an + IfcMonetaryUnit, consult the IFC documentation. + + :param unit: The IfcMonetaryUnit entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + # If you do all your cost plans in Zimbabwean dollars then nobody + # knows how accurate the numbers are. + zwl = ifcopenshell.api.unit.add_monetary_unit(model, currency="ZWL") + + # Ah who are we kidding + ifcopenshell.api.unit.edit_monetary_unit(model, unit=zwl, attributes={"Currency": "USD"}) + """ + for name, value in attributes.items(): + setattr(unit, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_named_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_named_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..683feb72160d7add242189e04c7cabb8955dc393 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_named_unit.py @@ -0,0 +1,54 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Any + + +def edit_named_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None: + """Edits the attributes of an IfcNamedUnit + + Named units include SI units, conversion based units (imperial units), + and context dependent units. + + For more information about the attributes and data types of an + IfcNamedUnit, consult the IFC documentation. + + :param unit: The IfcNamedUnit entity you want to edit + :param attributes: a dictionary of attribute names and values. + :return: None + + Example: + + .. code:: python + + # Boxes of things + unit = ifcopenshell.api.unit.add_context_dependent_unit(model, name="BOXES") + + # Uh, crates? Boxes? Whatever. + ifcopenshell.api.unit.edit_named_unit(model, unit=unit, attibutes={"Name": "CRATES"}) + """ + for name, value in attributes.items(): + if name == "Dimensions": + dimensions = unit.Dimensions + if file.get_total_inverses(dimensions) > 1: + unit.Dimensions = file.createIfcDimensionalExponents(*value) + else: + for i, exponent in enumerate(value): + dimensions[i] = exponent + continue + setattr(unit, name, value) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/remove_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/remove_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..a9920e0e5c950090802d36ce5c810ca160dfe3cb --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/remove_unit.py @@ -0,0 +1,50 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . + +import ifcopenshell.util.unit +import ifcopenshell.util.element + + +def remove_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance) -> None: + """Remove a unit + + Be very careful when a unit is removed, as it may mean that previously + defined quantities in the model completely lose their meaning. + + :param unit: The unit element to remove + :return: None + + Example: + + .. code:: python + + # What? + unit = ifcopenshell.api.unit.add_context_dependent_unit(model, name="HANDFULS") + + # Yeah maybe not. + ifcopenshell.api.unit.remove_unit(model, unit=unit) + """ + unit_assignment = ifcopenshell.util.unit.get_unit_assignment(file) + if unit_assignment and unit in unit_assignment.Units: + units = list(unit_assignment.Units) + units.remove(unit) + if units: + unit_assignment.Units = units + else: + file.remove(unit_assignment) + ifcopenshell.util.element.remove_deep(file, unit) diff --git a/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/unassign_unit.py b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/unassign_unit.py new file mode 100644 index 0000000000000000000000000000000000000000..443d9d0b1cced035892c0595f52935f29d2afc17 --- /dev/null +++ b/data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/unassign_unit.py @@ -0,0 +1,54 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# 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 . +import ifcopenshell +from typing import Optional + + +def unassign_unit(file: ifcopenshell.file, units: Optional[list[ifcopenshell.entity_instance]] = None) -> None: + """Unassigns units as default units for the project + + :param units: A list of units to unassign as project defaults. + :return: None + + Example: + + .. code:: python + + # You need a project before you can assign units. + ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject") + + # Millimeters and square meters + length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI") + area = ifcopenshell.api.unit.add_si_unit(model, unit_type="AREAUNIT") + + # Make it our default units, if we are doing a metric building + ifcopenshell.api.unit.assign_unit(model, units=[length, area]) + + # Actually, we don't need areas. + ifcopenshell.api.unit.unassign_unit(model, units=[area]) + """ + unit_assignments = file.by_type("IfcUnitAssignment") + if not unit_assignments: + return + unit_assignment = unit_assignments[0] + units_set = set(unit_assignment.Units or []) + units_set = units_set - set(units or []) + if units_set: + unit_assignment.Units = list(units_set) + return + file.remove(unit_assignment)