This commit is contained in:
Andrej730
2024-05-10 11:21:53 +05:00
parent e7eb00eaa3
commit c50d1ea2fe
105 changed files with 502 additions and 251 deletions
@@ -17,15 +17,16 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.api
from typing import Optional
def add_resource(
file,
parent_resource=None,
ifc_class="IfcCrewResource",
name=None,
predefined_type="NOTDEFINED",
) -> None:
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
@@ -48,7 +49,7 @@ def add_resource(
:param parent_resource: If this is a child resource (typically to a crew
resource), then nominate the parent IfcConstructionResource here.
:type parent_resource: ifcopenshell.entity_instance
:type parent_resource: ifcopenshell.entity_instance, optional
:param ifc_class: The class of resource chosen from
IfcConstructionEquipmentResource, IfcConstructionMaterialResource,
IfcConstructionProductResource, IfcCrewResource, IfcLaborResource,
@@ -19,7 +19,9 @@
import ifcopenshell.util.element
def add_resource_quantity(file, resource=None, ifc_class="IfcQuantityCount") -> None:
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
@@ -65,6 +67,7 @@ def add_resource_quantity(file, resource=None, ifc_class="IfcQuantityCount") ->
settings = {"resource": resource, "ifc_class": ifc_class}
quantity = file.create_entity(settings["ifc_class"], Name="Unnamed")
# 3 IfcPhysicalSimpleQuantity Value
quantity[3] = 0.0
old_quantity = settings["resource"].BaseQuantity
settings["resource"].BaseQuantity = quantity
@@ -19,7 +19,7 @@
import ifcopenshell.util.date
def add_resource_time(file, resource=None) -> None:
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
@@ -21,7 +21,11 @@ import ifcopenshell.api
import ifcopenshell.guid
def assign_resource(file, relating_resource=None, related_object=None) -> None:
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
@@ -89,7 +93,7 @@ def assign_resource(file, relating_resource=None, related_object=None) -> None:
assignment.is_a("IfclRelAssignsToResource")
and assignment.RelatingResource == settings["relating_resource"]
):
return
return assignment
resource_of = None
if settings["relating_resource"].ResourceOf:
@@ -18,12 +18,13 @@
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, resource=None) -> None:
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."""
settings = {"resource": resource}
@@ -18,12 +18,13 @@
import math
import ifcopenshell.api
import ifcopenshell.util.constraint
import ifcopenshell.util.date
import ifcopenshell.util.element
import ifcopenshell.util.resource
def calculate_resource_work(file, resource=None) -> None:
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
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_resource(file, resource=None, attributes=None) -> None:
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
@@ -26,7 +28,7 @@ def edit_resource(file, resource=None, attributes=None) -> None:
:param resource: The IfcResource entity you want to edit
:type resource: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -40,7 +42,7 @@ def edit_resource(file, resource=None, attributes=None) -> None:
# Change the name of the resource to "Zone A Crew"
ifcopenshell.api.run("resource.edit_resource", model, resource=resource, attributes={"Name": "Foo"})
"""
settings = {"resource": resource, "attributes": attributes or {}}
settings = {"resource": resource, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["resource"], name, value)
@@ -15,9 +15,13 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_resource_quantity(file, physical_quantity=None, attributes=None) -> None:
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
@@ -26,7 +30,7 @@ def edit_resource_quantity(file, physical_quantity=None, attributes=None) -> Non
:param physical_quantity: The IfC quantity entity you want to edit
:type physical_quantity: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -51,7 +55,7 @@ def edit_resource_quantity(file, physical_quantity=None, attributes=None) -> Non
"""
settings = {
"physical_quantity": physical_quantity,
"attributes": attributes or {},
"attributes": attributes,
}
for name, value in settings["attributes"].items():
@@ -18,9 +18,12 @@
import datetime
import ifcopenshell
from typing import Any
def edit_resource_time(file, resource_time=None, attributes=None) -> None:
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
@@ -29,7 +32,7 @@ def edit_resource_time(file, resource_time=None, attributes=None) -> None:
:param resource_time: The IfcResourceTime entity you want to edit
:type resource_time: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -59,7 +62,7 @@ def edit_resource_time(file, resource_time=None, attributes=None) -> None:
"""
usecase = Usecase()
usecase.file = file
usecase.settings = {"resource_time": resource_time, "attributes": attributes or {}}
usecase.settings = {"resource_time": resource_time, "attributes": attributes}
return usecase.execute()
@@ -21,7 +21,7 @@ import ifcopenshell.api
import ifcopenshell.util.element
def remove_resource(file, resource=None) -> None:
def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None:
"""Removes a resource and all relationships
Example:
@@ -19,7 +19,7 @@
import ifcopenshell.util.element
def remove_resource_quantity(file, resource=None) -> None:
def remove_resource_quantity(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None:
"""Removes the base quantity of a resource
Example:
@@ -21,7 +21,11 @@ import ifcopenshell.api
import ifcopenshell.util.element
def unassign_resource(file, relating_resource=None, related_object=None) -> None:
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.
@@ -29,8 +33,8 @@ def unassign_resource(file, relating_resource=None, related_object=None) -> None
:param related_object: The IfcProduct or IfcActor to assign to the
object.
:type related_object: ifcopenshell.entity_instance
:return: The newly created IfcRelAssignsToResource
:rtype: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -74,4 +78,3 @@ def unassign_resource(file, relating_resource=None, related_object=None) -> None
related_objects.remove(settings["related_object"])
rel.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": rel})
return rel