blender: relocate importing code into operator

This commit is contained in:
Julian Daube 2019-07-04 21:22:20 +02:00
parent ed79a6f129
commit 23522c6231

View File

@ -12,6 +12,8 @@ if "bpy" in locals():
import importlib import importlib
if "import_gds" in locals(): if "import_gds" in locals():
importlib.reload(import_gds) importlib.reload(import_gds)
if "gds" in locals():
importlib.reload(gds)
import bpy import bpy
@ -21,6 +23,7 @@ from bpy.props import (
StringProperty, StringProperty,
EnumProperty, EnumProperty,
) )
from bpy_extras.io_utils import ( from bpy_extras.io_utils import (
ImportHelper, ImportHelper,
ExportHelper, ExportHelper,
@ -102,6 +105,7 @@ class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
def execute(self, context): def execute(self, context):
# print("Selected: " + context.active_object.name) # print("Selected: " + context.active_object.name)
from . import import_gds from . import import_gds
from . import gds
# ignore axis helper arguments # ignore axis helper arguments
keywords = self.as_keywords(ignore=("axis_forward", keywords = self.as_keywords(ignore=("axis_forward",
@ -114,19 +118,31 @@ class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
import os import os
keywords["relpath"] = os.path.dirname(bpy.data.filepath) keywords["relpath"] = os.path.dirname(bpy.data.filepath)
result= import_gds.load(context, **keywords) # do the file import
progressCounter = import_gds.Progressor(context.window_manager)
# properly report errors to user in ui try:
if len(result) != 0 and "CANCELLED" in result: with open(keywords["filepath"], "rb") as file:
lib = gds.parse_file(file, progressCounter)
except gds.ParserError as e:
self.report({"ERROR_INVALID_INPUT"}, "cannot parse given gds file: {}".format(e))
progressCounter.end()
sceneInserter = import_gds.SceneInserter(context, lib, top_cell=keywords["top_cell_name"])
if not sceneInserter(progressCounter):
self.report({"ERROR_INVALID_INPUT"}, "Could not find structure with name {}".format(keywords["top_cell_name"])) self.report({"ERROR_INVALID_INPUT"}, "Could not find structure with name {}".format(keywords["top_cell_name"]))
return {"CANCELLED"}
return {"FINISHED"}
return result
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
row = layout.row() row = layout.row()
row.prop(self, "top_cell_name") row.prop(self, "top_cell_name")
# row = layout.row(align=True) # row = layout.row(align=True)
# row.prop(self, "use_smooth_groups") # row.prop(self, "use_smooth_groups")
# row.prop(self, "use_edges") # row.prop(self, "use_edges")