blender-gdsimporter/gds/library.py

58 lines
1.6 KiB
Python
Raw Normal View History

from datetime import datetime
from .elements import SRef
from .reader import ProgressGetter
class Library(object):
version = 0
name = "NONAME"
last_access = datetime.now()
last_mod = datetime.now()
# unit setup
units_per_dbunit = 1
meters_per_unit = 1
structures = {}
class LinkError(Exception):
element = None
pass
def link_srefs(self, progress_callback=None):
class Progress(ProgressGetter):
total = 0
current = 0
def __init__(self, lib):
for key, value in lib.structures.items():
self.total += len(value.references)
def progress(self):
return float(self.current) / self.total
def inc(self):
self.current += 1
count = Progress(self)
for key, value in self.structures.items():
2019-07-01 14:21:45 +02:00
for element in value.references:
if isinstance(element.structure, str):
# try to resolve link
try:
ref = self.structures[element.structure]
element.structure = ref
except KeyError:
err = LinkError("dangeling sref (structure {} is not defined in library)".format(element.structure))
err.element = element
raise err
count.inc()
if progress_callback:
progress_callback(count)