blender: add progress report

This commit is contained in:
Julian Daube 2019-07-02 19:39:34 +02:00
parent 4565879ffb
commit 99b4d73c24
2 changed files with 56 additions and 10 deletions

View File

@ -29,7 +29,6 @@ from bpy_extras.io_utils import (
axis_conversion,
)
IOOBJOrientationHelper = orientation_helper_factory("IOOBJOrientationHelper", axis_forward='-Z', axis_up='Y')

View File

@ -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 = {}
@ -61,13 +109,13 @@ def load(context,
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()
@ -78,7 +126,6 @@ def load(context,
layergroups[layer].objects.link(obj)
obj.parent = root
progress.leave_substeps("Done")
return {"FINISHED"}