2.5: Modifiers & Menus
[blender-staging.git] / source / blender / editors / object / object_edit.c
index de77b80a29a4890f738cc9e45b6972594eb59874..2fb9835f833b59365ec11e3c1a3adf34d6d4bdc0 100644 (file)
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 /* for menu/popup icons etc etc*/
 #include "UI_interface.h"
@@ -178,10 +179,6 @@ void ED_base_object_activate(bContext *C, Base *base)
        Scene *scene= CTX_data_scene(C);
        Base *tbase;
        
-       /* activating a non-mesh, should end a couple of modes... */
-       if(base && base->object->type!=OB_MESH)
-               ED_view3d_exit_paint_modes(C);
-       
        /* sets scene->basact */
        BASACT= base;
        
@@ -273,9 +270,6 @@ static Object *object_add_type(bContext *C, int type)
        Scene *scene= CTX_data_scene(C);
        Object *ob;
        
-       /* XXX hrms, this is editor level operator, remove? */
-       ED_view3d_exit_paint_modes(C);
-       
        /* for as long scene has editmode... */
        if (CTX_data_edit_object(C)) 
                ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
@@ -752,8 +746,6 @@ static int object_delete_exec(bContext *C, wmOperator *op)
        if(CTX_data_edit_object(C)) 
                return OPERATOR_CANCELLED;
        
-       ED_view3d_exit_paint_modes(C);
-
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
 
                if(base->object->type==OB_LAMP) islamp= 1;
@@ -1158,7 +1150,7 @@ void ED_object_apply_obmat(Object *ob)
        
 }
 
-int hook_getIndexArray(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
+int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
 {
        *indexar= NULL;
        *tot= 0;
@@ -1240,9 +1232,8 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
        }
 }
 
-void obedit_hook_select(Object *ob, HookModifierData *hmd) 
+void object_hook_select(Object *ob, HookModifierData *hmd) 
 {
-       
        if(ob->type==OB_MESH) select_editmesh_hook(ob, hmd);
        else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd);
        else if(ob->type==OB_CURVE) select_editcurve_hook(ob, hmd);
@@ -1326,7 +1317,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode)
                int tot, ok, *indexar;
                char name[32];
                
-               ok = hook_getIndexArray(obedit, &tot, &indexar, name, cent);
+               ok = object_hook_index_array(obedit, &tot, &indexar, name, cent);
                
                if(ok==0) {
                        error("Requires selected vertices or active Vertex Group");
@@ -1389,7 +1380,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode)
                modifier_free(md);
        }
        else if(mode==5) { /* select */
-               obedit_hook_select(obedit, hmd);
+               object_hook_select(obedit, hmd);
        }
        else if(mode==6) { /* clear offset */
                where_is_object(scene, ob);     /* ob is hook->parent */
@@ -3741,6 +3732,7 @@ void ED_object_exit_editmode(bContext *C, int flag)
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
        }
 
+       obedit->mode &= ~OB_MODE_EDIT;
        ED_object_toggle_modes(C, obedit->restore_mode);
 }
 
@@ -3776,8 +3768,9 @@ void ED_object_enter_editmode(bContext *C, int flag)
        if(flag & EM_WAITCURSOR) waitcursor(1);
 
        ob->restore_mode = ob->mode;
-       ED_view3d_exit_paint_modes(C);
        ED_object_toggle_modes(C, ob->mode);
