From df12d6bab174d6f759bccd0a10527482e889e5db Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 12 May 2020 13:31:16 +1000 Subject: [PATCH] New feature to convert from local to global coordinates --- .../blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/operator.py | 28 ++++++++++++++++++- src/ifcblenderexport/blenderbim/bim/ui.py | 3 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 2c6d30a883..294683546d 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -127,6 +127,7 @@ if bpy is not None: operator.RemoveVariable, operator.PropagateTextData, operator.PushRepresentation, + operator.ConvertLocalToGlobal, prop.StrProperty, prop.Variable, prop.Classification, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 9cebac6e55..81fbeca274 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -18,7 +18,7 @@ from . import annotation from bpy_extras.io_utils import ImportHelper from itertools import cycle from mathutils import Vector, Matrix, Euler -from math import radians, atan, tan +from math import radians, atan, tan, cos, sin, atan2 from pathlib import Path colour_list = [ @@ -2653,3 +2653,29 @@ class PushRepresentation(bpy.types.Operator): return element.ContextType == self.context \ and element.ContextIdentifier == self.subcontext \ and element.TargetView == self.target_view + + +class ConvertLocalToGlobal(bpy.types.Operator): + bl_idname = 'bim.convert_local_to_global' + bl_label = 'Convert Local To Global' + + def execute(self, context): + x, y, z = bpy.context.scene.cursor.location + + if bpy.context.scene.MapConversion.scale: + scale = float(bpy.context.scene.MapConversion.scale) + else: + scale = 1. + + rotation = atan2( + float(bpy.context.scene.MapConversion.x_axis_ordinate), + float(bpy.context.scene.MapConversion.x_axis_abscissa)) + a = scale * cos(rotation) + b = scale * sin(rotation) + + eastings = (a * x) - (b * y) + float(bpy.context.scene.MapConversion.eastings) + northings = (b * x) + (a * y) + float(bpy.context.scene.MapConversion.northings) + height = z + float(bpy.context.scene.MapConversion.orthogonal_height) + + bpy.context.scene.cursor.location = (eastings, northings, height) + return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 7227a75fe3..a4a156f8b7 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -535,6 +535,9 @@ class BIM_PT_gis(Panel): layout.row().prop(scene.TargetCRS, 'map_zone') layout.row().prop(scene.TargetCRS, 'map_unit') + row = layout.row(align=True) + row.operator('bim.convert_local_to_global') + class BIM_PT_documentation(Panel): bl_label = "Documentation"