[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22501] branches/blender2.5/blender/source /blender: 2.5/Modes:
Nicholas Bishop
nicholasbishop at gmail.com
Sun Aug 16 07:48:07 CEST 2009
Revision: 22501
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22501
Author: nicholasbishop
Date: 2009-08-16 07:48:07 +0200 (Sun, 16 Aug 2009)
Log Message:
-----------
2.5/Modes:
* 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 :)
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/object/object_edit.c
branches/blender2.5/blender/source/blender/editors/object/object_intern.h
branches/blender2.5/blender/source/blender/editors/object/object_ops.c
branches/blender2.5/blender/source/blender/makesrna/RNA_enum_types.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
Modified: branches/blender2.5/blender/source/blender/editors/object/object_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/object_edit.c 2009-08-16 04:59:11 UTC (rev 22500)
+++ branches/blender2.5/blender/source/blender/editors/object/object_edit.c 2009-08-16 05:48:07 UTC (rev 22501)
@@ -127,6 +127,7 @@
#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 @@
}
}
+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)
Modified: branches/blender2.5/blender/source/blender/editors/object/object_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/object_intern.h 2009-08-16 04:59:11 UTC (rev 22500)
+++ branches/blender2.5/blender/source/blender/editors/object/object_intern.h 2009-08-16 05:48:07 UTC (rev 22501)
@@ -39,6 +39,7 @@
/* 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);
Modified: branches/blender2.5/blender/source/blender/editors/object/object_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/object/object_ops.c 2009-08-16 04:59:11 UTC (rev 22500)
+++ branches/blender2.5/blender/source/blender/editors/object/object_ops.c 2009-08-16 05:48:07 UTC (rev 22501)
@@ -65,6 +65,7 @@
{
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);
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_enum_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_enum_types.h 2009-08-16 04:59:11 UTC (rev 22500)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_enum_types.h 2009-08-16 05:48:07 UTC (rev 22501)
@@ -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[];
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c 2009-08-16 04:59:11 UTC (rev 22500)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_object.c 2009-08-16 05:48:07 UTC (rev 22501)
@@ -41,6 +41,18 @@
#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 @@
{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 @@
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);
More information about the Bf-blender-cvs
mailing list