You can now see and edit WCS in the Blender UI (new API for it too)

This commit is contained in:
Dion Moult
2024-06-23 22:23:39 +10:00
parent 03ee826e67
commit 95d2d0af83
11 changed files with 314 additions and 17 deletions
@@ -20,20 +20,23 @@ import bpy
from . import ui, prop, operator
classes = (
operator.EnableEditingGeoreferencing,
operator.DisableEditingGeoreferencing,
operator.EditGeoreferencing,
operator.SetIfcGridNorth,
operator.SetBlenderGridNorth,
operator.SetIfcTrueNorth,
operator.SetBlenderTrueNorth,
operator.RemoveGeoreferencing,
operator.AddGeoreferencing,
operator.ConvertLocalToGlobal,
operator.ConvertGlobalToLocal,
operator.GetCursorLocation,
operator.ConvertAngleToCoordinates,
operator.ConvertGlobalToLocal,
operator.ConvertLocalToGlobal,
operator.DisableEditingGeoreferencing,
operator.DisableEditingWCS,
operator.EditGeoreferencing,
operator.EditWCS,
operator.EnableEditingGeoreferencing,
operator.EnableEditingWCS,
operator.GetCursorLocation,
operator.ImportPlot,
operator.RemoveGeoreferencing,
operator.SetBlenderGridNorth,
operator.SetBlenderTrueNorth,
operator.SetIfcGridNorth,
operator.SetIfcTrueNorth,
prop.BIMGeoreferenceProperties,
ui.BIM_PT_gis,
ui.BIM_PT_gis_calculator,
@@ -18,8 +18,9 @@
import bpy
import ifcopenshell.util.geolocation
import numpy as np
import blenderbim.tool as tool
import ifcopenshell.util.geolocation
from ifcopenshell.util.doc import get_entity_doc
@@ -42,6 +43,7 @@ class GeoreferenceData:
cls.data["true_derived_angle"] = cls.true_derived_angle()
cls.data["local_unit_symbol"] = cls.local_unit_symbol()
cls.data["map_unit_symbol"] = cls.map_unit_symbol()
cls.data["world_coordinate_system"] = cls.world_coordinate_system()
cls.is_loaded = True
@classmethod
@@ -143,7 +145,7 @@ class GeoreferenceData:
@classmethod
def true_derived_angle(cls):
if cls.data["true_north"]:
return str(round(ifcopenshell.util.geolocation.yaxis2angle(*cls.data["true_north"][0:2]), 3))
return str(round(ifcopenshell.util.geolocation.yaxis2angle(*cls.data["true_north"][:2]), 3))
@classmethod
def local_unit_symbol(cls):
@@ -161,3 +163,18 @@ class GeoreferenceData:
return cls.local_unit_symbol()
return ifcopenshell.util.unit.get_unit_symbol(unit)
return "n/a"
@classmethod
def world_coordinate_system(cls):
wcs = ifcopenshell.util.geolocation.get_wcs(tool.Ifc.get())
result = {}
if wcs is None:
result["has_transformation"] = False
return result
if np.allclose(wcs, np.eye(4)):
result["has_transformation"] = False
else:
result["has_transformation"] = True
result["rotation"] = str(round(ifcopenshell.util.geolocation.yaxis2angle(*wcs[:, 1][:2]), 3))
result["x"], result["y"], result["z"] = wcs[:, 3][:3]
return result
@@ -189,3 +189,33 @@ class ImportPlot(bpy.types.Operator, tool.Ifc.Operator):
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {"RUNNING_MODAL"}
class EnableEditingWCS(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.enable_editing_wcs"
bl_label = "Enable Editing WCS"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Enable editing WCS"
def _execute(self, context):
core.enable_editing_wcs(tool.Georeference)
class EditWCS(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.edit_wcs"
bl_label = "Edit WCS"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Edit the WCS"
def _execute(self, context):
core.edit_wcs(tool.Ifc, tool.Georeference)
class DisableEditingWCS(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.disable_editing_wcs"
bl_label = "Disable Editing WCS"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Close editing panel"
def _execute(self, context):
core.disable_editing_wcs(tool.Georeference)
@@ -43,6 +43,7 @@ class BIMGeoreferenceProperties(PropertyGroup):
items=get_coordinate_operation_class, name="Coordinate Operation Class"
)
is_editing: BoolProperty(name="Is Editing")
is_editing_wcs: BoolProperty(name="Is Editing WCS")
coordinate_operation: CollectionProperty(name="Coordinate Operation", type=Attribute)
projected_crs: CollectionProperty(name="Projected CRS", type=Attribute)
local_coordinates: StringProperty(
@@ -83,3 +84,7 @@ class BIMGeoreferenceProperties(PropertyGroup):
has_true_north: BoolProperty(name="Has True North", default=True)
true_north_abscissa: StringProperty(name="True North Abscissa")
true_north_ordinate: StringProperty(name="True North Ordinate")
wcs_x: StringProperty(name="WCS X", default="0")
wcs_y: StringProperty(name="WCS Y", default="0")
wcs_z: StringProperty(name="WCS Z", default="0")
wcs_rotation: StringProperty(name="WCS Rotation", default="0")
@@ -40,8 +40,14 @@ class BIM_PT_gis(Panel):
GeoreferenceData.load()
if props.is_editing:
return self.draw_editable_ui(context)
self.draw_ui(context)
self.draw_editable_ui(context)
else:
self.draw_ui(context)
if props.is_editing_wcs:
self.draw_editable_wcs_ui(context)
else:
self.draw_wcs_ui()
def draw_editable_ui(self, context):
props = context.scene.BIMGeoreferenceProperties
@@ -157,6 +163,47 @@ class BIM_PT_gis(Panel):
row.label(text="Derived Angle")
row.label(text=GeoreferenceData.data["true_derived_angle"])
def draw_wcs_ui(self):
row = self.layout.row(align=True)
row.label(text="World Coordinate System", icon="EMPTY_ARROWS")
row.operator("bim.enable_editing_wcs", icon="GREASEPENCIL", text="")
if GeoreferenceData.data["world_coordinate_system"]["has_transformation"]:
row = self.layout.row()
row.label(text="Unrecommended Transformation Found", icon="ERROR")
row = self.layout.row(align=True)
row.label(text="X")
row.label(text=str(GeoreferenceData.data["world_coordinate_system"]["x"]))
row = self.layout.row(align=True)
row.label(text="Y")
row.label(text=str(GeoreferenceData.data["world_coordinate_system"]["y"]))
row = self.layout.row(align=True)
row.label(text="Z")
row.label(text=str(GeoreferenceData.data["world_coordinate_system"]["z"]))
row = self.layout.row(align=True)
row.label(text="Rotation")
row.label(text=str(GeoreferenceData.data["world_coordinate_system"]["rotation"]))
else:
row = self.layout.row()
row.label(text="No WCS Transformation", icon="CHECKMARK")
def draw_editable_wcs_ui(self, context):
props = context.scene.BIMGeoreferenceProperties
row = self.layout.row(align=True)
row.label(text="World Coordinate System", icon="EMPTY_ARROWS")
row.operator("bim.edit_wcs", icon="CHECKMARK", text="")
row.operator("bim.disable_editing_wcs", icon="CANCEL", text="")
row = self.layout.row()
row.prop(props, "wcs_x")
row = self.layout.row()
row.prop(props, "wcs_y")
row = self.layout.row()
row.prop(props, "wcs_z")
row = self.layout.row()
row.prop(props, "wcs_rotation")
class BIM_PT_gis_calculator(Panel):
bl_idname = "BIM_PT_gis_calculator"
@@ -85,3 +85,18 @@ def convert_angle_to_coord(georeference, type):
def import_plot(georeference, filepath):
georeference.import_plot(filepath)
def enable_editing_wcs(georeference):
georeference.import_wcs()
georeference.enable_editing_wcs()
def disable_editing_wcs(georeference):
georeference.disable_editing_wcs()
def edit_wcs(ifc, georeference):
wcs = georeference.export_wcs()
georeference.set_wcs(wcs)
georeference.disable_editing_wcs()
+6 -1
View File
@@ -418,17 +418,21 @@ class Geometry:
class Georeference:
def angle2coords(cls, angle, type): pass
def disable_editing(cls): pass
def disable_editing_wcs(cls): pass
def enable_editing(cls): pass
def enable_editing_wcs(cls): pass
def enh2xyz(cls, coordinates): pass
def export_wcs(cls): pass
def get_angle(cls, type): pass
def get_coordinate_operation_attributes(cls): pass
def get_coordinates(cls, io): pass
def get_cursor_location(cls): pass
def get_coordinate_operation_attributes(cls): pass
def get_projected_crs_attributes(cls): pass
def get_true_north_attributes(cls): pass
def import_map_conversion(cls): pass
def import_projected_crs(cls): pass
def import_true_north(cls): pass
def import_wcs(cls): pass
def set_blender_grid_north(cls): pass
def set_blender_true_north(cls): pass
def set_coordinates(cls, io, coordinates): pass
@@ -436,6 +440,7 @@ class Georeference:
def set_ifc_grid_north(cls): pass
def set_ifc_true_north(cls): pass
def set_vector_coordinates(cls, vector_coordinates, type): pass
def set_wcs(cls, matrix): pass
def xyz2enh(cls, coordinates): pass
+42 -1
View File
@@ -18,9 +18,11 @@
import bpy
import json
import numpy as np
import ifcopenshell
import ifcopenshell.api.georeference
import blenderbim.core.tool
import blenderbim.tool as tool
import ifcopenshell
import blenderbim.bim.helper
from math import radians, cos, sin
@@ -169,6 +171,14 @@ class Georeference(blenderbim.core.tool.Georeference):
def disable_editing(cls):
bpy.context.scene.BIMGeoreferenceProperties.is_editing = False
@classmethod
def enable_editing_wcs(cls):
bpy.context.scene.BIMGeoreferenceProperties.is_editing_wcs = True
@classmethod
def disable_editing_wcs(cls):
bpy.context.scene.BIMGeoreferenceProperties.is_editing_wcs = False
@classmethod
def set_coordinates(cls, io, coordinates):
if io == "local":
@@ -315,3 +325,34 @@ class Georeference(blenderbim.core.tool.Georeference):
bm.verts.new(vertex)
bm.to_mesh(mesh)
bm.free()
@classmethod
def import_wcs(cls):
props = bpy.context.scene.BIMGeoreferenceProperties
wcs = None
for context in tool.Ifc.get().by_type("IfcGeometricRepresentationContext", include_subtypes=False):
wcs = context.WorldCoordinateSystem
if context.ContextType == "Model":
break
if not wcs:
return
placement = ifcopenshell.util.placement.get_axis2placement(wcs)
if np.allclose(placement, np.eye(4)):
props.wcs_x = props.wcs_y = props.wcs_z = props.wcs_rotation = "0"
else:
props.wcs_rotation = str(round(ifcopenshell.util.geolocation.yaxis2angle(*placement[:, 1][:2]), 3))
props.wcs_x, props.wcs_y, props.wcs_z = map(str, placement[:, 3][:3])
@classmethod
def export_wcs(cls):
props = bpy.context.scene.BIMGeoreferenceProperties
return {
"x": float(props.wcs_x),
"y": float(props.wcs_y),
"z": float(props.wcs_z),
"rotation": float(props.wcs_rotation),
}
@classmethod
def set_wcs(cls, wcs):
ifcopenshell.api.georeference.edit_wcs(tool.Ifc.get(), **wcs, is_si=False)