Merge from trunk -r 23968:24181.
[blender.git] / source / blender / windowmanager / intern / wm_operators.c
index f82e16b7951dbce7f626743d206b7a918080b856..3006f813d71eed84aea2f2f80cdb5617706fbdc2 100644 (file)
@@ -642,6 +642,7 @@ int WM_operator_redo_popup(bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
+
 /* ***************** Debug menu ************************* */
 
 static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
@@ -1345,6 +1346,105 @@ static void WM_OT_save_mainfile(wmOperatorType *ot)
 }
 
 
+/* XXX: move these collada operators to a more appropriate place */
+#ifdef WITH_COLLADA
+
+#include "../../collada/collada.h"
+
+static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       //char name[FILE_MAX];
+       //BLI_strncpy(name, G.sce, FILE_MAX);
+       //untitled(name);
+
+       /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
+       
+       WM_event_add_fileselect(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+/* function used for WM_OT_save_mainfile too */
+static int wm_collada_export_exec(bContext *C, wmOperator *op)
+{
+       char filename[FILE_MAX];
+       
+       if(RNA_property_is_set(op->ptr, "path"))
+               RNA_string_get(op->ptr, "path", filename);
+       else {
+               BLI_strncpy(filename, G.sce, FILE_MAX);
+               untitled(filename);
+       }
+       
+       //WM_write_file(C, filename, op->reports);
+       collada_export(CTX_data_scene(C), filename);
+       
+       /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
+
+       return OPERATOR_FINISHED;
+}
+
+static void WM_OT_collada_export(wmOperatorType *ot)
+{
+       ot->name= "Export COLLADA";
+       ot->idname= "WM_OT_collada_export";
+       
+       ot->invoke= wm_collada_export_invoke;
+       ot->exec= wm_collada_export_exec;
+       ot->poll= WM_operator_winactive;
+       
+       ot->flag= 0;
+       
+       RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
+}
+
+static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       /* RNA_string_set(op->ptr, "path", "/tmp/test.dae"); */
+       
+       WM_event_add_fileselect(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+/* function used for WM_OT_save_mainfile too */
+static int wm_collada_import_exec(bContext *C, wmOperator *op)
+{
+       char filename[FILE_MAX];
+       
+       if(RNA_property_is_set(op->ptr, "path"))
+               RNA_string_get(op->ptr, "path", filename);
+       else {
+               BLI_strncpy(filename, G.sce, FILE_MAX);
+               untitled(filename);
+       }
+       
+       //WM_write_file(C, filename, op->reports);
+       collada_import(C, filename);
+       
+       /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
+
+       return OPERATOR_FINISHED;
+}
+
+static void WM_OT_collada_import(wmOperatorType *ot)
+{
+       ot->name= "Import COLLADA";
+       ot->idname= "WM_OT_collada_import";
+       
+       ot->invoke= wm_collada_import_invoke;
+       ot->exec= wm_collada_import_exec;
+       ot->poll= WM_operator_winactive;
+       
+       ot->flag= 0;
+       
+       RNA_def_property(ot->srna, "path", PROP_STRING, PROP_FILEPATH);
+}
+
+#endif
+
+
+
 /* *********************** */
 
 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
@@ -2084,6 +2184,7 @@ void WM_OT_radial_control_partial(wmOperatorType *ot)
        RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
 }
 
+
 /* ************************** timer for testing ***************** */
 
 /* uses no type defines, fully local testing function anyway... ;) */
@@ -2247,6 +2348,13 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_memory_statistics);
        WM_operatortype_append(WM_OT_debug_menu);
        WM_operatortype_append(WM_OT_search_menu);
+
+#ifdef WITH_COLLADA
+       /* XXX: move these */
+       WM_operatortype_append(WM_OT_collada_export);
+       WM_operatortype_append(WM_OT_collada_import);
+#endif
+
        WM_operatortype_append(WM_OT_call_menu);
 }