Georeferencing calculator can now calculate blender offsets too

This commit is contained in:
Dion Moult
2024-07-27 19:54:12 +10:00
parent 1ac1b289c1
commit 4abcbbb4f9
4 changed files with 94 additions and 43 deletions
@@ -22,8 +22,6 @@ from . import ui, prop, operator
classes = (
operator.AddGeoreferencing,
operator.ConvertAngleToCoordinates,
operator.ConvertGlobalToLocal,
operator.ConvertLocalToGlobal,
operator.DisableEditingGeoreferencing,
operator.DisableEditingTrueNorth,
operator.DisableEditingWCS,
@@ -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"
@@ -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",
@@ -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']})")