blender-gdsimporter/__init__.py

207 lines
6.0 KiB
Python

bl_info = {
"name": "gdsii OBJ format",
"author": "Julian Daube",
"version": (0, 9, 0),
"blender": (2, 78, 0),
"location": "File > Import-Export",
"description": "Import GdsII files",
"warning": "",
"category": "Import-Export"}
if "bpy" in locals():
import importlib
if "import_gds" in locals():
importlib.reload(import_gds)
if "gds" in locals():
importlib.reload(gds)
import bpy
from bpy.props import (
BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
)
from bpy_extras.io_utils import (
ImportHelper,
orientation_helper_factory,
path_reference_mode,
axis_conversion,
)
IGDSOrientationHelper = orientation_helper_factory("IGDSOrientationHelper", axis_forward='-Z', axis_up='Y')
class ImportGDS(bpy.types.Operator, ImportHelper, IGDSOrientationHelper):
"""Load a GDSII File"""
bl_idname = "import_scene.gds"
bl_label = "Import GDSII"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".obj"
filter_glob = StringProperty(
default="*.gds",
options={'HIDDEN'},
)
# use_edges = BoolProperty(
# name="Lines",
# description="Import lines and faces with 2 verts as edge",
# default=True,
# )
# use_smooth_groups = BoolProperty(
# name="Smooth Groups",
# description="Surround smooth groups by sharp edges",
# default=True,
# )
# use_split_objects = BoolProperty(
# name="Object",
# description="Import OBJ Objects into Blender Objects",
# default=True,
# )
# use_split_groups = BoolProperty(
# name="Group",
# description="Import OBJ Groups into Blender Objects",
# default=True,
# )
# use_groups_as_vgroups = BoolProperty(
# name="Poly Groups",
# description="Import OBJ groups as vertex groups",
# default=False,
# )
# use_image_search = BoolProperty(
# name="Image Search",
# description="Search subdirs for any associated images "
# "(Warning, may be slow)",
# default=True,
# )
# split_mode = EnumProperty(
# name="Split",
# items=(('ON', "Split", "Split geometry, omits unused verts"),
# ('OFF', "Keep Vert Order", "Keep vertex order from file"),
# ),
# )
# global_clamp_size = FloatProperty(
# name="Clamp Size",
# description="Clamp bounds under this value (zero to disable)",
# min=0.0, max=1000.0,
# soft_min=0.0, soft_max=1000.0,
# default=0.0,
# )
gds_file = StringProperty(
name="gds file",
subtype="FILE_PATH"
)
top_cell_name = StringProperty(
name="Top Cell Name",
#descriptionn="When set, only import the structure with that name",
default="",
)
layer_definition = StringProperty(
name="Layer Def",
#descriptionn="When set, only import the structure with that name",
subtype="FILE_PATH"
)
def execute(self, context):
# print("Selected: " + context.active_object.name)
from . import import_gds
from . import pygds as gds
# ignore axis helper arguments
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"filter_glob",
"split_mode",
))
if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
import os
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
# do the file import
progressCounter = import_gds.Progressor(context.window_manager)
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"])
if not sceneInserter(progressCounter):
self.report({"ERROR_INVALID_INPUT"}, "Could not find structure with name {}".format(keywords["top_cell_name"]))
return {"CANCELLED"}
return {"FINISHED"}
def draw(self, context):
layout = self.layout
box = layout.box()
box.row().prop(self, "gds_file")
box.row().prop(self, "top_cell_name")
row = layout.row()
row.prop(self, "layer_definition")
# row = layout.row(align=True)
# row.prop(self, "use_smooth_groups")
# row.prop(self, "use_edges")
# box = layout.box()
# row = box.row()
# row.prop(self, "split_mode", expand=True)
# row = box.row()
# if self.split_mode == 'ON':
# row.label(text="Split by:")
# row.prop(self, "use_split_objects")
# row.prop(self, "use_split_groups")
# else:
# row.prop(self, "use_groups_as_vgroups")
# row = layout.split(percentage=0.67)
# row.prop(self, "global_clamp_size")
# layout.prop(self, "axis_forward")
# layout.prop(self, "axis_up")
# layout.prop(self, "use_image_search")
def menu_func_import(self, context):
self.layout.operator(ImportGDS.bl_idname, text="GDSII Stream (.gds)")
classes = (
ImportGDS,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.INFO_MT_file_import.append(menu_func_import)
def unregister():
bpy.types.INFO_MT_file_import.remove(menu_func_import)
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()