Skip to content

Commit a3844fe

Browse files
committed
More tests and fixes for linking in models with different project norths
1 parent d00e603 commit a3844fe

4 files changed

Lines changed: 83 additions & 12 deletions

File tree

src/blenderbim/blenderbim/bim/module/project/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ def set_model_origin_from_link(self):
11121112
data = json.load(f)
11131113

11141114
gprops = bpy.context.scene.BIMGeoreferenceProperties
1115-
for prop in ("model_origin", "blender_x_axis_abscissa", "blender_x_axis_ordinate"):
1115+
for prop in ("model_origin", "model_project_north"):
11161116
if (value := data.get(prop, None)) is not None:
11171117
setattr(gprops, prop, value)
11181118

src/blenderbim/blenderbim/tool/loader.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,12 @@ def create_settings(cls, is_gross=False):
564564

565565
@classmethod
566566
def set_manual_blender_offset(cls, ifc_file: ifcopenshell.file) -> None:
567-
model_origin = np.array(ifcopenshell.util.geolocation.auto_xyz2enh(ifc_file, 0, 0, 0))
568567
false_origin = np.array(cls.settings.false_origin)
569-
model_offset = false_origin - model_origin
568+
model_offset = np.array(
569+
ifcopenshell.util.geolocation.auto_enh2xyz(
570+
ifc_file, *cls.settings.false_origin, is_specified_in_map_units=False
571+
)
572+
)
570573
zero_origin = np.array((0, 0, 0))
571574
has_offset = not np.allclose(model_offset, zero_origin)
572575

@@ -582,7 +585,7 @@ def set_manual_blender_offset(cls, ifc_file: ifcopenshell.file) -> None:
582585
if not has_offset:
583586
model_offset = false_origin = (0, 0, 0)
584587

585-
if not has_rotation:
588+
if np.isclose(project_north, 0):
586589
project_north = 0
587590

588591
if has_offset or has_rotation:
@@ -676,6 +679,8 @@ def guess_false_origin_from_elements(cls, ifc_file: ifcopenshell.file) -> None:
676679
if offset_point is None:
677680
return
678681
cls.settings.false_origin = ifcopenshell.util.geolocation.auto_xyz2enh(ifc_file, *offset_point)
682+
if angle := ifcopenshell.util.geolocation.get_grid_north(ifc_file):
683+
cls.settings.project_north = angle
679684
cls.set_manual_blender_offset(ifc_file)
680685

681686
@classmethod
@@ -742,7 +747,5 @@ def calculate_model_origin(cls, ifc_file: ifcopenshell.file | None) -> None:
742747
)
743748
gprops.model_project_north = gprops.blender_project_north
744749
else:
745-
gprops.model_origin = ",".join(
746-
map(str, ifcopenshell.util.geolocation.auto_xyz2enh(ifc_file, 0, 0, 0))
747-
)
750+
gprops.model_origin = ",".join(map(str, ifcopenshell.util.geolocation.auto_xyz2enh(ifc_file, 0, 0, 0)))
748751
gprops.model_project_north = str(ifcopenshell.util.geolocation.get_grid_north(ifc_file))

src/blenderbim/test/bim/feature/project.feature

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ Scenario: Load project elements - all georeferencing coordinate situations with
454454
Scenario: Load project elements - all georeferencing coordinate situations with an offset site - manual false origin mode
455455
Given an empty Blender session
456456
And I press "bim.load_project(filepath='{cwd}/test/files/geolocation-offsetsite.ifc', is_advanced=True)"
457-
When I set "scene.BIMProjectProperties.false_origin_mode" to "MANUAL"
458-
When I set "scene.BIMProjectProperties.false_origin" to "0,10000,0"
459-
When I set "scene.BIMProjectProperties.distance_limit" to "5"
460-
And I press "bim.load_project_elements"
457+
And I set "scene.BIMProjectProperties.false_origin_mode" to "MANUAL"
458+
And I set "scene.BIMProjectProperties.false_origin" to "0,10000,0"
459+
And I set "scene.BIMProjectProperties.distance_limit" to "5"
460+
When I press "bim.load_project_elements"
461461
Then "scene.BIMGeoreferenceProperties.has_blender_offset" is "True"
462462
And "scene.BIMGeoreferenceProperties.blender_eastings" is "0.0"
463463
And "scene.BIMGeoreferenceProperties.blender_northings" is "10000.0"
@@ -489,6 +489,36 @@ Scenario: Load project elements - all georeferencing coordinate situations with
489489
And the object "IfcActuator/J" has a vertex at "10.366,3.813,-1"
490490
And the object "IfcActuator/J" has a vertex at "12.298,4.331,-1"
491491

