From 6ecf7a80f527b2c5954d9f4520a17db7b225141e Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 5 Nov 2020 18:17:45 +1100 Subject: [PATCH] You can now convert from global to local coordinates --- .../blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/operator.py | 45 ++++++++++++++----- src/ifcblenderexport/blenderbim/bim/prop.py | 3 ++ src/ifcblenderexport/blenderbim/bim/ui.py | 7 +++ .../ifcopenshell/util/geolocation.py | 12 +++++ 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 98efd6b018..0747c8d7d7 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -169,6 +169,7 @@ if bpy is not None: operator.PropagateTextData, operator.PushRepresentation, operator.ConvertLocalToGlobal, + operator.ConvertGlobalToLocal, operator.GuessQuantity, operator.ExecuteBIMTester, operator.BIMTesterPurge, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index c4d60a6711..2ded6d15c8 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -3596,25 +3596,48 @@ class ConvertLocalToGlobal(bpy.types.Operator): 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.0 - - rotation = atan2( - float(bpy.context.scene.MapConversion.x_axis_ordinate), + results = ifcopenshell.util.geolocation.xyz2enh( + bpy.context.scene.cursor.location[0], + bpy.context.scene.cursor.location[1], + bpy.context.scene.cursor.location[2], + float(bpy.context.scene.MapConversion.eastings), + float(bpy.context.scene.MapConversion.northings), + float(bpy.context.scene.MapConversion.orthogonal_height), float(bpy.context.scene.MapConversion.x_axis_abscissa), + float(bpy.context.scene.MapConversion.x_axis_ordinate), + scale ) - a = scale * cos(rotation) - b = scale * sin(rotation) + print("Coordinates:", results) + bpy.context.scene.cursor.location = results + return {"FINISHED"} - 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) +class ConvertGlobalToLocal(bpy.types.Operator): + bl_idname = "bim.convert_global_to_local" + bl_label = "Convert Global To Local" + + def execute(self, context): + if bpy.context.scene.MapConversion.scale: + scale = float(bpy.context.scene.MapConversion.scale) + else: + scale = 1.0 + results = ifcopenshell.util.geolocation.enh2xyz( + float(bpy.context.scene.BIMProperties.eastings), + float(bpy.context.scene.BIMProperties.northings), + float(bpy.context.scene.BIMProperties.orthogonal_height), + float(bpy.context.scene.MapConversion.eastings), + float(bpy.context.scene.MapConversion.northings), + float(bpy.context.scene.MapConversion.orthogonal_height), + float(bpy.context.scene.MapConversion.x_axis_abscissa), + float(bpy.context.scene.MapConversion.x_axis_ordinate), + scale + ) + print("Coordinates:", results) + bpy.context.scene.cursor.location = results return {"FINISHED"} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 9286232873..32139193b1 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -1473,6 +1473,9 @@ class BIMProperties(PropertyGroup): active_clash_set_index: IntProperty(name="Active Clash Set Index") constraints: CollectionProperty(name="Constraints", type=Constraint) active_constraint_index: IntProperty(name="Active Constraint Index") + eastings: StringProperty(name="Eastings") + northings: StringProperty(name="Northings") + orthogonal_height: StringProperty(name="Orthogonal Height") ifc_patch_recipes: EnumProperty(items=getIfcPatchRecipes, name="Recipes") ifc_patch_input: StringProperty(default="", name="IFC Patch Input IFC") ifc_patch_output: StringProperty(default="", name="IFC Patch Output IFC") diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 7767e92ab2..8bca2125e8 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -839,6 +839,13 @@ class BIM_PT_gis(Panel): row = layout.row(align=True) row.operator("bim.convert_local_to_global") + layout.row().prop(scene.BIMProperties, "eastings") + layout.row().prop(scene.BIMProperties, "northings") + layout.row().prop(scene.BIMProperties, "orthogonal_height") + + row = layout.row(align=True) + row.operator("bim.convert_global_to_local") + if hasattr(bpy.context.scene, "sun_pos_properties"): row = layout.row(align=True) row.operator("bim.get_north_offset") diff --git a/src/ifcopenshell-python/ifcopenshell/util/geolocation.py b/src/ifcopenshell-python/ifcopenshell/util/geolocation.py index 7e1dcd8b96..4bc3e9c2c1 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/geolocation.py +++ b/src/ifcopenshell-python/ifcopenshell/util/geolocation.py @@ -33,6 +33,18 @@ def xyz2enh(x, y, z, eastings, northings, orthogonal_height, x_axis_abscissa, x_ return (eastings, northings, height) +def enh2xyz(e, n, h, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None): + if scale is None: + scale = 1.0 + rotation = math.atan2(x_axis_ordinate, x_axis_abscissa) + a = scale * math.cos(rotation) + b = scale * math.sin(rotation) + x = ((b * n) - (b * northings) - (a * eastings) + (a * e)) / ((a * a) + (b * b)) + y = ((a * n) - (a * northings) + (b * eastings) - (b * e)) / ((a * a) + (b * b)) + z = h - orthogonal_height + return (x, y, z) + + # Used for converting the X and Y vectors of the X Axis in IFC geolocation def xy2angle(x, y): return math.degrees(math.atan2(y, x))