diff --git a/__init__.py b/__init__.py index 9c98d53..7b28ac5 100644 --- a/__init__.py +++ b/__init__.py @@ -29,7 +29,6 @@ from bpy_extras.io_utils import ( axis_conversion, ) - IOOBJOrientationHelper = orientation_helper_factory("IOOBJOrientationHelper", axis_forward='-Z', axis_up='Y') diff --git a/import_gds.py b/import_gds.py index 1b825d8..796d4ef 100644 --- a/import_gds.py +++ b/import_gds.py @@ -8,6 +8,49 @@ import pathlib import bpy from bpy_extras.wm_utils.progress_report import ProgressReport +class Progressor: + def __init__(self, wm, precision = 0.001): + self.wm = wm + self.report = 0 + self.precision = precision + self.next_update = 0 + + @property + def total(self): + return self.report + + @total.setter + def total(self, t): + if self.report >= t: + return + + if self.report: + self.wm.progress_end() + + self.wm.progress_begin(0, t) + self.report = t + + @property + def current(self): + return 0 + + @current.setter + def current(self, c): + prog = float(c)/self.total + if prog >= self.next_update: + self.next_update = prog + self.precision + self.wm.progress_update(c) + + def end(self): + if self.report: + self.report = 0 + self.wm.progress_end() + + def __call__(self, update): + self.total = update.total + self.current = update.current + + def load(context, filepath, *, @@ -24,16 +67,19 @@ def load(context, ): path = pathlib.Path(filepath) - + lib = None + print(lib) with ProgressReport(context.window_manager) as progress: - progress.enter_substeps(1, "Importing GDS %r..." % filepath) + progress.enter_substeps(2, "Importing GDS %r..." % filepath) + prog = Progressor(context.window_manager) with open(filepath, "rb") as f: - lib = gds.parse_file(f) + lib = gds.parse_file(f, progress_func=prog) progress.step("Done, linking references") - lib.link_refs() + lib.link_refs(prog) progress.step("Done, building meshes") + prog.end() layergroups = {} @@ -41,6 +87,8 @@ def load(context, if not len(value.elements): continue + print("structure name: {}".format(name)) + verts = {} faces = {} @@ -60,14 +108,14 @@ def load(context, indices.append(len(verts[element.layer])-1) faces[element.layer].append(tuple(indices)) - + + # build structure object for layer in verts.keys(): if layer not in layergroups: layergroups[layer] = bpy.data.groups.new("layer{}".format(layer)) - meshname = "{}[{}]".format(name.replace("\x00", ""), layer) + meshname = "{}[{}]".format(name, layer) - print(layer, meshname) mesh = bpy.data.meshes.new(meshname) mesh.from_pydata(verts[layer], [], faces[layer]) mesh.update() @@ -77,8 +125,7 @@ def load(context, context.scene.objects.link(obj) layergroups[layer].objects.link(obj) obj.parent = root - - + progress.leave_substeps("Done") return {"FINISHED"}