mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
typing
This commit is contained in:
@@ -36,15 +36,12 @@ def add_resource_quantity(
|
||||
This base quantity is then used in other calculations.
|
||||
|
||||
:param resource: The IfcConstructionResource to add a quantity to.
|
||||
:type resource: ifcopenshell.entity_instance
|
||||
: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).
|
||||
:type ifc_class: str,optional
|
||||
:return: The newly created quantity depending on the IFC class
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
|
||||
@@ -65,8 +62,6 @@ def add_resource_quantity(
|
||||
ifcopenshell.api.resource.edit_resource_quantity(model,
|
||||
physical_quantity=quantity, attributes={"TimeValue": 8.0})
|
||||
"""
|
||||
settings = {"resource": resource, "ifc_class": ifc_class}
|
||||
|
||||
resource_type = resource.is_a()
|
||||
supported_quantities = ifcopenshell.util.resource.RESOURCES_TO_QUANTITIES[resource_type]
|
||||
if ifc_class not in supported_quantities:
|
||||
@@ -75,14 +70,14 @@ def add_resource_quantity(
|
||||
f"Supported quantities: {','.join(supported_quantities)}"
|
||||
)
|
||||
|
||||
quantity = file.create_entity(settings["ifc_class"], Name="Unnamed")
|
||||
quantity = file.create_entity(ifc_class, Name="Unnamed")
|
||||
# 3 IfcPhysicalSimpleQuantity Value
|
||||
if settings["ifc_class"] == "IfcQuantityCount":
|
||||
if ifc_class == "IfcQuantityCount":
|
||||
quantity[3] = 0
|
||||
else:
|
||||
quantity[3] = 0.0
|
||||
old_quantity = settings["resource"].BaseQuantity
|
||||
settings["resource"].BaseQuantity = quantity
|
||||
old_quantity = resource.BaseQuantity
|
||||
resource.BaseQuantity = quantity
|
||||
if old_quantity:
|
||||
ifcopenshell.util.element.remove_deep(file, old_quantity)
|
||||
return quantity
|
||||
|
||||
@@ -26,11 +26,8 @@ def edit_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instanc
|
||||
IfcResource, consult the IFC documentation.
|
||||
|
||||
: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
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
@@ -42,7 +39,5 @@ def edit_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instanc
|
||||
# Change the name of the resource to "Zone A Crew"
|
||||
ifcopenshell.api.resource.edit_resource(model, resource=resource, attributes={"Name": "Foo"})
|
||||
"""
|
||||
settings = {"resource": resource, "attributes": attributes}
|
||||
|
||||
for name, value in settings["attributes"].items():
|
||||
setattr(settings["resource"], name, value)
|
||||
for name, value in attributes.items():
|
||||
setattr(resource, name, value)
|
||||
|
||||
@@ -28,11 +28,8 @@ def edit_resource_quantity(
|
||||
IfC quantity, consult the IFC documentation.
|
||||
|
||||
: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
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
@@ -53,10 +50,5 @@ def edit_resource_quantity(
|
||||
ifcopenshell.api.resource.edit_resource_quantity(model,
|
||||
physical_quantity=time, attributes={"TimeValue": 8.0})
|
||||
"""
|
||||
settings = {
|
||||
"physical_quantity": physical_quantity,
|
||||
"attributes": attributes,
|
||||
}
|
||||
|
||||
for name, value in settings["attributes"].items():
|
||||
setattr(settings["physical_quantity"], name, value)
|
||||
for name, value in attributes.items():
|
||||
setattr(physical_quantity, name, value)
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.sequence
|
||||
import ifcopenshell.util.constraint
|
||||
import ifcopenshell.util.date
|
||||
import ifcopenshell.util.resource
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -30,11 +33,8 @@ def edit_resource_time(
|
||||
IfcResourceTime, consult the IFC documentation.
|
||||
|
||||
: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
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
@@ -62,25 +62,23 @@ def edit_resource_time(
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {"resource_time": resource_time, "attributes": attributes}
|
||||
return usecase.execute()
|
||||
return usecase.execute(resource_time, attributes)
|
||||
|
||||
|
||||
class Usecase:
|
||||
def execute(self):
|
||||
self.resource = self.get_resource()
|
||||
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 (
|
||||
self.settings["attributes"].get("ScheduleWork", None)
|
||||
and "ScheduleFinish" in self.settings["attributes"].keys()
|
||||
):
|
||||
del self.settings["attributes"]["ScheduleFinish"]
|
||||
if self.settings["attributes"].get("ActualWork", None) and "ActualFinish" in self.settings["attributes"].keys():
|
||||
del self.settings["attributes"]["ActualFinish"]
|
||||
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 self.settings["attributes"].items():
|
||||
metrics = ifcopenshell.util.constraint.get_metric_constraints(self.resource, "Usage." + name)
|
||||
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:
|
||||
@@ -88,13 +86,13 @@ class Usecase:
|
||||
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime")
|
||||
elif name == "ScheduleWork" or name == "ActualWork" or name == "RemainingTime":
|
||||
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDuration")
|
||||
setattr(self.settings["resource_time"], name, value)
|
||||
setattr(resource_time, name, value)
|
||||
if name == "ScheduleUsage" and ifcopenshell.util.constraint.get_metric_constraints(
|
||||
self.resource, "Usage.ScheduleWork"
|
||||
resource, "Usage.ScheduleWork"
|
||||
):
|
||||
task = ifcopenshell.util.resource.get_task_assignments(self.resource)
|
||||
task = ifcopenshell.util.resource.get_task_assignments(resource)
|
||||
if task:
|
||||
ifcopenshell.api.sequence.calculate_task_duration(self.file, task=task)
|
||||
|
||||
def get_resource(self):
|
||||
return [e for e in self.file.get_inverse(self.settings["resource_time"]) if e.is_a("IfcResource")][0]
|
||||
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"))
|
||||
|
||||
Reference in New Issue
Block a user