Fix deep purge of unit when converting units and fix bug where unit was removed if map unit was the same as the project unit

This commit is contained in:
Dion Moult
2024-07-12 22:48:23 +10:00
parent c79e490d6d
commit 04365053a8
2 changed files with 21 additions and 2 deletions
@@ -132,6 +132,24 @@ class TestConvertFileLengthUnits(test.bootstrap.IFC4):
assert output.by_type("IfcMapConversion")[0].Scale == 1
assert subject.get_full_unit_name(output.by_type("IfcProjectedCRS")[0].MapUnit) == "METRE"
def test_preserving_enh_if_there_is_a_map_unit_which_is_also_the_project_default(self):
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
meter = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT")
ifcopenshell.api.context.add_context(self.file, "Model")
ifcopenshell.api.georeference.add_georeferencing(self.file)
ifcopenshell.api.georeference.edit_georeferencing(
self.file, projected_crs={"MapUnit": meter}, coordinate_operation={"Eastings": 10, "Scale": 1}
)
ifcopenshell.api.unit.assign_unit(self.file, units=[meter])
output = subject.convert_file_length_units(self.file, target_units="MILLIMETER")
assert subject.get_full_unit_name(subject.get_project_unit(output, "LENGTHUNIT")) == "MILLIMETRE"
assert output.by_type("IfcMapConversion")[0].Eastings == 10
assert output.by_type("IfcMapConversion")[0].Northings == 0
assert output.by_type("IfcMapConversion")[0].Scale == 0.001
assert subject.get_full_unit_name(output.by_type("IfcProjectedCRS")[0].MapUnit) == "METRE"
unit_assignment = subject.get_unit_assignment(output)
assert len(unit_assignment.Units) == 1
class TestConvertFileLengthUnitsIFC2X3(test.bootstrap.IFC2X3):
def test_converting_map_conversion_if_there_is_no_map_unit(self):