mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
ifc5d - refactor
This commit is contained in:
@@ -165,6 +165,7 @@ class Csv2Ifc:
|
|||||||
def create_ifc(self) -> None:
|
def create_ifc(self) -> None:
|
||||||
if not self.file:
|
if not self.file:
|
||||||
self.create_boilerplate_ifc()
|
self.create_boilerplate_ifc()
|
||||||
|
assert self.file
|
||||||
if not self.cost_schedule:
|
if not self.cost_schedule:
|
||||||
self.cost_schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="CSV Import")
|
self.cost_schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="CSV Import")
|
||||||
if self.is_schedule_of_rates:
|
if self.is_schedule_of_rates:
|
||||||
@@ -179,6 +180,7 @@ class Csv2Ifc:
|
|||||||
self.create_cost_item(cost_item, parent)
|
self.create_cost_item(cost_item, parent)
|
||||||
|
|
||||||
def create_cost_item(self, cost_item: CostItem, parent: Optional[ifcopenshell.entity_instance] = None) -> None:
|
def create_cost_item(self, cost_item: CostItem, parent: Optional[ifcopenshell.entity_instance] = None) -> None:
|
||||||
|
assert self.file
|
||||||
if parent is None:
|
if parent is None:
|
||||||
cost_item["ifc"] = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=self.cost_schedule)
|
cost_item["ifc"] = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=self.cost_schedule)
|
||||||
else:
|
else:
|
||||||
@@ -265,6 +267,7 @@ class Csv2Ifc:
|
|||||||
unit = self.units.get(symbol, None)
|
unit = self.units.get(symbol, None)
|
||||||
if unit:
|
if unit:
|
||||||
return unit
|
return unit
|
||||||
|
assert self.file
|
||||||
unit = self.file.create_entity(
|
unit = self.file.create_entity(
|
||||||
"IfcContextDependentUnit",
|
"IfcContextDependentUnit",
|
||||||
self.file.create_entity("IfcDimensionalExponents", 0, 0, 0, 0, 0, 0, 0),
|
self.file.create_entity("IfcDimensionalExponents", 0, 0, 0, 0, 0, 0, 0),
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class IfcDataGetter:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_root_costs(cost_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
|
def get_root_costs(cost_schedule: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
|
||||||
return [obj for rel in cost_schedule.Controls or [] for obj in rel.RelatedObjects or []]
|
return ifcopenshell.util.cost.get_root_cost_items(cost_schedule)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_cost_item_values(cost_item: Union[ifcopenshell.entity_instance, None]) -> Union[list[dict[str, Any]], None]:
|
def get_cost_item_values(cost_item: Union[ifcopenshell.entity_instance, None]) -> Union[list[dict[str, Any]], None]:
|
||||||
@@ -85,6 +85,9 @@ class IfcDataGetter:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_categories(cost_item: ifcopenshell.entity_instance, categories: set[str]) -> set[str]:
|
def process_categories(cost_item: ifcopenshell.entity_instance, categories: set[str]) -> set[str]:
|
||||||
|
"""
|
||||||
|
:param categories: A set to fill with categories.
|
||||||
|
"""
|
||||||
for cost_value in cost_item.CostValues or []:
|
for cost_value in cost_item.CostValues or []:
|
||||||
if cost_value.Category:
|
if cost_value.Category:
|
||||||
categories.add("{}{}".format(cost_value.Category, " Cost"))
|
categories.add("{}{}".format(cost_value.Category, " Cost"))
|
||||||
@@ -93,14 +96,16 @@ class IfcDataGetter:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def process_cost_item_categories(cost_item: ifcopenshell.entity_instance, categories: set[str]) -> set[str]:
|
def process_cost_item_categories(cost_item: ifcopenshell.entity_instance, categories: set[str]) -> set[str]:
|
||||||
IfcDataGetter.process_categories(cost_item, categories)
|
IfcDataGetter.process_categories(cost_item, categories)
|
||||||
for rel in cost_item.IsNestedBy or []:
|
for child in ifcopenshell.util.cost.get_nested_cost_items(cost_item):
|
||||||
for child in rel.RelatedObjects or []:
|
IfcDataGetter.process_cost_item_categories(child, categories)
|
||||||
IfcDataGetter.process_cost_item_categories(child, categories)
|
|
||||||
return categories
|
return categories
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_cost_rates_categories(schedule: ifcopenshell.entity_instance) -> set[str]:
|
def get_cost_rates_categories(schedule: ifcopenshell.entity_instance) -> set[str]:
|
||||||
categories = set()
|
"""
|
||||||
|
:param categories: A set to fill with categories.
|
||||||
|
"""
|
||||||
|
categories: set[str] = set()
|
||||||
for cost_item in IfcDataGetter.get_root_costs(schedule):
|
for cost_item in IfcDataGetter.get_root_costs(schedule):
|
||||||
IfcDataGetter.process_cost_item_categories(cost_item, categories)
|
IfcDataGetter.process_cost_item_categories(cost_item, categories)
|
||||||
return categories
|
return categories
|
||||||
@@ -110,16 +115,14 @@ class IfcDataGetter:
|
|||||||
file: ifcopenshell.file,
|
file: ifcopenshell.file,
|
||||||
cost_item: ifcopenshell.entity_instance,
|
cost_item: ifcopenshell.entity_instance,
|
||||||
cost_items_data: list[CostItem],
|
cost_items_data: list[CostItem],
|
||||||
index: int,
|
index: int = 1,
|
||||||
hierarchy: str = "1",
|
hierarchy: str = "1",
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
:param cost_items_data: A list to fill with cost items.
|
:param cost_items_data: A list to fill with cost items.
|
||||||
|
:param index: Current hierarchy depth.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def listToString(s):
|
|
||||||
return ", ".join([str(i) for i in s])
|
|
||||||
|
|
||||||
quantity_data = IfcDataGetter.get_cost_item_quantity(file, cost_item)
|
quantity_data = IfcDataGetter.get_cost_item_quantity(file, cost_item)
|
||||||
cost_values_data = IfcDataGetter.get_cost_item_values(cost_item)
|
cost_values_data = IfcDataGetter.get_cost_item_values(cost_item)
|
||||||
|
|
||||||
@@ -150,15 +153,13 @@ class IfcDataGetter:
|
|||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
child_hierarchy = hierarchy + ".1"
|
child_hierarchy = hierarchy + ".1"
|
||||||
for nested_cost in [obj for rel in cost_item.IsNestedBy or [] for obj in rel.RelatedObjects or []]:
|
for i, nested_cost in enumerate(ifcopenshell.util.cost.get_nested_cost_items(cost_item), 1):
|
||||||
|
child_hierarchy = f"{hierarchy}.{i}"
|
||||||
IfcDataGetter.process_cost_data(file, nested_cost, cost_items_data, index, child_hierarchy)
|
IfcDataGetter.process_cost_data(file, nested_cost, cost_items_data, index, child_hierarchy)
|
||||||
child_hierarchy = (
|
|
||||||
".".join(child_hierarchy.split(".")[:-1]) + "." + str(int(child_hierarchy.split(".")[-1]) + 1)
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_cost_items_data(file: ifcopenshell.file, schedule: ifcopenshell.entity_instance) -> list[CostItem]:
|
def get_cost_items_data(file: ifcopenshell.file, schedule: ifcopenshell.entity_instance) -> list[CostItem]:
|
||||||
cost_items_data: list[cost_item] = []
|
cost_items_data: list[CostItem] = []
|
||||||
index = 0
|
index = 0
|
||||||
for cost_item in IfcDataGetter.get_root_costs(schedule):
|
for cost_item in IfcDataGetter.get_root_costs(schedule):
|
||||||
IfcDataGetter.process_cost_data(file, cost_item, cost_items_data, index)
|
IfcDataGetter.process_cost_data(file, cost_item, cost_items_data, index)
|
||||||
@@ -278,6 +279,8 @@ class Ifc5Dwriter:
|
|||||||
self.colours = self.default_colors.copy()
|
self.colours = self.default_colors.copy()
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
|
"""Fill ``sheet_data`` from ``cost_schedules``."""
|
||||||
|
self.sheet_data = {}
|
||||||
counter: Counter[str] = Counter()
|
counter: Counter[str] = Counter()
|
||||||
for cost_schedule in self.cost_schedules:
|
for cost_schedule in self.cost_schedules:
|
||||||
sheet_id = cost_schedule.id()
|
sheet_id = cost_schedule.id()
|
||||||
@@ -326,7 +329,6 @@ class Ifc5Dwriter:
|
|||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
self.cost_schedules = IfcDataGetter.get_schedules(self.file, self.cost_schedule)
|
self.cost_schedules = IfcDataGetter.get_schedules(self.file, self.cost_schedule)
|
||||||
self.sheet_data = {}
|
|
||||||
self.parse()
|
self.parse()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user