blender-gdsimporter/__init__.py

179 lines
5.2 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)
import bpy
from bpy.props import (
BoolProperty,
FloatProperty,
StringProperty,
EnumProperty,
)
from bpy_extras.io_utils import (
ImportHelper,
ExportHelper,
orientation_helper_factory,
path_reference_mode,
axis_conversion,
)
IOOBJOrientationHelper = orientation_helper_factory("IOOBJOrientationHelper", axis_forward='-Z', axis_up='Y')
class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
"""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,
# )
top_cell_name = StringProperty(
name="Top Cell Name",
#descriptionn="When set, only import the structure with that name",
default="",
)
def execute(self, context):
# print("Selected: " + context.active_object.name)
from . import import_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)
result= import_gds.load(context, **keywords)
# properly report errors to user in ui
if len(result) != 0 and "CANCELLED" in result:
self.report({"ERROR_INVALID_INPUT"}, "Could not find structure with name {}".format(keywords["top_cell_name"]))
return result
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(self, "top_cell_name")
# 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()