blender: relocate importing code into operator
This commit is contained in:
parent
ed79a6f129
commit
23522c6231
26
__init__.py
26
__init__.py
@ -12,7 +12,9 @@ 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
|
||||||
|
|
||||||
from bpy.props import (
|
from bpy.props import (
|
||||||
@ -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",
|
||||||
@ -113,20 +117,32 @@ class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
|
|||||||
if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
|
if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
|
||||||
import os
|
import os
|
||||||
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
|
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
|
||||||
|
|
||||||
|
# do the file import
|
||||||
|
progressCounter = import_gds.Progressor(context.window_manager)
|
||||||
|
|
||||||
result= import_gds.load(context, **keywords)
|
try:
|
||||||
|
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"])
|
||||||
|
|
||||||
# properly report errors to user in ui
|
if not sceneInserter(progressCounter):
|
||||||
if len(result) != 0 and "CANCELLED" in result:
|
|
||||||
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user