Spelling Cleanup
[blender.git] / source / blender / editors / physics / dynamicpaint_ops.c
index 888b5af01bbf3f759769f9ac85de780472ee69f8..7f5688338668d15ee4f2b56bdd92c6a4c5c840ef 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_string.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_dynamicpaint_types.h"
 #include "DNA_modifier_types.h"
 
 #include "ED_mesh.h"
 #include "ED_screen.h"
+#include "ED_object.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 
-/* Platform independend time   */
 #include "PIL_time.h"
 
 #include "WM_types.h"
 #include "WM_api.h"
 
-static int surface_slot_add_exec(bContext *C, wmOperator *op)
+#include "physics_intern.h" /* own include */
+
+static int surface_slot_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       DynamicPaintModifierData *pmd = 0;
-       Object *cObject = CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       DynamicPaintModifierData *pmd = NULL;
+       Object *cObject = ED_object_context(C);
        DynamicPaintCanvasSettings *canvas;
        DynamicPaintSurface *surface;
 
@@ -94,10 +97,10 @@ void DPAINT_OT_surface_slot_add(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int surface_slot_remove_exec(bContext *C, wmOperator *op)
+static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       DynamicPaintModifierData *pmd = 0;
-       Object *cObject = CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       DynamicPaintModifierData *pmd = NULL;
+       Object *cObject = ED_object_context(C);
        DynamicPaintCanvasSettings *canvas;
        DynamicPaintSurface *surface;
        int id=0;
@@ -145,7 +148,7 @@ void DPAINT_OT_surface_slot_remove(wmOperatorType *ot)
 static int type_toggle_exec(bContext *C, wmOperator *op)
 {
 
-       Object *cObject = CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       Object *cObject = ED_object_context(C);
        Scene *scene = CTX_data_scene(C);
        DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint);
        int type= RNA_enum_get(op->ptr, "type");
@@ -165,7 +168,7 @@ static int type_toggle_exec(bContext *C, wmOperator *op)
                        return OPERATOR_CANCELLED;
        }
        
-       /* update dependancy */
+       /* update dependency */
        DAG_id_tag_update(&cObject->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, cObject);
        DAG_scene_sort(CTX_data_main(C), scene);
@@ -180,7 +183,7 @@ void DPAINT_OT_type_toggle(wmOperatorType *ot)
        /* identifiers */
        ot->name= "Toggle Type Active";
        ot->idname= "DPAINT_OT_type_toggle";
-       ot->description = "Toggles whether given type is active or not";
+       ot->description = "Toggle whether given type is active or not";
        
        /* api callbacks */
        ot->exec= type_toggle_exec;
@@ -196,24 +199,23 @@ void DPAINT_OT_type_toggle(wmOperatorType *ot)
 
 static int output_toggle_exec(bContext *C, wmOperator *op)
 {
-
-       Object *ob = CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       Object *ob = ED_object_context(C);
        Scene *scene = CTX_data_scene(C);
        DynamicPaintSurface *surface;
        DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint);
-       int index= RNA_int_get(op->ptr, "index");
+       int output= RNA_enum_get(op->ptr, "output"); /* currently only 1/0 */
 
        if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED;
        surface = get_activeSurface(pmd->canvas);
 
        /* if type is already enabled, toggle it off */
        if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
-               int exists = dynamicPaint_outputLayerExists(surface, ob, index);
-               char *name;
+               int exists = dynamicPaint_outputLayerExists(surface, ob, output);
+               const char *name;
                
-               if (index == 0)
+               if (output == 0)
                        name = surface->output_name;
-               else if (index == 1)
+               else
                        name = surface->output_name2;
 
                /* Vertex Color Layer */
@@ -225,8 +227,9 @@ static int output_toggle_exec(bContext *C, wmOperator *op)
                }
                /* Vertex Weight Layer */
                else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
-                       if (!exists)
+                       if (!exists) {
                                ED_vgroup_add_name(ob, name);
+                       }
                        else {
                                bDeformGroup *defgroup = defgroup_find_name(ob, name);
                                if (defgroup) ED_vgroup_delete(ob, defgroup);
@@ -239,12 +242,16 @@ static int output_toggle_exec(bContext *C, wmOperator *op)
 
 void DPAINT_OT_output_toggle(wmOperatorType *ot)
 {
-       PropertyRNA *prop;
+       static EnumPropertyItem prop_output_toggle_types[] = {
+               {0, "A", 0, "Output A", ""},
+               {1, "B", 0, "Output B", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
 
        /* identifiers */
        ot->name= "Toggle Output Layer";
        ot->idname= "DPAINT_OT_output_toggle";
-       ot->description = "Adds or removes Dynamic Paint output data layer";
+       ot->description = "Add or remove Dynamic Paint output data layer";
        
        /* api callbacks */
        ot->exec= output_toggle_exec;
@@ -254,8 +261,7 @@ void DPAINT_OT_output_toggle(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       prop= RNA_def_int(ot->srna, "index", 0, 0, 1, "Index", "", 0, 1);
-       ot->prop= prop;
+       ot->prop= RNA_def_enum(ot->srna, "output", prop_output_toggle_types, 0, "Output Toggle", "");
 }
 
 
@@ -306,22 +312,22 @@ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surf
                */
                {
                        char filename[FILE_MAX];
-                       /* make sure output path has ending slash */
-                       BLI_add_slash(surface->image_output_path);
 
                        /* primary output layer */
                        if (surface->flags & MOD_DPAINT_OUT1) {
                                /* set filepath */
-                               BLI_snprintf(filename, sizeof(filename), "%s%s", surface->image_output_path, surface->output_name);
+                               BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name);
                                BLI_path_frame(filename, frame, 4);
+
                                /* save image */
                                dynamicPaint_outputSurfaceImage(surface, filename, 0);
                        }
                        /* secondary output */
                        if (surface->flags & MOD_DPAINT_OUT2 && surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
                                /* set filepath */
-                               BLI_snprintf(filename, sizeof(filename), "%s%s", surface->image_output_path, surface->output_name2);
+                               BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name2);
                                BLI_path_frame(filename, frame, 4);
+
                                /* save image */
                                dynamicPaint_outputSurfaceImage(surface, filename, 1);
                        }
@@ -332,13 +338,13 @@ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surf
 
 
 /*
-*      Bake Dynamic Paint image sequence surface
-*/
-int dynamicPaint_initBake(struct bContext *C, struct wmOperator *op)
+ * Bake Dynamic Paint image sequence surface
+ */
+static int dynamicPaint_initBake(struct bContext *C, struct wmOperator *op)
 {
        DynamicPaintModifierData *pmd = NULL;
        DynamicPaintCanvasSettings *canvas;
-       Object *ob = CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       Object *ob = ED_object_context(C);
        int status = 0;
        double timer = PIL_check_seconds_timer();
        char result_str[80];
@@ -418,4 +424,4 @@ void DPAINT_OT_bake(wmOperatorType *ot)
        /* api callbacks */
        ot->exec= dynamicpaint_bake_exec;
        ot->poll= ED_operator_object_active_editable;
-}
\ No newline at end of file
+}