From 4abcbbb4f965d4b9217acba6f30ecd4091142115 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 27 Jul 2024 19:54:12 +1000 Subject: [PATCH] Georeferencing calculator can now calculate blender offsets too --- .../bim/module/georeference/__init__.py | 2 - .../bim/module/georeference/operator.py | 32 ------- .../bim/module/georeference/prop.py | 86 ++++++++++++++++++- .../blenderbim/bim/module/georeference/ui.py | 17 ++-- 4 files changed, 94 insertions(+), 43 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/georeference/__init__.py b/src/blenderbim/blenderbim/bim/module/georeference/__init__.py index 303fd50ccc..fe5ff8d028 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/__init__.py @@ -22,8 +22,6 @@ from . import ui, prop, operator classes = ( operator.AddGeoreferencing, operator.ConvertAngleToCoordinates, - operator.ConvertGlobalToLocal, - operator.ConvertLocalToGlobal, operator.DisableEditingGeoreferencing, operator.DisableEditingTrueNorth, operator.DisableEditingWCS, diff --git a/src/blenderbim/blenderbim/bim/module/georeference/operator.py b/src/blenderbim/blenderbim/bim/module/georeference/operator.py index 10f7d0c209..23591ee305 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/operator.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/operator.py @@ -87,38 +87,6 @@ class GetCursorLocation(bpy.types.Operator, tool.Ifc.Operator): core.get_cursor_location(tool.Georeference) -class ConvertLocalToGlobal(bpy.types.Operator, tool.Ifc.Operator): - bl_idname = "bim.convert_local_to_global" - bl_label = "Convert Local To Global" - bl_options = {"REGISTER", "UNDO"} - bl_description = "Convert local coordinate to global coordinate" - - @classmethod - def poll(cls, context): - file = tool.Ifc.get() - props = context.scene.BIMGeoreferenceProperties - return file and props.local_coordinates.count(",") == 2 - - def _execute(self, context): - core.convert_local_to_global(tool.Georeference) - - -class ConvertGlobalToLocal(bpy.types.Operator, tool.Ifc.Operator): - bl_idname = "bim.convert_global_to_local" - bl_label = "Convert Global To Local" - bl_options = {"REGISTER", "UNDO"} - bl_description = "Convert global coordinate to local coordinate" - - @classmethod - def poll(cls, context): - file = tool.Ifc.get() - props = context.scene.BIMGeoreferenceProperties - return file and file.by_type("IfcUnitAssignment") and props.local_coordinates.count(",") == 2 - - def _execute(self, context): - core.convert_global_to_local(tool.Georeference) - - class ConvertAngleToCoordinates(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.convert_angle_to_coord" bl_label = "Convert Angle To Y Axis" diff --git a/src/blenderbim/blenderbim/bim/module/georeference/prop.py b/src/blenderbim/blenderbim/bim/module/georeference/prop.py index dfa947e03c..28144ce578 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/prop.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/prop.py @@ -18,6 +18,7 @@ import bpy import ifcopenshell.util.geolocation +import blenderbim.tool as tool from blenderbim.bim.prop import Attribute from bpy.types import PropertyGroup from bpy.props import ( @@ -101,6 +102,74 @@ def update_should_visualise(self, context): GeoreferenceDecorator.uninstall() +def update_blender_coordinates(self, context): + props = bpy.context.scene.BIMGeoreferenceProperties + if props.is_updating_coordinates: + return + props.is_updating_coordinates = True + blender_coordinates = tool.Georeference.get_coordinates("blender") + local_coordinates = ifcopenshell.util.geolocation.xyz2enh( + *blender_coordinates, + float(props.blender_offset_x), + float(props.blender_offset_y), + float(props.blender_offset_z), + float(props.blender_x_axis_abscissa), + float(props.blender_x_axis_ordinate), + ) + tool.Georeference.set_coordinates("local", local_coordinates) + tool.Georeference.set_coordinates( + "map", ifcopenshell.util.geolocation.auto_xyz2enh(tool.Ifc.get(), *local_coordinates) + ) + props.is_updating_coordinates = False + + +def update_local_coordinates(self, context): + props = bpy.context.scene.BIMGeoreferenceProperties + if props.is_updating_coordinates: + return + props.is_updating_coordinates = True + local_coordinates = tool.Georeference.get_coordinates("local") + tool.Georeference.set_coordinates( + "map", ifcopenshell.util.geolocation.auto_xyz2enh(tool.Ifc.get(), *local_coordinates) + ) + if props.has_blender_offset: + tool.Georeference.set_coordinates( + "blender", + ifcopenshell.util.geolocation.enh2xyz( + *local_coordinates, + float(props.blender_offset_x), + float(props.blender_offset_y), + float(props.blender_offset_z), + float(props.blender_x_axis_abscissa), + float(props.blender_x_axis_ordinate), + ), + ) + props.is_updating_coordinates = False + + +def update_map_coordinates(self, context): + props = bpy.context.scene.BIMGeoreferenceProperties + if props.is_updating_coordinates: + return + props.is_updating_coordinates = True + map_coordinates = tool.Georeference.get_coordinates("map") + local_coordinates = ifcopenshell.util.geolocation.auto_enh2xyz(tool.Ifc.get(), *map_coordinates) + tool.Georeference.set_coordinates("local", local_coordinates) + if props.has_blender_offset: + tool.Georeference.set_coordinates( + "blender", + ifcopenshell.util.geolocation.enh2xyz( + *local_coordinates, + float(props.blender_offset_x), + float(props.blender_offset_y), + float(props.blender_offset_z), + float(props.blender_x_axis_abscissa), + float(props.blender_x_axis_ordinate), + ), + ) + props.is_updating_coordinates = False + + class BIMGeoreferenceProperties(PropertyGroup): coordinate_operation_class: bpy.props.EnumProperty( items=get_coordinate_operation_class, name="Coordinate Operation Class" @@ -111,11 +180,24 @@ class BIMGeoreferenceProperties(PropertyGroup): is_editing_true_north: BoolProperty(name="Is Editing True North") coordinate_operation: CollectionProperty(name="Coordinate Operation", type=Attribute) projected_crs: CollectionProperty(name="Projected CRS", type=Attribute) + is_updating_coordinates: BoolProperty(name="Is Updating Coordinates", default=False) + blender_coordinates: StringProperty( + name="Blender Coordinates", + description='Formatted "x,y,z" (without quotes)', + default="0,0,0", + update=update_blender_coordinates, + ) local_coordinates: StringProperty( - name="Local Coordinates", description='Formatted "x,y,z" (without quotes)', default="0,0,0" + name="Local Coordinates", + description='Formatted "x,y,z" (without quotes)', + default="0,0,0", + update=update_local_coordinates, ) map_coordinates: StringProperty( - name="Map Coordinates", description='Formatted "x,y,z" (without quotes)', default="0,0,0" + name="Map Coordinates", + description='Formatted "x,y,z" (without quotes)', + default="0,0,0", + update=update_map_coordinates, ) should_visualise: BoolProperty( name="Should Visualise", diff --git a/src/blenderbim/blenderbim/bim/module/georeference/ui.py b/src/blenderbim/blenderbim/bim/module/georeference/ui.py index dcd2d391b4..3c0f8210fc 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/ui.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/ui.py @@ -288,12 +288,15 @@ class BIM_PT_gis_calculator(Panel): props = context.scene.BIMGeoreferenceProperties - row = self.layout.row(align=True) - row.prop(props, "local_coordinates", text=f"Local ({GeoreferenceData.data['local_unit_symbol']})") - row.operator("bim.get_cursor_location", text="", icon="TRACKER") - row = self.layout.row() - row.prop(props, "map_coordinates", text=f"Map ({GeoreferenceData.data['map_unit_symbol']})") + if props.has_blender_offset: + row = self.layout.row(align=True) + row.prop(props, "blender_coordinates", text=f"Blender ({GeoreferenceData.data['local_unit_symbol']})") + row.operator("bim.get_cursor_location", text="", icon="TRACKER") row = self.layout.row(align=True) - row.operator("bim.convert_local_to_global", text="Local to Global") - row.operator("bim.convert_global_to_local", text="Global to Local") + row.prop(props, "local_coordinates", text=f"Local ({GeoreferenceData.data['local_unit_symbol']})") + if not props.has_blender_offset: + row.operator("bim.get_cursor_location", text="", icon="TRACKER") + + row = self.layout.row() + row.prop(props, "map_coordinates", text=f"Map ({GeoreferenceData.data['map_unit_symbol']})")