Fix fundamental bug where area and volume units were ignored on new projects.

This commit is contained in:
Dion Moult
2023-05-04 21:43:18 +10:00
parent 41e58a3d46
commit 539b3a243b
5 changed files with 73 additions and 73 deletions
+2 -1
View File
@@ -292,6 +292,7 @@ class Drawing:
def get_reference_description(cls, reference): pass
def get_reference_document(cls, reference): pass
def get_reference_location(cls, reference): pass
def get_references_with_location(cls, location): pass
def get_text_literal(cls, obj): pass
def get_unit_system(cls): pass
def import_assigned_product(cls, obj): pass
@@ -848,7 +849,7 @@ class Unit:
def enable_editing_units(cls): pass
def export_unit_attributes(cls): pass
def get_scene_unit_name(cls, unit_type): pass
def get_scene_unit_si_prefix(cls): pass
def get_scene_unit_si_prefix(cls, unit_type): pass
def import_unit_attributes(cls, unit): pass
def import_units(cls): pass
def is_scene_unit_metric(cls): pass
+6 -8
View File
@@ -18,19 +18,17 @@
def assign_scene_units(ifc, unit):
length_name = unit.get_scene_unit_name("length")
area_name = unit.get_scene_unit_name("area")
volume_name = unit.get_scene_unit_name("volume")
if unit.is_scene_unit_metric():
prefix = unit.get_scene_unit_si_prefix()
prefix = unit.get_scene_unit_si_prefix("LENGTHUNIT")
lengthunit = ifc.run("unit.add_si_unit", unit_type="LENGTHUNIT", prefix=prefix)
prefix = unit.get_scene_unit_si_prefix("AREAUNIT")
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)
else:
lengthunit = ifc.run("unit.add_conversion_based_unit", name=length_name)
areaunit = ifc.run("unit.add_conversion_based_unit", name=area_name)
volumeunit = ifc.run("unit.add_conversion_based_unit", name=volume_name)
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"))
planeangleunit = ifc.run("unit.add_conversion_based_unit", name="degree")
+27 -29
View File
@@ -51,37 +51,35 @@ class Unit(blenderbim.core.tool.Unit):
@classmethod
def get_scene_unit_name(cls, unit_type):
props = bpy.context.scene.unit_settings
is_metric = props.system == "METRIC" or props.system == "NONE"
if is_metric:
name = "METRE"
elif props.length_unit == "MILES":
name = "mile"
elif props.length_unit == "FEET" or props.length_unit == "ADAPTIVE":
name = "foot"
elif props.length_unit == "INCHES":
name = "inch"
elif props.length_unit == "THOU":
name = "thou"
if unit_type == "length":
return name
elif unit_type == "area":
if is_metric:
return f"SQUARE_{name}"
return f"square {name}"
elif unit_type == "volume":
if is_metric:
return f"CUBIC_{name}"
return f"cubic {name}"
if unit_type == "LENGTHUNIT":
props = bpy.context.scene.unit_settings
if props.length_unit == "MILES":
return "mile"
elif props.length_unit == "FEET" or props.length_unit == "ADAPTIVE":
return "foot"
elif props.length_unit == "INCHES":
return "inch"
elif props.length_unit == "THOU":
return "thou"
return "foot"
elif unit_type == "AREAUNIT":
return bpy.context.scene.BIMProperties.area_unit
elif unit_type == "VOLUMEUNIT":
return bpy.context.scene.BIMProperties.volume_unit
@classmethod
def get_scene_unit_si_prefix(cls):
props = bpy.context.scene.unit_settings
if props.length_unit == "ADAPTIVE" or props.length_unit == "METERS":
return
return props.length_unit.replace("METERS", "")
def get_scene_unit_si_prefix(cls, unit_type):
if unit_type == "LENGTHUNIT":
props = bpy.context.scene.unit_settings
if props.length_unit == "ADAPTIVE" or props.length_unit == "METERS":
return
return props.length_unit.replace("METERS", "")
elif unit_type == "AREAUNIT":
unit = bpy.context.scene.BIMProperties.area_unit
elif unit_type == "VOLUMEUNIT":
unit = bpy.context.scene.BIMProperties.volume_unit
if "/" in unit:
return unit.split("/")[0]
@classmethod
def import_unit_attributes(cls, unit):
+6 -7
View File
@@ -23,16 +23,15 @@ from test.core.bootstrap import ifc, unit
class TestAssignSceneUnits:
def test_creating_and_assigning_metric_units(self, ifc, unit):
unit.is_scene_unit_metric().should_be_called().will_return(True)
unit.get_scene_unit_name("length").should_be_called().will_return("name")
unit.get_scene_unit_si_prefix().should_be_called().will_return("prefix")
unit.get_scene_unit_si_prefix("LENGTHUNIT").should_be_called().will_return("prefix")
unit.get_scene_unit_si_prefix("AREAUNIT").should_be_called().will_return("prefix")
unit.get_scene_unit_si_prefix("VOLUMEUNIT").should_be_called().will_return("prefix")
ifc.run(
"unit.add_si_unit", unit_type="LENGTHUNIT", prefix="prefix"
).should_be_called().will_return("lengthunit")
unit.get_scene_unit_name("area").should_be_called().will_return("name")
ifc.run("unit.add_si_unit", unit_type="AREAUNIT", prefix="prefix").should_be_called().will_return("areaunit")
unit.get_scene_unit_name("volume").should_be_called().will_return("name")
ifc.run(
"unit.add_si_unit", unit_type="VOLUMEUNIT", prefix="prefix"
).should_be_called().will_return("volumeunit")
@@ -44,13 +43,13 @@ class TestAssignSceneUnits:
def test_creating_and_assigning_imperial_units(self, ifc, unit):
unit.is_scene_unit_metric().should_be_called().will_return(False)
unit.get_scene_unit_name("length").should_be_called().will_return("lengthname")
unit.get_scene_unit_name("LENGTHUNIT").should_be_called().will_return("lengthname")
ifc.run("unit.add_conversion_based_unit", name="lengthname").should_be_called().will_return("lengthunit")
unit.get_scene_unit_name("area").should_be_called().will_return("areaname")
unit.get_scene_unit_name("AREAUNIT").should_be_called().will_return("areaname")
ifc.run("unit.add_conversion_based_unit", name="areaname").should_be_called().will_return("areaunit")
unit.get_scene_unit_name("volume").should_be_called().will_return("volumename")
unit.get_scene_unit_name("VOLUMEUNIT").should_be_called().will_return("volumename")
ifc.run("unit.add_conversion_based_unit", name="volumename").should_be_called().will_return("volumeunit")
ifc.run("unit.add_conversion_based_unit", name="degree").should_be_called().will_return("planeangleunit")
+32 -28
View File
@@ -97,55 +97,59 @@ class TestExportUnitAttributes(NewFile):
class TestGetSceneUnitName(NewFile):
def test_getting_a_metric_name(self):
bpy.context.scene.unit_settings.system = "METRIC"
assert subject.get_scene_unit_name("length") == "METRE"
assert subject.get_scene_unit_name("area") == "SQUARE_METRE"
assert subject.get_scene_unit_name("volume") == "CUBIC_METRE"
def test_getting_an_imperial_name(self):
bpy.context.scene.unit_settings.system = "IMPERIAL"
bpy.context.scene.unit_settings.length_unit = "MILES"
assert subject.get_scene_unit_name("length") == "mile"
assert subject.get_scene_unit_name("area") == "square mile"
assert subject.get_scene_unit_name("volume") == "cubic mile"
bpy.context.scene.BIMProperties.area_unit = "square foot"
bpy.context.scene.BIMProperties.volume_unit = "cubic inch"
assert subject.get_scene_unit_name("LENGTHUNIT") == "mile"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "FEET"
assert subject.get_scene_unit_name("length") == "foot"
assert subject.get_scene_unit_name("area") == "square foot"
assert subject.get_scene_unit_name("volume") == "cubic foot"
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "INCHES"
assert subject.get_scene_unit_name("length") == "inch"
assert subject.get_scene_unit_name("area") == "square inch"
assert subject.get_scene_unit_name("volume") == "cubic inch"
assert subject.get_scene_unit_name("LENGTHUNIT") == "inch"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "THOU"
assert subject.get_scene_unit_name("length") == "thou"
assert subject.get_scene_unit_name("area") == "square thou"
assert subject.get_scene_unit_name("volume") == "cubic thou"
assert subject.get_scene_unit_name("LENGTHUNIT") == "thou"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
bpy.context.scene.unit_settings.length_unit = "ADAPTIVE"
assert subject.get_scene_unit_name("length") == "foot"
assert subject.get_scene_unit_name("area") == "square foot"
assert subject.get_scene_unit_name("volume") == "cubic foot"
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
assert subject.get_scene_unit_name("AREAUNIT") == "square foot"
assert subject.get_scene_unit_name("VOLUMEUNIT") == "cubic inch"
def test_getting_a_name_with_no_unit_system(self):
bpy.context.scene.unit_settings.system = "NONE"
assert subject.get_scene_unit_name("length") == "METRE"
assert subject.get_scene_unit_name("LENGTHUNIT") == "foot"
class TestGetSceneUnitSIPrefix:
def test_run(self):
bpy.context.scene.unit_settings.system = "METRIC"
bpy.context.scene.unit_settings.length_unit = "METERS"
assert subject.get_scene_unit_si_prefix() is None
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") is None
bpy.context.scene.unit_settings.length_unit = "MICROMETERS"
assert subject.get_scene_unit_si_prefix() == "MICRO"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "MICRO"
bpy.context.scene.unit_settings.length_unit = "MILLIMETERS"
assert subject.get_scene_unit_si_prefix() == "MILLI"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "MILLI"
bpy.context.scene.unit_settings.length_unit = "CENTIMETERS"
assert subject.get_scene_unit_si_prefix() == "CENTI"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "CENTI"
bpy.context.scene.unit_settings.length_unit = "KILOMETERS"
assert subject.get_scene_unit_si_prefix() == "KILO"
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") == "KILO"
bpy.context.scene.unit_settings.length_unit = "ADAPTIVE"
assert subject.get_scene_unit_si_prefix() is None
assert subject.get_scene_unit_si_prefix("LENGTHUNIT") is None
bpy.context.scene.BIMProperties.area_unit = "SQUARE_METRE"
assert subject.get_scene_unit_si_prefix("AREAUNIT") is None
bpy.context.scene.BIMProperties.area_unit = "MILLI/SQUARE_METRE"
assert subject.get_scene_unit_si_prefix("AREAUNIT") == "MILLI"
bpy.context.scene.BIMProperties.volume_unit = "CUBIC_METRE"
assert subject.get_scene_unit_si_prefix("VOLUMEUNIT") is None
bpy.context.scene.BIMProperties.volume_unit = "MILLI/CUBIC_METRE"
assert subject.get_scene_unit_si_prefix("VOLUMEUNIT") == "MILLI"
class TestImportUnitAttributes(NewFile):