2.5/Modes:
authorNicholas Bishop <nicholasbishop@gmail.com>
Sun, 16 Aug 2009 05:48:07 +0000 (05:48 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Sun, 16 Aug 2009 05:48:07 +0000 (05:48 +0000)
* Added OBJECT_OT_mode_set for setting the object mode. Takes one property, "mode", which can be any of the OB_MODE_* flags. The available modes are limited based on the active object (e.g. only meshes can have sculptmode, and so forth.)
* Set the icon properties in the object mode enum RNA

TODO:
At this point I think everything is ready to start ripping out the ugly hacks in view3d_header for setting the mode :)

source/blender/editors/object/object_edit.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_object.c

index 302c4c1bdce977eace6549e0d6c63bfc34a568f0..581b870d0b482110c737eaaa8a58915804346695 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"
@@ -7031,6 +7032,85 @@ 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 = CTX_data_active_object(C);
+       int totitem= 0;
+       
+       if(!C) /* needed for docs */
+               return object_mode_items;
+
+       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 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;
+
+       if((mode == OB_MODE_EDIT) == !(ob->mode & OB_MODE_EDIT))
+               WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if((mode == OB_MODE_SCULPT) == !(ob->mode & OB_MODE_SCULPT))
+               WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if((mode == OB_MODE_VERTEX_PAINT) == !(ob->mode & OB_MODE_VERTEX_PAINT))
+               WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if((mode == OB_MODE_WEIGHT_PAINT) == !(ob->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) == !(ob->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) == !(ob->mode & OB_MODE_PARTICLE_EDIT))
+               WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if((mode == OB_MODE_POSE) == !(ob->mode & OB_MODE_POSE))
+               WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", 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)
index 17d4f5deaae6540dd7a9ccab3bcdfce80e6f158f..e47087a3c27df8754526a1ecde15042815ec65b6 100644 (file)
@@ -39,6 +39,7 @@ struct Mesh;
 
 
 /* object_edit.c */
+void OBJECT_OT_mode_set(struct wmOperatorType *ot);
 void OBJECT_OT_editmode_toggle(struct wmOperatorType *ot);
 void OBJECT_OT_posemode_toggle(struct wmOperatorType *ot);
 void OBJECT_OT_parent_set(struct wmOperatorType *ot);
index c1509e7850277e54600d75cc3a81ddf0b9d5ec7c..f2e048284f4ceffb664319b4f48dacb773b9bf85 100644 (file)
@@ -65,6 +65,7 @@ void ED_operatortypes_object(void)
 {
        wmOperatorType *ot;
        
+       WM_operatortype_append(OBJECT_OT_mode_set);
        WM_operatortype_append(OBJECT_OT_editmode_toggle);
        WM_operatortype_append(OBJECT_OT_posemode_toggle);
        WM_operatortype_append(OBJECT_OT_parent_set);
index 78e65e8fc061f30c4f47557db6bf93398a9da427..a7488ed437bd146b1caa8de7c3a872d686157824 100644 (file)
@@ -29,6 +29,8 @@
 
 /* Types */
 
+extern EnumPropertyItem object_mode_items[];
+
 extern EnumPropertyItem prop_mode_items[];
 extern EnumPropertyItem space_type_items[];
 extern EnumPropertyItem region_type_items[];
index 105d08f237ff13bdabc92d4e2e9ff6f5b8ac3f87..2e40765935d9bc912107277f2f522be361049373 100644 (file)
 
 #include "WM_types.h"
 
+
+EnumPropertyItem object_mode_items[] = {
+       {OB_MODE_OBJECT, "OBJECT", ICON_OBJECT_DATAMODE, "Object", ""},
+       {OB_MODE_EDIT, "EDIT", ICON_EDITMODE_HLT, "Edit", ""},
+       {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
+       {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
+       {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
+       {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
+       {OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", ICON_PARTICLEMODE, "Particle Edit", ""},
+       {OB_MODE_POSE, "POSE", ICON_POSE_HLT, "Pose", ""},
+       {0, NULL, 0, NULL, NULL}};
+
 static EnumPropertyItem parent_type_items[] = {
        {PAROBJECT, "OBJECT", 0, "Object", ""},
        {PARCURVE, "CURVE", 0, "Curve", ""},
@@ -968,17 +980,6 @@ static void rna_def_object(BlenderRNA *brna)
                {OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
                {0, NULL, 0, NULL, NULL}};
 
-       static EnumPropertyItem mode_items[] = {
-               {OB_MODE_OBJECT, "OBJECT", 0, "Object", ""},
-               {OB_MODE_EDIT, "EDIT", 0, "Edit", ""},
-               {OB_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
-               {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", 0, "Vertex Paint", ""},
-               {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", 0, "Weight Paint", ""},
-               {OB_MODE_WEIGHT_PAINT, "TEXTURE_PAINT", 0, "Texture Paint", ""},
-               {OB_MODE_PARTICLE_EDIT, "PARTICLE_EDIT", 0, "Particle Edit", ""},
-               {OB_MODE_POSE, "POSE", 0, "Pose", ""},
-               {0, NULL, 0, NULL, NULL}};
-
        static EnumPropertyItem empty_drawtype_items[] = {
                {OB_ARROWS, "ARROWS", 0, "Arrows", ""},
                {OB_SINGLE_ARROW, "SINGLE_ARROW", 0, "Single Arrow", ""},
@@ -1049,7 +1050,8 @@ static void rna_def_object(BlenderRNA *brna)
 
        prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "mode");
-       RNA_def_property_enum_items(prop, mode_items);
+       RNA_def_property_enum_items(prop, object_mode_items);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Mode", "Object interaction mode.");
 
        prop= RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_NONE);