From 2ed24434c88ee6000c400a6d150a295c932834bd Mon Sep 17 00:00:00 2001 From: "Sigma Dimensions (Yass)" <79010126+myoualid@users.noreply.github.com> Date: Mon, 14 Aug 2023 18:21:44 +0100 Subject: [PATCH] experimental import plot coordinates --- .../bim/module/georeference/__init__.py | 1 + .../bim/module/georeference/operator.py | 19 ++++++++++- .../blenderbim/bim/module/misc/ui.py | 3 +- .../blenderbim/core/georeference.py | 5 ++- .../blenderbim/tool/georeference.py | 34 +++++++++++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/georeference/__init__.py b/src/blenderbim/blenderbim/bim/module/georeference/__init__.py index 146ce8b1c3..6a1c3fb1b6 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/__init__.py @@ -34,6 +34,7 @@ classes = ( operator.GetCursorLocation, operator.SetCursorLocation, operator.ConvertAngleToCoordinates, + operator.ImportPlot, prop.BIMGeoreferenceProperties, ui.BIM_PT_gis, ui.BIM_PT_gis_utilities, diff --git a/src/blenderbim/blenderbim/bim/module/georeference/operator.py b/src/blenderbim/blenderbim/bim/module/georeference/operator.py index cbcfe930ea..eec2dab9ca 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/operator.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/operator.py @@ -110,7 +110,7 @@ class SetCursorLocation(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.set_cursor_location" bl_label = "Set Cursor Location" bl_options = {"REGISTER", "UNDO"} - bl_description = "Move curson location to the specified coordinates" + bl_description = "Move cursor location to the specified coordinates" @classmethod def poll(cls, context): @@ -187,3 +187,20 @@ class ConvertAngleToCoordinates(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): core.convert_angle_to_coord(tool.Georeference, type=self.type) + + +class ImportPlot(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.import_plot" + bl_label = "Import Plot" + bl_options = {"REGISTER", "UNDO"} + bl_description = "Import plot" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + filter_glob: bpy.props.StringProperty(default="*.csv", options={"HIDDEN"}) + + def execute(self, context): + core.import_plot(tool.Georeference, filepath=self.filepath) + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} diff --git a/src/blenderbim/blenderbim/bim/module/misc/ui.py b/src/blenderbim/blenderbim/bim/module/misc/ui.py index 9fe4e178cc..a2c9ebb0ec 100644 --- a/src/blenderbim/blenderbim/bim/module/misc/ui.py +++ b/src/blenderbim/blenderbim/bim/module/misc/ui.py @@ -50,8 +50,9 @@ class BIM_PT_misc_utilities(bpy.types.Panel): row.operator("bim.clean_wireframes") row = layout.row() row.operator("bim.patch_non_parametric_mep_segment") - row = layout.row(align=True) row.operator("bim.enable_editing_sketch_extrusion_profile", text="Start Sketching") row.operator("bim.edit_sketch_extrusion_profile", text="", icon="FILE_REFRESH") row.operator("bim.disable_editing_sketch_extrusion_profile", text="", icon="CANCEL") + row = layout.row() + row.operator("bim.import_plot", text="Import Plot Coordinates", icon="FILE_FOLDER") diff --git a/src/blenderbim/blenderbim/core/georeference.py b/src/blenderbim/blenderbim/core/georeference.py index f3faded3b2..dcc9823904 100644 --- a/src/blenderbim/blenderbim/core/georeference.py +++ b/src/blenderbim/blenderbim/core/georeference.py @@ -83,4 +83,7 @@ def convert_global_to_local(georeference): def convert_angle_to_coord(georeference, type): vector_coordinates = georeference.angle2coords(georeference.get_angle(type), type) - georeference.set_vector_coordinates(vector_coordinates,type) \ No newline at end of file + georeference.set_vector_coordinates(vector_coordinates,type) + +def import_plot(georeference, filepath): + georeference.import_plot(filepath, georeference.get_map_conversion()) diff --git a/src/blenderbim/blenderbim/tool/georeference.py b/src/blenderbim/blenderbim/tool/georeference.py index 2dc6001b61..52c31de1a2 100644 --- a/src/blenderbim/blenderbim/tool/georeference.py +++ b/src/blenderbim/blenderbim/tool/georeference.py @@ -296,3 +296,37 @@ class Georeference(blenderbim.core.tool.Georeference): elif type == "rel_y": bpy.context.scene.BIMGeoreferenceProperties.y_axis_abscissa_output = str(x) bpy.context.scene.BIMGeoreferenceProperties.y_axis_ordinate_output = str(y) + + @classmethod + def import_plot(cls, filepath, map_conversion): + import bmesh + + def parse_csv(file_path): + import csv + + with open(file_path, "r") as f: + reader = csv.reader(f) # Assuming tab-delimited CSV + rows = [] + for row in reader: + if len(row) == 0: + continue + rows.append(row) + return rows + + rows = parse_csv(filepath) + vertices = [] + for row in rows: + coordinates = cls.enh2xyz([float(row[0]), float(row[1]), float(row[2])], map_conversion) + vertices.append(coordinates) + + mesh = bpy.data.meshes.new("mesh") + obj = bpy.data.objects.new("Plot Line", mesh) + bpy.context.scene.collection.objects.link(obj) + bpy.context.view_layer.objects.active = obj + obj.select_set(True) + obj.data + bm = bmesh.new() + for vertex in vertices: + bm.verts.new(vertex) + bm.to_mesh(mesh) + bm.free()