mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Import of CSV-based schedule of rates is now possible
This commit is contained in:
@@ -16,18 +16,13 @@ class Usecase:
|
||||
# TODO: support all applied value select types
|
||||
value = self.file.createIfcMonetaryMeasure(value)
|
||||
elif name == "UnitBasis":
|
||||
self.remove_existing_unit_basis()
|
||||
old_unit_basis = self.settings["cost_value"].UnitBasis
|
||||
if value:
|
||||
value_component = self.file.create_entity(
|
||||
ifcopenshell.util.unit.get_unit_measure_type(value["UnitComponent"].UnitType),
|
||||
ifcopenshell.util.unit.get_unit_measure_class(value["UnitComponent"].UnitType),
|
||||
value["ValueComponent"],
|
||||
)
|
||||
value = self.file.create_entity("IfcMeasureWithUnit", value_component, value["UnitComponent"])
|
||||
if old_unit_basis and len(self.file.get_inverse(old_unit_basis)) == 0:
|
||||
ifcopenshell.util.element.remove_deep(self.file, old_unit_basis)
|
||||
setattr(self.settings["cost_value"], name, value)
|
||||
|
||||
def remove_existing_unit_basis(self):
|
||||
if (
|
||||
self.settings["cost_value"].UnitBasis
|
||||
and len(self.file.get_inverse(self.settings["cost_value"].UnitBasis)) == 1
|
||||
):
|
||||
ifcopenshell.util.element.remove_deep(self.file, self.settings["cost_value"].UnitBasis)
|
||||
|
||||
@@ -246,45 +246,79 @@ def get_named_dimensions(name):
|
||||
return named_dimensions.get(name, (0, 0, 0, 0, 0, 0, 0))
|
||||
|
||||
|
||||
def get_unit_assignment(ifc_file):
|
||||
unit_assignments = ifc_file.by_type("IfcUnitAssignment")
|
||||
if unit_assignments:
|
||||
return unit_assignments[0]
|
||||
|
||||
|
||||
def get_property_unit(prop, ifc_file):
|
||||
unit = getattr(prop, "Unit", None)
|
||||
if unit:
|
||||
return unit
|
||||
unit_assignment = ifc_file.by_type("IfcUnitAssignment")
|
||||
unit_assignment = get_unit_assignment(ifc_file)
|
||||
if not unit_assignment:
|
||||
return
|
||||
entity = prop.wrapped_data.declaration().as_entity()
|
||||
if prop.is_a("IfcPhysicalSimpleQuantity"):
|
||||
measure_type = entity.attribute_by_index(3).type_of_attribute().declared_type().name()
|
||||
measure_class = entity.attribute_by_index(3).type_of_attribute().declared_type().name()
|
||||
elif prop.is_a("IfcPropertySingleValue") and prop.NominalValue:
|
||||
measure_type = prop.NominalValue.is_a()
|
||||
for text in ("Ifc", "Measure", "Non", "Positive", "Negative"):
|
||||
measure_type = measure_type.replace(text, "")
|
||||
measure_type = measure_type.upper() + "UNIT"
|
||||
units = [u for u in unit_assignment[0].Units if getattr(u, "UnitType", None) == measure_type]
|
||||
measure_class = prop.NominalValue.is_a()
|
||||
unit_type = get_measure_unit_type(measure_class)
|
||||
units = [u for u in unit_assignment.Units if getattr(u, "UnitType", None) == unit_type]
|
||||
if units:
|
||||
return units[0]
|
||||
|
||||
|
||||
def get_unit_measure_type(unit_type):
|
||||
def get_unit_measure_class(unit_type):
|
||||
if unit_type == "USERDEFINED":
|
||||
# See https://github.com/buildingSMART/IFC4.3.x-development/issues/71
|
||||
return "IfcNumericMeasure"
|
||||
return "Ifc" + unit_type[0:-4].lower().capitalize() + "Measure"
|
||||
|
||||
|
||||
def get_measure_unit_type(measure_class):
|
||||
if measure_class == "IfcNumericMeasure":
|
||||
# See https://github.com/buildingSMART/IFC4.3.x-development/issues/71
|
||||
return "USERDEFINED"
|
||||
for text in ("Ifc", "Measure", "Non", "Positive", "Negative"):
|
||||
measure_class = measure_class.replace(text, "")
|
||||
return measure_class.upper() + "UNIT"
|
||||
|
||||
|
||||
def get_symbol_measure_class(symbol):
|
||||
# Dumb, but everybody gets it, unlike regex golf
|
||||
if not symbol:
|
||||
return "IfcNumericMeasure"
|
||||
symbol = symbol.lower()
|
||||
if symbol in ["km", "m", "cm", "mm", "ly", "lf", "lin", "yd", "ft", "in"]:
|
||||
return "IfcLengthMeasure"
|
||||
elif symbol in ["km2", "m2", "cm2", "mm2", "sqy", "sqft", "sqin"]:
|
||||
return "IfcAreaMeasure"
|
||||
elif symbol in ["km3", "m3", "cm3", "mm3", "cy", "cft", "cin"]:
|
||||
return "IfcVolumeMeasure"
|
||||
elif symbol in ["kg", "g", "mt", "kt", "t"]:
|
||||
return "IfcMassMeasure"
|
||||
elif symbol in ["day", "d", "hour", "hr", "h", "minute", "min", "m", "second", "sec", "s"]:
|
||||
return "IfcTimeMeasure"
|
||||
return "IfcNumericMeasure"
|
||||
|
||||
|
||||
def get_symbol_quantity_class(symbol):
|
||||
# Dumb, but everybody gets it, unlike regex golf
|
||||
if not symbol:
|
||||
return "IfcQuantityCount"
|
||||
symbol = symbol.lower()
|
||||
if symbol in ["kg", "g", "mt", "kt", "t"]:
|
||||
if symbol in ["km", "m", "cm", "mm", "ly", "lf", "lin", "yd", "ft", "in"]:
|
||||
return "IfcQuantityLength"
|
||||
elif symbol in ["km2", "m2", "cm2", "mm2", "sqy", "sqft", "sqin"]:
|
||||
return "IfcQuantityArea"
|
||||
elif symbol in ["km3", "m3", "cm3", "mm3", "cy", "cft", "cin"]:
|
||||
return "IfcQuantityVolume"
|
||||
elif symbol in ["kg", "g", "mt", "kt", "t"]:
|
||||
return "IfcQuantityWeight"
|
||||
elif symbol in ["day", "d", "hour", "hr", "h", "minute", "min", "m", "second", "sec", "s"]:
|
||||
return "IfcQuantityTime"
|
||||
elif symbol in ["km3", "m3", "cm3", "mm3", "cy", "cft", "cin"]:
|
||||
return "IfcQuantityVolume"
|
||||
elif symbol in ["km2", "m2", "cm2", "mm2", "sqy", "sqft", "sqin"]:
|
||||
return "IfcQuantityArea"
|
||||
elif symbol in ["km", "m", "cm", "mm", "ly", "lf", "lin", "yd", "ft", "in"]:
|
||||
return "IfcQuantityLength"
|
||||
return "IfcQuantityCount"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user