mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
You can now convert from global to local coordinates
This commit is contained in:
@@ -169,6 +169,7 @@ if bpy is not None:
|
|||||||
operator.PropagateTextData,
|
operator.PropagateTextData,
|
||||||
operator.PushRepresentation,
|
operator.PushRepresentation,
|
||||||
operator.ConvertLocalToGlobal,
|
operator.ConvertLocalToGlobal,
|
||||||
|
operator.ConvertGlobalToLocal,
|
||||||
operator.GuessQuantity,
|
operator.GuessQuantity,
|
||||||
operator.ExecuteBIMTester,
|
operator.ExecuteBIMTester,
|
||||||
operator.BIMTesterPurge,
|
operator.BIMTesterPurge,
|
||||||
|
|||||||
@@ -3596,25 +3596,48 @@ class ConvertLocalToGlobal(bpy.types.Operator):
|
|||||||
bl_label = "Convert Local To Global"
|
bl_label = "Convert Local To Global"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
x, y, z = bpy.context.scene.cursor.location
|
|
||||||
|
|
||||||
if bpy.context.scene.MapConversion.scale:
|
if bpy.context.scene.MapConversion.scale:
|
||||||
scale = float(bpy.context.scene.MapConversion.scale)
|
scale = float(bpy.context.scene.MapConversion.scale)
|
||||||
else:
|
else:
|
||||||
scale = 1.0
|
scale = 1.0
|
||||||
|
results = ifcopenshell.util.geolocation.xyz2enh(
|
||||||
rotation = atan2(
|
bpy.context.scene.cursor.location[0],
|
||||||
float(bpy.context.scene.MapConversion.x_axis_ordinate),
|
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_abscissa),
|
||||||
|
float(bpy.context.scene.MapConversion.x_axis_ordinate),
|
||||||
|
scale
|
||||||
)
|
)
|
||||||
a = scale * cos(rotation)
|
print("Coordinates:", results)
|
||||||
b = scale * sin(rotation)
|
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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1473,6 +1473,9 @@ class BIMProperties(PropertyGroup):
|
|||||||
active_clash_set_index: IntProperty(name="Active Clash Set Index")
|
active_clash_set_index: IntProperty(name="Active Clash Set Index")
|
||||||
constraints: CollectionProperty(name="Constraints", type=Constraint)
|
constraints: CollectionProperty(name="Constraints", type=Constraint)
|
||||||
active_constraint_index: IntProperty(name="Active Constraint Index")
|
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_recipes: EnumProperty(items=getIfcPatchRecipes, name="Recipes")
|
||||||
ifc_patch_input: StringProperty(default="", name="IFC Patch Input IFC")
|
ifc_patch_input: StringProperty(default="", name="IFC Patch Input IFC")
|
||||||
ifc_patch_output: StringProperty(default="", name="IFC Patch Output 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 = layout.row(align=True)
|
||||||
row.operator("bim.convert_local_to_global")
|
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"):
|
if hasattr(bpy.context.scene, "sun_pos_properties"):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator("bim.get_north_offset")
|
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)
|
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
|
# Used for converting the X and Y vectors of the X Axis in IFC geolocation
|
||||||
def xy2angle(x, y):
|
def xy2angle(x, y):
|
||||||
return math.degrees(math.atan2(y, x))
|
return math.degrees(math.atan2(y, x))
|
||||||
|
|||||||
Reference in New Issue
Block a user