mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 21:53:40 +00:00
proposal to add massunit and timeunit in project creation wizard
This commit is contained in:
@@ -98,6 +98,8 @@ class NewProject(bpy.types.Operator):
|
||||
bpy.context.scene.unit_settings.length_unit = "METERS"
|
||||
bim_props.area_unit = "SQUARE_METRE"
|
||||
bim_props.volume_unit = "CUBIC_METRE"
|
||||
bim_props.mass_unit = "KILOGRAM"
|
||||
bim_props.time_unit = "SECOND"
|
||||
pprops.template_file = "0"
|
||||
elif self.preset == "metric_mm":
|
||||
pprops.export_schema = "IFC4"
|
||||
@@ -105,6 +107,8 @@ class NewProject(bpy.types.Operator):
|
||||
bpy.context.scene.unit_settings.length_unit = "MILLIMETERS"
|
||||
bim_props.area_unit = "SQUARE_METRE"
|
||||
bim_props.volume_unit = "CUBIC_METRE"
|
||||
bim_props.mass_unit = "KILOGRAM"
|
||||
bim_props.time_unit = "SECOND"
|
||||
pprops.template_file = "0"
|
||||
elif self.preset == "imperial_ft":
|
||||
pprops.export_schema = "IFC4"
|
||||
@@ -112,6 +116,8 @@ class NewProject(bpy.types.Operator):
|
||||
bpy.context.scene.unit_settings.length_unit = "FEET"
|
||||
bim_props.area_unit = "square foot"
|
||||
bim_props.volume_unit = "cubic foot"
|
||||
bim_props.mass_unit = "POUND"
|
||||
bim_props.time_unit = "SECOND"
|
||||
pprops.template_file = "0"
|
||||
elif self.preset == "demo":
|
||||
pprops.export_schema = "IFC4"
|
||||
@@ -119,6 +125,8 @@ class NewProject(bpy.types.Operator):
|
||||
bpy.context.scene.unit_settings.length_unit = "MILLIMETERS"
|
||||
bim_props.area_unit = "SQUARE_METRE"
|
||||
bim_props.volume_unit = "CUBIC_METRE"
|
||||
bim_props.mass_unit = "KILOGRAM"
|
||||
bim_props.time_unit = "SECOND"
|
||||
pprops.template_file = "IFC4 Demo Template.ifc"
|
||||
|
||||
if self.preset != "wizard":
|
||||
|
||||
@@ -356,6 +356,10 @@ class BIM_PT_new_project_wizard(Panel):
|
||||
row.prop(props, "area_unit", text="Area Unit")
|
||||
row = self.layout.row()
|
||||
row.prop(props, "volume_unit", text="Volume Unit")
|
||||
row = self.layout.row()
|
||||
row.prop(props, "mass_unit", text="Mass Unit")
|
||||
row = self.layout.row()
|
||||
row.prop(props, "time_unit", text="Time Unit")
|
||||
prop_with_search(self.layout, pprops, "template_file", text="Template")
|
||||
|
||||
row = self.layout.row()
|
||||
|
||||
@@ -586,7 +586,28 @@ class BIMProperties(PropertyGroup):
|
||||
],
|
||||
name="IFC Volume Unit",
|
||||
)
|
||||
mass_unit: EnumProperty(
|
||||
items=[
|
||||
("KILOGRAM", "Kilogram", "Kilograms"),
|
||||
("GRAM", "Gram", "Grams"),
|
||||
("POUND", "Pound (Mass)", "Pounds"),
|
||||
("OUNCE", "Ounce", "Ounces"),
|
||||
("TON", "Ton", "Metric Tons"),
|
||||
],
|
||||
name="Mass Unit",
|
||||
default="KILOGRAM",
|
||||
)
|
||||
|
||||
time_unit: EnumProperty(
|
||||
items=[
|
||||
("SECOND", "Second", "Seconds"),
|
||||
("MINUTE", "Minutes", "Minutes"),
|
||||
("HOUR", "Hour", "Hours"),
|
||||
("DAY", "Day", "Days"),
|
||||
],
|
||||
name="Time Unit",
|
||||
default="HOUR",
|
||||
)
|
||||
if TYPE_CHECKING:
|
||||
is_dirty: bool
|
||||
schema_dir: str
|
||||
@@ -599,6 +620,8 @@ class BIMProperties(PropertyGroup):
|
||||
section_line_decorator_width: float
|
||||
area_unit: str
|
||||
volume_unit: str
|
||||
mass_unit: str
|
||||
time_unit: str
|
||||
|
||||
|
||||
class IfcParameter(PropertyGroup):
|
||||
|
||||
@@ -34,14 +34,29 @@ def assign_scene_units(ifc: type[tool.Ifc], unit: type[tool.Unit]) -> None:
|
||||
areaunit = ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix=prefix)
|
||||
prefix = unit.get_scene_unit_si_prefix("VOLUMEUNIT")
|
||||
volumeunit = ifc.run("unit.add_si_unit", unit_type="VOLUMEUNIT", prefix=prefix)
|
||||
|
||||
prefix = unit.get_scene_unit_si_prefix("MASSUNIT")
|
||||
if prefix == "CONVERSION":
|
||||
mass_unit_name = unit.get_scene_unit_name("MASSUNIT")
|
||||
massunit = ifc.run("unit.add_conversion_based_unit", name=mass_unit_name.lower())
|
||||
else:
|
||||
massunit = ifc.run("unit.add_si_unit", unit_type="MASSUNIT", prefix=prefix)
|
||||
|
||||
prefix = unit.get_scene_unit_si_prefix("TIMEUNIT")
|
||||
if prefix == "CONVERSION":
|
||||
time_unit_name = unit.get_scene_unit_name("TIMEUNIT")
|
||||
timeunit = ifc.run("unit.add_conversion_based_unit", name=time_unit_name.lower())
|
||||
else:
|
||||
timeunit = ifc.run("unit.add_si_unit", unit_type="TIMEUNIT", prefix=prefix)
|
||||
else:
|
||||
lengthunit = ifc.run("unit.add_conversion_based_unit", name=unit.get_scene_unit_name("LENGTHUNIT"))
|
||||
areaunit = ifc.run("unit.add_conversion_based_unit", name=unit.get_scene_unit_name("AREAUNIT"))
|
||||
volumeunit = ifc.run("unit.add_conversion_based_unit", name=unit.get_scene_unit_name("VOLUMEUNIT"))
|
||||
massunit = ifc.run("unit.add_conversion_based_unit", name=unit.get_scene_unit_name("MASSUNIT"))
|
||||
timeunit = ifc.run("unit.add_conversion_based_unit", name=unit.get_scene_unit_name("TIMEUNIT"))
|
||||
|
||||
planeangleunit = ifc.run("unit.add_conversion_based_unit", name="degree")
|
||||
|
||||
ifc.run("unit.assign_unit", units=[lengthunit, areaunit, volumeunit, planeangleunit])
|
||||
ifc.run("unit.assign_unit", units=[lengthunit, areaunit, volumeunit, planeangleunit, massunit, timeunit])
|
||||
|
||||
|
||||
def assign_unit(ifc: type[tool.Ifc], unit_tool: type[tool.Unit], unit: ifcopenshell.entity_instance) -> None:
|
||||
|
||||
@@ -266,7 +266,7 @@ def parse_distance_string(input_string: str, use_project_unit: bool = True) -> t
|
||||
|
||||
|
||||
class Unit(bonsai.core.tool.Unit):
|
||||
UNIT_TYPE = Literal["LENGTHUNIT", "AREAUNIT", "VOLUMEUNIT"]
|
||||
UNIT_TYPE = Literal["LENGTHUNIT", "AREAUNIT", "VOLUMEUNIT", "MASSUNIT", "TIMEUNIT"]
|
||||
|
||||
@staticmethod
|
||||
def format_distance(meters: float, use_imperial: bool = None, **kwargs) -> str:
|
||||
@@ -343,6 +343,10 @@ class Unit(bonsai.core.tool.Unit):
|
||||
return bim_props.area_unit
|
||||
elif unit_type == "VOLUMEUNIT":
|
||||
return bim_props.volume_unit
|
||||
elif unit_type == "MASSUNIT":
|
||||
return bim_props.mass_unit
|
||||
elif unit_type == "TIMEUNIT":
|
||||
return bim_props.time_unit
|
||||
else:
|
||||
assert_never(unit_type)
|
||||
|
||||
@@ -359,6 +363,26 @@ class Unit(bonsai.core.tool.Unit):
|
||||
unit = bim_props.area_unit
|
||||
elif unit_type == "VOLUMEUNIT":
|
||||
unit = bim_props.volume_unit
|
||||
elif unit_type == "MASSUNIT":
|
||||
unit = bim_props.mass_unit
|
||||
if unit == "KILOGRAM":
|
||||
return "KILO"
|
||||
elif unit == "GRAM":
|
||||
return None
|
||||
elif unit == "TON":
|
||||
return "MEGA"
|
||||
elif unit in ["POUND", "OUNCE"]:
|
||||
return "CONVERSION"
|
||||
else:
|
||||
return None
|
||||
|
||||
elif unit_type == "TIMEUNIT":
|
||||
unit = bim_props.time_unit
|
||||
if unit == "SECOND":
|
||||
return None
|
||||
else:
|
||||
return "CONVERSION"
|
||||
|
||||
else:
|
||||
assert_never(unit_type)
|
||||
if "/" in unit:
|
||||
|
||||
Reference in New Issue
Block a user