You can now convert from global to local coordinates

This commit is contained in:
Dion Moult
2020-11-05 18:17:45 +11:00
parent 30afd6c95b
commit 6ecf7a80f5
5 changed files with 57 additions and 11 deletions
@@ -169,6 +169,7 @@ if bpy is not None:
operator.PropagateTextData,
operator.PushRepresentation,
operator.ConvertLocalToGlobal,
operator.ConvertGlobalToLocal,
operator.GuessQuantity,
operator.ExecuteBIMTester,
operator.BIMTesterPurge,
+34 -11
View File
@@ -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"}
@@ -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")
@@ -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")
@@ -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))