This commit is contained in:
Andrej730
2024-11-11 11:56:37 +05:00
parent 088bc207ab
commit 004488533f
5 changed files with 18 additions and 23 deletions
@@ -151,7 +151,7 @@ class UpdateIfcPatchArguments(bpy.types.Operator):
new_attr.set_value(arg_info.get("default", new_attr.get_value_default())) new_attr.set_value(arg_info.get("default", new_attr.get_value_default()))
return {"FINISHED"} return {"FINISHED"}
def pretty_arg_name(self, arg_name: str): def pretty_arg_name(self, arg_name: str) -> str:
words = [] words = []
for word in arg_name.split("_"): for word in arg_name.split("_"):
+8 -15
View File
@@ -23,6 +23,7 @@ import ifcopenshell.util.constraint
import ifcopenshell.util.cost import ifcopenshell.util.cost
import ifcopenshell.util.date import ifcopenshell.util.date
import ifcopenshell.util.resource import ifcopenshell.util.resource
from typing import Any
def refresh(): def refresh():
@@ -44,11 +45,11 @@ class ResourceData:
cls.is_loaded = True cls.is_loaded = True
@classmethod @classmethod
def total_resources(cls): def total_resources(cls) -> int:
return len(tool.Ifc.get().by_type("IfcResource")) return len(tool.Ifc.get().by_type("IfcResource"))
@classmethod @classmethod
def resources(cls): def resources(cls) -> dict[int, dict[str, Any]]:
results = {} results = {}
for resource in tool.Ifc.get().by_type("IfcResource"): for resource in tool.Ifc.get().by_type("IfcResource"):
base_quantity = None base_quantity = None
@@ -63,7 +64,7 @@ class ResourceData:
if resource.is_a() in ["IfcLaborResource", "IfcConstructionEquipmentResource"]: if resource.is_a() in ["IfcLaborResource", "IfcConstructionEquipmentResource"]:
results[resource.id()]["Productivity"] = {} results[resource.id()]["Productivity"] = {}
results[resource.id()]["InheritedProductivity"] = {} results[resource.id()]["InheritedProductivity"] = {}
productivity = cls.get_productivity(resource) productivity = ifcopenshell.util.resource.get_productivity(resource, should_inherit=False)
if productivity: if productivity:
results[resource.id()]["Productivity"] = { results[resource.id()]["Productivity"] = {
"id": productivity.get("id"), "id": productivity.get("id"),
@@ -71,7 +72,7 @@ class ResourceData:
"TimeConsumed": ifcopenshell.util.resource.get_unit_consumed(productivity), "TimeConsumed": ifcopenshell.util.resource.get_unit_consumed(productivity),
"QuantityProducedName": ifcopenshell.util.resource.get_quantity_produced_name(productivity), "QuantityProducedName": ifcopenshell.util.resource.get_quantity_produced_name(productivity),
} }
inherited_productivity = cls.get_parent_productivity(resource) inherited_productivity = ifcopenshell.util.resource.get_parent_productivity(resource)
if inherited_productivity: if inherited_productivity:
results[resource.id()]["InheritedProductivity"] = { results[resource.id()]["InheritedProductivity"] = {
"QuantityProduced": ifcopenshell.util.resource.get_quantity_produced(inherited_productivity), "QuantityProduced": ifcopenshell.util.resource.get_quantity_produced(inherited_productivity),
@@ -94,7 +95,7 @@ class ResourceData:
return results return results
@classmethod @classmethod
def sum_person_hours(cls, resource): def sum_person_hours(cls, resource: ifcopenshell.entity_instance) -> float:
sum = 0 sum = 0
nested_resources = ifcopenshell.util.resource.get_nested_resources(resource) nested_resources = ifcopenshell.util.resource.get_nested_resources(resource)
for nested_resource in nested_resources or []: for nested_resource in nested_resources or []:
@@ -105,7 +106,7 @@ class ResourceData:
return round(float(sum), 2) if sum else 0 return round(float(sum), 2) if sum else 0
@classmethod @classmethod
def get_resource_benchmarks(cls, resource): def get_resource_benchmarks(cls, resource: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
constraints = [] constraints = []
for constraint in ifcopenshell.util.constraint.get_constraints(resource) or []: for constraint in ifcopenshell.util.constraint.get_constraints(resource) or []:
metrics = [] metrics = []
@@ -121,15 +122,7 @@ class ResourceData:
return constraints return constraints
@classmethod @classmethod
def get_productivity(cls, resource): def cost_values(cls) -> list[dict[str, Any]]:
return ifcopenshell.util.resource.get_productivity(resource, should_inherit=False)
@classmethod
def get_parent_productivity(cls, resource):
return ifcopenshell.util.resource.get_parent_productivity(resource)
@classmethod
def cost_values(cls):
results = [] results = []
ifc_id = bpy.context.scene.BIMResourceProperties.active_resource_id ifc_id = bpy.context.scene.BIMResourceProperties.active_resource_id
if not ifc_id: if not ifc_id:
+2 -2
View File
@@ -176,14 +176,14 @@ class MultipleFileSelect(PropertyGroup):
single_file: bpy.props.StringProperty(name="Single File Path", description="", update=update_single_file) single_file: bpy.props.StringProperty(name="Single File Path", description="", update=update_single_file)
file_list: bpy.props.CollectionProperty(type=StrProperty) file_list: bpy.props.CollectionProperty(type=StrProperty)
def set_file_list(self, dirname: str, files: list[str]): def set_file_list(self, dirname: str, files: list[str]) -> None:
self.file_list.clear() self.file_list.clear()
for f in files: for f in files:
new = self.file_list.add() new = self.file_list.add()
new.name = os.path.join(dirname, f) new.name = os.path.join(dirname, f)
def layout_file_select(self, layout, filter_glob="", text=""): def layout_file_select(self, layout: bpy.types.UILayout, filter_glob: str = "", text: str = "") -> None:
if len(self.file_list) > 1: if len(self.file_list) > 1:
layout.label(text=f"{len(self.file_list)} Files Selected") layout.label(text=f"{len(self.file_list)} Files Selected")
else: else:
+7 -4
View File
@@ -27,7 +27,7 @@ import inspect
import collections import collections
import importlib import importlib
import importlib.util import importlib.util
from typing import Union from typing import Union, Iterable, Optional, Any
__version__ = version = "0.0.0" __version__ = version = "0.0.0"
@@ -114,7 +114,7 @@ def write(output: Union[ifcopenshell.file, str], filepath: str) -> None:
def extract_docs( def extract_docs(
submodule_name: str, cls_name: str, method_name: str = "__init__", boilerplate_args: typing.Iterable[str] = None submodule_name: str, cls_name: str, method_name: str = "__init__", boilerplate_args: Optional[Iterable[str]] = None
): ):
"""Extract class docstrings and method arguments """Extract class docstrings and method arguments
@@ -137,10 +137,10 @@ def extract_docs(
print(f"Error : IFCPatch {str(submodule)} could not load because : {str(e)}") print(f"Error : IFCPatch {str(submodule)} could not load because : {str(e)}")
def _extract_docs(cls, method_name, boilerplate_args): def _extract_docs(cls: type, method_name: str, boilerplate_args: Union[Iterable[str], None]):
inputs = collections.OrderedDict() inputs = collections.OrderedDict()
method = getattr(cls, method_name) method = getattr(cls, method_name)
docs = {"class": cls} docs: dict[str, Any] = {"class": cls}
if boilerplate_args is None: if boilerplate_args is None:
boilerplate_args = [] boilerplate_args = []
@@ -152,6 +152,7 @@ def _extract_docs(cls, method_name, boilerplate_args):
if isinstance(parameter.default, (str, float, int, bool)): if isinstance(parameter.default, (str, float, int, bool)):
inputs[name]["default"] = parameter.default inputs[name]["default"] = parameter.default
# Parse data from type hints.
type_hints = typing.get_type_hints(method) type_hints = typing.get_type_hints(method)
for input_name in inputs.keys(): for input_name in inputs.keys():
type_hint = type_hints.get(input_name, None) type_hint = type_hints.get(input_name, None)
@@ -172,6 +173,7 @@ def _extract_docs(cls, method_name, boilerplate_args):
else: else:
inputs[input_name]["type"] = type_hint.__name__ inputs[input_name]["type"] = type_hint.__name__
# Parse the docstring.
description = "" description = ""
doc = method.__doc__ doc = method.__doc__
if doc is not None: if doc is not None:
@@ -185,6 +187,7 @@ def _extract_docs(cls, method_name, boilerplate_args):
param_name = line.split(":")[1].strip().replace("param ", "") param_name = line.split(":")[1].strip().replace("param ", "")
if param_name in inputs: if param_name in inputs:
inputs[param_name]["description"] = line.split(":")[2].strip() inputs[param_name]["description"] = line.split(":")[2].strip()
# :filter_glob is our special doc-tag.
elif line.startswith(":filter_glob"): elif line.startswith(":filter_glob"):
param_name = line.split(":")[1].strip().replace("filter_glob ", "") param_name = line.split(":")[1].strip().replace("filter_glob ", "")
if param_name in inputs: if param_name in inputs:
@@ -42,7 +42,6 @@ class Patcher:
:param filepaths: The filepath(s) of the second (, third, ...) IFC model :param filepaths: The filepath(s) of the second (, third, ...) IFC model
to merge into the first. The first model is already specified as the to merge into the first. The first model is already specified as the
input to IfcPatch. input to IfcPatch.
:type filepaths: list[Union[str, ifcopenshell.file]]
:filter_glob filepaths: *.ifc;*.ifczip;*.ifcxml :filter_glob filepaths: *.ifc;*.ifczip;*.ifcxml
Example: Example: