mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-15 18:14:08 +00:00
convert_file_length_units - fix issue converting to imperial units
ifcpatch ConvertLengthUnit - change used units from plural to singular names, to make it consistent across the api more test coverage - test converting to more units and back from them
This commit is contained in:
@@ -31,14 +31,14 @@ class Patcher:
|
||||
src: str,
|
||||
file: ifcopenshell.file,
|
||||
logger: Logger,
|
||||
unit: str = "METERS",
|
||||
unit: str = "METER",
|
||||
):
|
||||
"""Converts the length unit of a model to the specified unit
|
||||
|
||||
Allowed metric units include METERS, MILLIMETERS, CENTIMETERS, etc.
|
||||
Allowed imperial units include INCHES, FEET, MILES.
|
||||
Allowed metric units include METER, MILLIMETER, CENTIMETER, etc.
|
||||
Allowed imperial units include INCH, FOOT, MILE.
|
||||
|
||||
:param unit: The name of the desired unit, defaults to "METERS"
|
||||
:param unit: The name of the desired unit, defaults to "METER"
|
||||
:type unit: str
|
||||
|
||||
Example:
|
||||
@@ -46,10 +46,10 @@ class Patcher:
|
||||
.. code:: python
|
||||
|
||||
# Convert to millimeters
|
||||
ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "ConvertLengthUnit", "arguments": ["MILLIMETERS"]})
|
||||
ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "ConvertLengthUnit", "arguments": ["MILLIMETER"]})
|
||||
|
||||
# Convert to feet
|
||||
ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "ConvertLengthUnit", "arguments": ["FEET"]})
|
||||
ifcpatch.execute({"input": "input.ifc", "file": model, "recipe": "ConvertLengthUnit", "arguments": ["FOOT"]})
|
||||
"""
|
||||
self.src = src
|
||||
self.file = file
|
||||
|
||||
@@ -79,14 +79,7 @@ class Patcher:
|
||||
|
||||
def get_unit_name(self, ifc_file: ifcopenshell.file) -> str:
|
||||
length_unit = ifcopenshell.util.unit.get_project_unit(ifc_file, "LENGTHUNIT")
|
||||
names = {
|
||||
"METRE": "METERS",
|
||||
"FOOT": "FEET",
|
||||
"INCH": "INCHES",
|
||||
"MILE": "MILES",
|
||||
}
|
||||
prefix = getattr(length_unit, "Prefix", None) or ""
|
||||
return prefix + names[length_unit.Name.upper()]
|
||||
return ifcopenshell.util.unit.get_full_unit_name(length_unit)
|
||||
|
||||
def reuse_existing_contexts(self):
|
||||
to_delete = set()
|
||||
|
||||
@@ -29,10 +29,10 @@ class TestConvertLengthUnit(test.bootstrap.IFC4):
|
||||
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
|
||||
output = ifcpatch.execute(
|
||||
{"input": "input.ifc", "file": self.file, "recipe": "ConvertLengthUnit", "arguments": ["METERS"]}
|
||||
{"input": "input.ifc", "file": self.file, "recipe": "ConvertLengthUnit", "arguments": ["METER"]}
|
||||
)
|
||||
unit = ifcopenshell.util.unit.get_project_unit(output, "LENGTHUNIT")
|
||||
assert unit.Prefix == None
|
||||
assert ifcopenshell.util.unit.get_full_unit_name(unit) == "METRE"
|
||||
|
||||
|
||||
class TestConvertLengthUnitIFC2X3(test.bootstrap.IFC2X3, TestConvertLengthUnit):
|
||||
|
||||
Reference in New Issue
Block a user