mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 17:26:30 +00:00
typing
This commit is contained in:
@@ -289,7 +289,7 @@ def calculate_cost_item_resource_value(ifc: tool.Ifc, cost_item: ifcopenshell.en
|
|||||||
ifc.run("cost.calculate_cost_item_resource_value", cost_item=cost_item)
|
ifc.run("cost.calculate_cost_item_resource_value", cost_item=cost_item)
|
||||||
|
|
||||||
|
|
||||||
def export_cost_schedules(cost: tool.Cost, filepath, format, cost_schedule=None):
|
def export_cost_schedules(cost: tool.Cost, filepath: str, format: str, cost_schedule=None):
|
||||||
cost.play_sound()
|
cost.play_sound()
|
||||||
return cost.export_cost_schedules(filepath, format, cost_schedule)
|
return cost.export_cost_schedules(filepath, format, cost_schedule)
|
||||||
|
|
||||||
|
|||||||
@@ -529,7 +529,7 @@ class Cost(blenderbim.core.tool.Cost):
|
|||||||
props.is_cost_update_enabled = True
|
props.is_cost_update_enabled = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_cost_schedules(cls, filepath, format=None, cost_schedule=None):
|
def export_cost_schedules(cls, filepath: str, format: str, cost_schedule=None):
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -642,7 +642,7 @@ class Cost(blenderbim.core.tool.Cost):
|
|||||||
return bool(cost_items)
|
return bool(cost_items)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_product_cost_items(cls, product):
|
def load_product_cost_items(cls, product: ifcopenshell.entity_instance) -> None:
|
||||||
props = bpy.context.scene.BIMCostProperties
|
props = bpy.context.scene.BIMCostProperties
|
||||||
props.is_cost_update_enabled = False
|
props.is_cost_update_enabled = False
|
||||||
props.product_cost_items.clear()
|
props.product_cost_items.clear()
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ class Csv2Ifc:
|
|||||||
|
|
||||||
self.create_cost_items(cost_item["children"], cost_item["ifc"])
|
self.create_cost_items(cost_item["children"], cost_item["ifc"])
|
||||||
|
|
||||||
def create_unit(self, symbol) -> ifcopenshell.entity_instance:
|
def create_unit(self, symbol: str) -> ifcopenshell.entity_instance:
|
||||||
unit = self.units.get(symbol, None)
|
unit = self.units.get(symbol, None)
|
||||||
if unit:
|
if unit:
|
||||||
return unit
|
return unit
|
||||||
@@ -227,7 +227,7 @@ class Csv2Ifc:
|
|||||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
|
|
||||||
|
|
||||||
def has_property(self, product, property_name) -> bool:
|
def has_property(self, product: ifcopenshell.entity_instance, property_name: str) -> bool:
|
||||||
if not property_name:
|
if not property_name:
|
||||||
return True
|
return True
|
||||||
qtos = ifcopenshell.util.element.get_psets(product, qtos_only=True)
|
qtos = ifcopenshell.util.element.get_psets(product, qtos_only=True)
|
||||||
|
|||||||
@@ -26,13 +26,18 @@ import ifcopenshell
|
|||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.cost
|
import ifcopenshell.util.cost
|
||||||
import ifcopenshell.util.date
|
import ifcopenshell.util.date
|
||||||
|
from typing import Union, Optional
|
||||||
|
|
||||||
|
|
||||||
class IfcDataGetter:
|
class IfcDataGetter:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_schedules(file, filter_by_schedule=None):
|
def get_schedules(
|
||||||
|
file: ifcopenshell.file, filter_by_schedule: Optional[ifcopenshell.entity_instance] = None
|
||||||
|
) -> list[ifcopenshell.entity_instance]:
|
||||||
return [
|
return [
|
||||||
schedule for schedule in file.by_type("IfcCostSchedule") if not filter_by_schedule or schedule == filter_by_schedule
|
schedule
|
||||||
|
for schedule in file.by_type("IfcCostSchedule")
|
||||||
|
if not filter_by_schedule or schedule == filter_by_schedule
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -195,7 +200,18 @@ class IfcDataGetter:
|
|||||||
|
|
||||||
|
|
||||||
class Ifc5Dwriter:
|
class Ifc5Dwriter:
|
||||||
def __init__(self, file=None, output=None, cost_schedule=None):
|
file: ifcopenshell.file
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
file: Union[str, ifcopenshell.file],
|
||||||
|
output: str,
|
||||||
|
cost_schedule: Optional[ifcopenshell.entity_instance] = None,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
cost_schedule: exported cost schedule. If not provided, will export all available schedules.
|
||||||
|
"""
|
||||||
self.output = output
|
self.output = output
|
||||||
if isinstance(file, str):
|
if isinstance(file, str):
|
||||||
self.file = ifcopenshell.open(file)
|
self.file = ifcopenshell.open(file)
|
||||||
|
|||||||
@@ -17,10 +17,13 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.util.unit
|
||||||
|
|
||||||
|
|
||||||
def add_cost_item_quantity(
|
def add_cost_item_quantity(
|
||||||
file: ifcopenshell.file, cost_item: ifcopenshell.entity_instance, ifc_class: str = "IfcQuantityCount"
|
file: ifcopenshell.file,
|
||||||
|
cost_item: ifcopenshell.entity_instance,
|
||||||
|
ifc_class: ifcopenshell.util.unit.QUANTITY_CLASS = "IfcQuantityCount",
|
||||||
) -> ifcopenshell.entity_instance:
|
) -> ifcopenshell.entity_instance:
|
||||||
"""Adds a new quantity associated with a cost item
|
"""Adds a new quantity associated with a cost item
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,14 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
from typing import Optional
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def assign_cost_item_quantity(
|
def assign_cost_item_quantity(
|
||||||
file: ifcopenshell.file,
|
file: ifcopenshell.file,
|
||||||
cost_item: ifcopenshell.entity_instance,
|
cost_item: ifcopenshell.entity_instance,
|
||||||
products: list[ifcopenshell.entity_instance],
|
products: list[ifcopenshell.entity_instance],
|
||||||
prop_name: Optional[str] = "",
|
prop_name: str = "",
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Adds a cost item quantity that is parametrically connected to a product
|
"""Adds a cost item quantity that is parametrically connected to a product
|
||||||
|
|
||||||
@@ -96,6 +96,9 @@ def assign_cost_item_quantity(
|
|||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
|
file: ifcopenshell.file
|
||||||
|
settings: dict[str, Any]
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
if self.settings["prop_name"]:
|
if self.settings["prop_name"]:
|
||||||
self.quantities = set(self.settings["cost_item"].CostQuantities or [])
|
self.quantities = set(self.settings["cost_item"].CostQuantities or [])
|
||||||
@@ -113,7 +116,9 @@ class Usecase:
|
|||||||
else:
|
else:
|
||||||
self.update_cost_item_count()
|
self.update_cost_item_count()
|
||||||
|
|
||||||
def assign_cost_control(self, related_object, cost_item):
|
def assign_cost_control(
|
||||||
|
self, related_object: ifcopenshell.entity_instance, cost_item: ifcopenshell.entity_instance
|
||||||
|
) -> ifcopenshell.entity_instance:
|
||||||
return ifcopenshell.api.run(
|
return ifcopenshell.api.run(
|
||||||
"control.assign_control",
|
"control.assign_control",
|
||||||
self.file,
|
self.file,
|
||||||
@@ -121,12 +126,12 @@ class Usecase:
|
|||||||
relating_control=cost_item,
|
relating_control=cost_item,
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_quantity_from_related_object(self, element):
|
def add_quantity_from_related_object(self, element: ifcopenshell.entity_instance) -> None:
|
||||||
for relationship in element.IsDefinedBy:
|
for relationship in element.IsDefinedBy:
|
||||||
if relationship.is_a("IfcRelDefinesByProperties"):
|
if relationship.is_a("IfcRelDefinesByProperties"):
|
||||||
self.add_quantity_from_qto(relationship.RelatingPropertyDefinition)
|
self.add_quantity_from_qto(relationship.RelatingPropertyDefinition)
|
||||||
|
|
||||||
def add_quantity_from_qto(self, qto):
|
def add_quantity_from_qto(self, qto: ifcopenshell.entity_instance) -> None:
|
||||||
if not qto.is_a("IfcElementQuantity"):
|
if not qto.is_a("IfcElementQuantity"):
|
||||||
return
|
return
|
||||||
for prop in qto.Quantities:
|
for prop in qto.Quantities:
|
||||||
|
|||||||
@@ -337,6 +337,25 @@ unit_symbols = {
|
|||||||
"fahrenheit": "°F",
|
"fahrenheit": "°F",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUANTITY_CLASS = Literal[
|
||||||
|
"IfcQuantityCount",
|
||||||
|
"IfcQuantityNumber",
|
||||||
|
"IfcQuantityLength",
|
||||||
|
"IfcQuantityArea",
|
||||||
|
"IfcQuantityVolume",
|
||||||
|
"IfcQuantityWeight",
|
||||||
|
"IfcQuantityTime",
|
||||||
|
"IfcQuantityCount",
|
||||||
|
]
|
||||||
|
|
||||||
|
MEASURE_CLASS = Literal[
|
||||||
|
"IfcNumericMeasure",
|
||||||
|
"IfcLengthMeasure",
|
||||||
|
"IfcAreaMeasure",
|
||||||
|
"IfcVolumeMeasure",
|
||||||
|
"IfcMassMeasure",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_prefix(text):
|
def get_prefix(text):
|
||||||
if text:
|
if text:
|
||||||
@@ -468,14 +487,14 @@ def get_property_unit(
|
|||||||
return units[0]
|
return units[0]
|
||||||
|
|
||||||
|
|
||||||
def get_unit_measure_class(unit_type: str) -> str:
|
def get_unit_measure_class(unit_type: str) -> MEASURE_CLASS:
|
||||||
if unit_type == "USERDEFINED":
|
if unit_type == "USERDEFINED":
|
||||||
# See https://github.com/buildingSMART/IFC4.3.x-development/issues/71
|
# See https://github.com/buildingSMART/IFC4.3.x-development/issues/71
|
||||||
return "IfcNumericMeasure"
|
return "IfcNumericMeasure"
|
||||||
return "Ifc" + unit_type[0:-4].lower().capitalize() + "Measure"
|
return "Ifc" + unit_type[0:-4].lower().capitalize() + "Measure"
|
||||||
|
|
||||||
|
|
||||||
def get_measure_unit_type(measure_class: str) -> str:
|
def get_measure_unit_type(measure_class: MEASURE_CLASS) -> str:
|
||||||
if measure_class == "IfcNumericMeasure":
|
if measure_class == "IfcNumericMeasure":
|
||||||
# See https://github.com/buildingSMART/IFC4.3.x-development/issues/71
|
# See https://github.com/buildingSMART/IFC4.3.x-development/issues/71
|
||||||
return "USERDEFINED"
|
return "USERDEFINED"
|
||||||
@@ -484,7 +503,7 @@ def get_measure_unit_type(measure_class: str) -> str:
|
|||||||
return measure_class.upper() + "UNIT"
|
return measure_class.upper() + "UNIT"
|
||||||
|
|
||||||
|
|
||||||
def get_symbol_measure_class(symbol: Optional[str] = None) -> str:
|
def get_symbol_measure_class(symbol: Optional[str] = None) -> MEASURE_CLASS:
|
||||||
# Dumb, but everybody gets it, unlike regex golf
|
# Dumb, but everybody gets it, unlike regex golf
|
||||||
if not symbol:
|
if not symbol:
|
||||||
return "IfcNumericMeasure"
|
return "IfcNumericMeasure"
|
||||||
@@ -502,7 +521,7 @@ def get_symbol_measure_class(symbol: Optional[str] = None) -> str:
|
|||||||
return "IfcNumericMeasure"
|
return "IfcNumericMeasure"
|
||||||
|
|
||||||
|
|
||||||
def get_symbol_quantity_class(symbol: Optional[str] = None) -> str:
|
def get_symbol_quantity_class(symbol: Optional[str] = None) -> QUANTITY_CLASS:
|
||||||
# Dumb, but everybody gets it, unlike regex golf
|
# Dumb, but everybody gets it, unlike regex golf
|
||||||
if not symbol:
|
if not symbol:
|
||||||
return "IfcQuantityCount"
|
return "IfcQuantityCount"
|
||||||
|
|||||||
Reference in New Issue
Block a user