]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/operators.py
Redesign progress and error reporting in the Blender exporter
[libs/gl.git] / blender / io_mspgl / operators.py
index 920f025141cde05add6a40631a902b6777de511e..3741358406bad0cbf67ac12f4825220bbc5d9d82 100644 (file)
@@ -19,6 +19,7 @@ class ExportMspGLData(bpy.types.Operator):
        filepath: bpy.props.StringProperty(name="File path", description="File path for exporting the data", subtype='FILE_PATH')
        collection: bpy.props.BoolProperty(name="As a collection", description="Export all data as a single collection file", default=False)
        shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
+       debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
 
        @classmethod
        def poll(cls, context):
@@ -34,9 +35,12 @@ class ExportMspGLData(bpy.types.Operator):
                return {'RUNNING_MODAL'}
 
        def execute(self, context):
+               from .context import ExportContext
                from .export import DataExporter
+
+               ex_ctx = ExportContext(context, verbose=self.debug_mode)
                exporter = DataExporter()
-               exporter.export_to_file(context, self.filepath,
+               ex_ctx.export(exporter.export_to_file, self.filepath,
                        collection=self.collection,
                        shared_resources=self.shared_resources)
                return {'FINISHED'}
@@ -47,6 +51,11 @@ class ExportMspGLData(bpy.types.Operator):
                col.prop(self, "collection")
                col.prop(self, "shared_resources")
 
+               self.layout.separator()
+
+               col = self.layout.column()
+               col.prop(self, "debug_mode")
+
 class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
        bl_idname = "export.mspgl_animation"
        bl_label = "Export Msp GL animation"
@@ -57,6 +66,7 @@ class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
        export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
        collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
        looping_threshold: bpy.props.FloatProperty(name="Looping threshold", description="Tolerance for curve beginning and end values for looping", min=0.0, soft_max=1.0, precision=4, default=0.001)
+       debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
 
        def check(self, context):
                ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
@@ -64,9 +74,12 @@ class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
                return ext_changed or super_result
 
        def execute(self, context):
+               from .context import ExportContext
                from .export_animation import AnimationExporter
+
+               ex_ctx = ExportContext(context, verbose=self.debug_mode)
                exporter = AnimationExporter()
-               exporter.export_to_file(context, self.filepath,
+               ex_ctx.export(exporter.export_to_file, self.filepath,
                        export_all=self.export_all,
                        collection=self.collection,
                        looping_threshold=looping_threshold)
@@ -79,6 +92,11 @@ class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
                        col.prop(self, "collection")
                col.prop(self, "looping_threshold")
 
+               self.layout.separator()
+
+               col = self.layout.column()
+               col.prop(self, "debug_mode")
+
 class ExportMspGLScene(bpy.types.Operator, ExportHelper):
        bl_idname = "export_scene.mspgl_scene"
        bl_label = "Export Msp GL scene"
@@ -90,6 +108,7 @@ class ExportMspGLScene(bpy.types.Operator, ExportHelper):
        visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
        collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
        skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
+       debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
 
        def invoke(self, context, event):
                self.filepath = context.scene.name+".scene"
@@ -101,9 +120,12 @@ class ExportMspGLScene(bpy.types.Operator, ExportHelper):
                return ext_changed or super_result
 
        def execute(self, context):
+               from .context import ExportContext
                from .export_scene import SceneExporter
+
+               ex_ctx = ExportContext(context, verbose=self.debug_mode)
                exporter = SceneExporter()
-               exporter.export_to_file(context, self.filepath,
+               ex_ctx.export(exporter.export_to_file, self.filepath,
                        selected_only=self.selected_only,
                        visible_only=self.visible_only,
                        collection=self.collection,
@@ -118,12 +140,18 @@ class ExportMspGLScene(bpy.types.Operator, ExportHelper):
                if self.collection:
                        col.prop(self, "skip_existing")
 
+               self.layout.separator()
+
+               col = self.layout.column()
+               col.prop(self, "debug_mode")
+
 class ExportMspGLProject(bpy.types.Operator):
        bl_idname = "export.mspgl_project"
        bl_label = "Export Msp GL project"
        bl_description = "Export the entire project in Msp GL format"
 
        directory: bpy.props.StringProperty(name="Directory", description="Directory for exporting the data", subtype='FILE_PATH')
+       debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
 
        def invoke(self, context, event):
                blend_filepath = context.blend_data.filepath
@@ -133,11 +161,18 @@ class ExportMspGLProject(bpy.types.Operator):
                return {'RUNNING_MODAL'}
 
        def execute(self, context):
+               from .context import ExportContext
                from .export import ProjectExporter
+
+               ex_ctx = ExportContext(context, verbose=self.debug_mode)
                exporter = ProjectExporter()
-               exporter.export_to_directory(context, self.directory)
+               ex_ctx.export(exporter.export_to_directory, self.directory)
                return {'FINISHED'}
 
+       def draw(self, context):
+               col = self.layout.column()
+               col.prop(self, "debug_mode")
+
 class AddRenderMethod(bpy.types.Operator):
        bl_idname = "material.add_render_method"
        bl_label = "Add Render Method"