blender: make progress report work consistent
This commit is contained in:
parent
5e6f3d243b
commit
416f5aef69
@ -31,7 +31,19 @@ class Library(object):
|
|||||||
|
|
||||||
return (coord[0] * fact, coord[1] * fact)
|
return (coord[0] * fact, coord[1] * fact)
|
||||||
|
|
||||||
def link_refs(self, progress_callback=None):
|
def link_refs(self, root, progress_callback=None):
|
||||||
|
for ref in root.references:
|
||||||
|
if isinstance(ref.structure, str):
|
||||||
|
try:
|
||||||
|
element.structure = self.structures[ref.structure]
|
||||||
|
except KeyError:
|
||||||
|
err = LinkError("dangeling sref (structure {} is not defined in library)".format(ref.structure))
|
||||||
|
err.element = root
|
||||||
|
raise err
|
||||||
|
|
||||||
|
return root
|
||||||
|
|
||||||
|
def link_all_refs(self, progress_callback=None):
|
||||||
class Progress(ProgressGetter):
|
class Progress(ProgressGetter):
|
||||||
total = 0
|
total = 0
|
||||||
current = 0
|
current = 0
|
||||||
|
@ -98,11 +98,14 @@ class SceneInserter(object):
|
|||||||
def link(self, obj):
|
def link(self, obj):
|
||||||
self.context.scene.objects.link(obj)
|
self.context.scene.objects.link(obj)
|
||||||
|
|
||||||
def build_object(self, structure):
|
def build_object(self, structure, progress=None):
|
||||||
# is the object already existent => return new instance
|
# is the object already existent => return new instance
|
||||||
if structure.name in bpy.data.objects:
|
if structure.name in bpy.data.objects:
|
||||||
return self.new_instance(bpy.data.objects[structure.name])
|
return self.new_instance(bpy.data.objects[structure.name])
|
||||||
|
|
||||||
|
if progress:
|
||||||
|
progress.total += 1 + len(structure.references)
|
||||||
|
|
||||||
verts = {}
|
verts = {}
|
||||||
faces = {}
|
faces = {}
|
||||||
|
|
||||||
@ -149,10 +152,21 @@ class SceneInserter(object):
|
|||||||
self.layers[layer].link(obj)
|
self.layers[layer].link(obj)
|
||||||
obj.parent = root
|
obj.parent = root
|
||||||
|
|
||||||
|
if progress:
|
||||||
|
progress.inc()
|
||||||
|
|
||||||
# handle all references
|
# handle all references
|
||||||
# build tree depth first
|
# build tree depth first
|
||||||
for reference in structure.references:
|
for reference in structure.references:
|
||||||
obj = self.build_object(reference.structure)
|
if isinstance(reference.structure, str):
|
||||||
|
if reference.structure not in self.lib.structures:
|
||||||
|
progress.inc()
|
||||||
|
continue
|
||||||
|
|
||||||
|
# resolve structure
|
||||||
|
reference.structure = self.lib.structures[reference.structure]
|
||||||
|
|
||||||
|
obj = self.build_object(reference.structure, progress=progress)
|
||||||
|
|
||||||
if hasattr(reference, "size"):
|
if hasattr(reference, "size"):
|
||||||
def add(a,b):
|
def add(a,b):
|
||||||
@ -209,6 +223,9 @@ class SceneInserter(object):
|
|||||||
obj.rotation_euler.z = math.radians(trans.rotation)
|
obj.rotation_euler.z = math.radians(trans.rotation)
|
||||||
obj.scale = (trans.zoom, trans.zoom, 1)
|
obj.scale = (trans.zoom, trans.zoom, 1)
|
||||||
|
|
||||||
|
if progress:
|
||||||
|
progress.inc()
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|
||||||
def new_instance(self, obj):
|
def new_instance(self, obj):
|
||||||
@ -230,7 +247,7 @@ class SceneInserter(object):
|
|||||||
|
|
||||||
def __call__(self, progress=None):
|
def __call__(self, progress=None):
|
||||||
class ProgressTracker:
|
class ProgressTracker:
|
||||||
def __init__(self, total, callback):
|
def __init__(self, callback, total=0):
|
||||||
self.total = total
|
self.total = total
|
||||||
self.current = 0
|
self.current = 0
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
@ -245,12 +262,18 @@ class SceneInserter(object):
|
|||||||
if self.top_cell:
|
if self.top_cell:
|
||||||
if self.top_cell not in self.lib.structures:
|
if self.top_cell not in self.lib.structures:
|
||||||
return None
|
return None
|
||||||
|
s = self.lib.structures[self.top_cell]
|
||||||
|
|
||||||
|
progressTracker = ProgressTracker(progress, 1+len(s.references))
|
||||||
|
self.build_object(s,progress=progressTracker)
|
||||||
|
|
||||||
self.build_object(self.lib.structures[self.top_cell])
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# build all structures in object
|
progressTracker = ProgressTracker(progress)
|
||||||
progressTracker = ProgressTracker(2*(len(self.lib.structures)-len(self.ignore_structures)), progress)
|
progressTracker.total = len(self.lib.structures)
|
||||||
|
|
||||||
|
# self.link_all_refs(progressTracker)
|
||||||
|
|
||||||
# build all structures first
|
# build all structures first
|
||||||
# since references could reference unknown objects otherwise
|
# since references could reference unknown objects otherwise
|
||||||
for name, value in self.lib.structures.items():
|
for name, value in self.lib.structures.items():
|
||||||
@ -258,8 +281,7 @@ class SceneInserter(object):
|
|||||||
if name in self.ignore_structures:
|
if name in self.ignore_structures:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.build_object(value)
|
self.build_object(value, progress=progressTracker)
|
||||||
progressTracker.total += len(value.references)
|
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -285,11 +307,6 @@ def load(context,
|
|||||||
progress.step("linking references")
|
progress.step("linking references")
|
||||||
prog.end()
|
prog.end()
|
||||||
|
|
||||||
lib.link_refs(prog)
|
|
||||||
|
|
||||||
progress.step("inserting structures into scene")
|
|
||||||
prog.end()
|
|
||||||
|
|
||||||
if not SceneInserter(context=context, lib=lib, top_cell=top_cell_name)(prog):
|
if not SceneInserter(context=context, lib=lib, top_cell=top_cell_name)(prog):
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user