+
+       ob->mode |= OB_MODE_EDIT;
        
        if(ob->type==OB_MESH) {
                Mesh *me= ob->data;
@@ -3865,6 +3858,16 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
+static int editmode_toggle_poll(bContext *C)
+{
+       Object *ob = CTX_data_active_object(C);
+
+       return ob && (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
+                     ob->type == OB_FONT || ob->type == OB_MBALL ||
+                     ob->type == OB_LATTICE || ob->type == OB_SURF ||
+                     ob->type == OB_CURVE);
+}
+
 void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
 {
        
@@ -3876,7 +3879,7 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
        /* api callbacks */
        ot->exec= editmode_toggle_exec;
        
-       ot->poll= ED_operator_object_active;
+       ot->poll= editmode_toggle_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3893,7 +3896,7 @@ static int posemode_exec(bContext *C, wmOperator *op)
                        ED_object_exit_editmode(C, EM_FREEDATA);
                        ED_armature_enter_posemode(C, base);
                }
-               else if(base->object->flag & OB_POSEMODE)
+               else if(base->object->mode & OB_MODE_POSE)
                        ED_armature_exit_posemode(C, base);
                else
                        ED_armature_enter_posemode(C, base);
@@ -4116,7 +4119,7 @@ void special_editmenu(Scene *scene, View3D *v3d)
        
        if(obedit==NULL) {
                
-               if(ob->flag & OB_POSEMODE) {
+               if(ob->mode & OB_MODE_POSE) {
 // XXX                 pose_special_editmenu();
                }
                else if(paint_facesel_test(ob)) {
@@ -4181,14 +4184,14 @@ void special_editmenu(Scene *scene, View3D *v3d)
                else if(ob->mode & OB_MODE_WEIGHT_PAINT) {
                        Object *par= modifiers_isDeformedByArmature(ob);
 
-                       if(par && (par->flag & OB_POSEMODE)) {
+                       if(par && (par->mode & OB_MODE_POSE)) {
                                nr= pupmenu("Specials%t|Apply Bone Envelopes to Vertex Groups %x1|Apply Bone Heat Weights to Vertex Groups %x2");
 
 // XXX                         if(nr==1 || nr==2)
 // XXX                                 pose_adds_vgroups(ob, (nr == 2));
                        }
                }
-               else if(G.f & G_PARTICLEEDIT) {
+               else if(ob->mode & OB_MODE_PARTICLE_EDIT) {
 #if 0
                        // XXX
                        ParticleSystem *psys = PE_get_current(ob);
@@ -6301,7 +6304,7 @@ static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag
        int a, didit;
 
        ob= base->object;
-       if(ob->flag & OB_POSEMODE) {
+       if(ob->mode & OB_MODE_POSE) {
                ; /* nothing? */
        }
        else {
@@ -7038,6 +7041,98 @@ void hookmenu(Scene *scene, View3D *v3d)
        }       
 }
 
+static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *ptr, int *free)
+{      
+       EnumPropertyItem *input = object_mode_items;
+       EnumPropertyItem *item= NULL;
+       Object *ob;
+       int totitem= 0;
+       
+       if(!C) /* needed for docs */
+               return object_mode_items;
+
+       ob = CTX_data_active_object(C);
+       while(ob && input->identifier) {
+               if((input->value == OB_MODE_EDIT && ((ob->type == OB_MESH) || (ob->type == OB_ARMATURE) ||
+                                                   (ob->type == OB_CURVE) || (ob->type == OB_SURF) ||
+                                                    (ob->type == OB_FONT) || (ob->type == OB_MBALL) || (ob->type == OB_LATTICE))) ||
+                  (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
+                  (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) ||
+                  ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT ||
+                    input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
+                  (input->value == OB_MODE_OBJECT))
+                       RNA_enum_item_add(&item, &totitem, input);
+               ++input;
+       }
+
+       RNA_enum_item_end(&item, &totitem);
+
+       *free= 1;
+
+       return item;
+}
+
+static const char *object_mode_op_string(int mode)
+{
+       if(mode == OB_MODE_EDIT)
+               return "OBJECT_OT_editmode_toggle";
+       if(mode == OB_MODE_SCULPT)
+               return "SCULPT_OT_sculptmode_toggle";
+       if(mode == OB_MODE_VERTEX_PAINT)
+               return "PAINT_OT_vertex_paint_toggle";
+       if(mode == OB_MODE_WEIGHT_PAINT)
+               return "PAINT_OT_weight_paint_toggle";
+       if(mode == OB_MODE_TEXTURE_PAINT)
+               return "PAINT_OT_texture_paint_toggle";
+       if(mode == OB_MODE_PARTICLE_EDIT)
+               return "PARTICLE_OT_particle_edit_toggle";
+       if(mode == OB_MODE_POSE)
+               return "OBJECT_OT_posemode_toggle";
+       return NULL;
+}
+
+static int object_mode_set_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_active_object(C);
+       int mode = RNA_enum_get(op->ptr, "mode");
+
+       if(!ob)
+               return OPERATOR_CANCELLED;
+
+       /* Exit off current mode */
+       if(ob->mode != OB_MODE_OBJECT)
+               WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL);
+
+       /* Enter new mode */
+       if(mode != OB_MODE_OBJECT)
+               WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_mode_set(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+
+       /* identifiers */
+       ot->name= "Set Object Mode";
+       ot->description = "Sets the object interaction mode.";
+       ot->idname= "OBJECT_OT_mode_set";
+       
+       /* api callbacks */
+       ot->exec= object_mode_set_exec;
+       
+       ot->poll= ED_operator_object_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       prop= RNA_def_enum(ot->srna, "mode", object_mode_items, 0, "Mode", "");
+       RNA_def_enum_funcs(prop, object_mode_set_itemsf);
+}
+
+
+
 void ED_object_toggle_modes(bContext *C, int mode)
 {
        if(mode & OB_MODE_SCULPT)
@@ -7046,4 +7141,8 @@ void ED_object_toggle_modes(bContext *C, int mode)
                WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
        if(mode & OB_MODE_WEIGHT_PAINT)
                WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if(mode & OB_MODE_TEXTURE_PAINT)
+               WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if(mode & OB_MODE_PARTICLE_EDIT)
+               WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
 }