492+
Scenario: Load project elements - all georeferencing coordinate situations with an offset site - manual false origin mode - with custom project north
493+
Given an empty Blender session
494+
And I press "bim.load_project(filepath='{cwd}/test/files/geolocation-offsetsite.ifc', is_advanced=True)"
495+
And I set "scene.BIMProjectProperties.false_origin_mode" to "MANUAL"
496+
And I set "scene.BIMProjectProperties.false_origin" to "0,10000,0"
497+
And I set "scene.BIMProjectProperties.project_north" to "-15"
498+
And I set "scene.BIMProjectProperties.distance_limit" to "5"
499+
When I press "bim.load_project_elements"
500+
Then "scene.BIMGeoreferenceProperties.has_blender_offset" is "True"
501+
And "scene.BIMGeoreferenceProperties.blender_eastings" is "0.0"
502+
And "scene.BIMGeoreferenceProperties.blender_northings" is "10000.0"
503+
And "scene.BIMGeoreferenceProperties.blender_orthogonal_height" is "0.0"
504+
And "scene.BIMGeoreferenceProperties.blender_offset_x" is "0.0"
505+
And "scene.BIMGeoreferenceProperties.blender_offset_y" is "10000.0"
506+
And "scene.BIMGeoreferenceProperties.blender_offset_z" is "0.0"
507+
And the object "IfcSite/My Site" is at "0,0,0"
508+
And the object "IfcBuilding/My Building" is at "0,0,0"
509+
And the object "IfcBuildingStorey/My Storey" is at "0,0,0"
510+
And the object "IfcActuator/A" is at "7,3,0"
511+
And the object "IfcActuator/B" is at "6,1,0"
512+
And the object "IfcActuator/C" is at "0,0,0"
513+
And the object "IfcActuator/D" is at "13,4,-1"
514+
And the object "IfcActuator/E" is at "6,3,0"
515+
And the object "IfcActuator/F" is at "3,3,0"
516+
And the object "IfcActuator/G" is at "15,6,-1"
517+
And the object "IfcActuator/H" is at "9,2,0"
518+
And the object "IfcActuator/I" is at "3,3,0"
519+
And the object "IfcActuator/J" is at "11,3,-1"
520+
And the object "IfcActuator/K" is at "10,0,0"
521+
492522
Scenario: Load project elements - all georeferencing coordinate situations with a map conversion - disabled false origin mode (this should be identical to the situation with no map conversion)
493523
Given an empty Blender session
494524
And I press "bim.load_project(filepath='{cwd}/test/files/geolocation-mapconversion.ifc', is_advanced=True)"
@@ -718,6 +748,39 @@ Scenario: Link IFC - manual false origin mode
718748
And the object "Chunk" has a vertex at "-1,-1,-1"
719749
And the object "Chunk" has a vertex at "7,4,-1"
720750

751+
Scenario: Link IFC - automatic false origin mode - two different false origins and project norths - grid north is up because we start with geolocation.ifc
752+
Given an empty Blender session
753+
# Not currently possible via UI
754+
And I set "scene.BIMProjectProperties.distance_limit" to "5"
755+
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
756+
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
757+
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-mapconversion-angle.ifc', use_cache=False)"
758+
Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists
759+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists
760+
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-11,-2,0"
761+
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-4,-5,0"
762+
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "4,0,0"
763+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "4.732,-3.268,0"
764+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "9.294,-9.366,0"
765+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "18.722,-9.036,0"
766+
767+
Scenario: Link IFC - automatic false origin mode - two different false origins and project norths - project north is up because we start with geolocation-mapconversion-angle.ifc
768+
Given an empty Blender session
769+
# Not currently possible via UI
770+
And I set "scene.BIMProjectProperties.distance_limit" to "5"
771+
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
772+
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-mapconversion-angle.ifc', use_cache=False)"
773+
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
774+
Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists
775+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists
776+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "-11,-2,0"
777+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "-4,-5,0"
778+
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "4,0,0"
779+
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-25.258,-8.768,0"
780+
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-17.696,-7.866,0"
781+
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-13.268,0.464,0"
782+
783+
721784
Scenario: Toggle link visibility - wireframe mode
722785
Given an empty IFC project
723786
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"

src/blenderbim/test/bim/test_feature.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,12 @@ def nothing_happens():
373373

374374
@then(parsers.parse('the object "{name}" exists'))
375375
def the_object_name_exists(name: str) -> bpy.types.Object:
376-
obj = bpy.data.objects.get(name)
376+
# Some objects from linked collections may share the same name. This disambiguates them.
377+
if name.startswith("Col:"):
378+
_, collection_name, name = name.split(":")
379+
obj = bpy.data.collections.get(collection_name).objects.get(name)
380+
else:
381+
obj = bpy.data.objects.get(name)
377382
if not obj:
378383
assert False, f'The object "{name}" does not exist'
379384
return obj

0 commit comments

Comments
 (0)