From 22a892f4024db7da71ccdced00bf494c28443510 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 Dec 2009 16:11:11 +0000 Subject: - make ToolSettings.mesh_selection_mode into an array of 3 bools rather then an enum since multiple can be set at once. - ToolSettings had its id.data set to NULL when taken directly from the context (causing a crash in cases) - menu for changing vert/edge/face selection now a python menu, removed operator. - wm.context_set_value(), would really prefer not to have this since it evaluates the value as a python expression however there are no ways to define arrays in PyOperators --- release/scripts/op/mesh_skin.py | 11 +++--- release/scripts/op/wm.py | 38 +++++++++++++++++--- release/scripts/ui/space_view3d.py | 23 ++++++++++++ source/blender/editors/mesh/editmesh_mods.c | 51 --------------------------- source/blender/editors/mesh/mesh_intern.h | 1 - source/blender/editors/mesh/mesh_ops.c | 3 +- source/blender/makesrna/RNA_types.h | 7 +++- source/blender/makesrna/intern/rna_context.c | 1 + source/blender/makesrna/intern/rna_internal.h | 3 ++ source/blender/makesrna/intern/rna_scene.c | 48 ++++++++++++++++++++++--- 10 files changed, 117 insertions(+), 69 deletions(-) diff --git a/release/scripts/op/mesh_skin.py b/release/scripts/op/mesh_skin.py index 436cd21c9ee..a78da39c5d4 100644 --- a/release/scripts/op/mesh_skin.py +++ b/release/scripts/op/mesh_skin.py @@ -249,17 +249,16 @@ def mesh_faces_extend(me, faces, mat_idx = 0): def getSelectedEdges(context, me, ob): - MESH_MODE= context.scene.tool_settings.mesh_selection_mode + MESH_MODE = tuple(context.tool_settings.mesh_selection_mode) + context.tool_settings.mesh_selection_mode = False, True, False - if MESH_MODE in ('EDGE', 'VERTEX'): - context.scene.tool_settings.mesh_selection_mode = 'EDGE' + if not MESH_MODE[2]: edges= [ ed for ed in me.edges if ed.selected ] # print len(edges), len(me.edges) context.scene.tool_settings.mesh_selection_mode = MESH_MODE return edges - if MESH_MODE == 'FACE': - context.scene.tool_settings.mesh_selection_mode = 'EDGE' + else: # value is [edge, face_sel_user_in] edge_dict= dict((ed.key, [ed, 0]) for ed in me.edges) @@ -268,7 +267,7 @@ def getSelectedEdges(context, me, ob): for edkey in f.edge_keys: edge_dict[edkey][1] += 1 - context.scene.tool_settings.mesh_selection_mode = MESH_MODE + context.tool_settings.mesh_selection_mode = MESH_MODE return [ ed_data[0] for ed_data in edge_dict.values() if ed_data[1] == 1 ] diff --git a/release/scripts/op/wm.py b/release/scripts/op/wm.py index 5069d206a3f..45a9e91d2c6 100644 --- a/release/scripts/op/wm.py +++ b/release/scripts/op/wm.py @@ -68,7 +68,8 @@ def execute_context_assign(self, context): class WM_OT_context_set_boolean(bpy.types.Operator): '''Set a context value.''' bl_idname = "wm.context_set_boolean" - bl_label = "Context Set" + bl_label = "Context Set Boolean" + bl_undo = True path = rna_path_prop value = BoolProperty(name="Value", @@ -81,6 +82,7 @@ class WM_OT_context_set_int(bpy.types.Operator): # same as enum '''Set a context value.''' bl_idname = "wm.context_set_int" bl_label = "Context Set" + bl_undo = True path = rna_path_prop value = IntProperty(name="Value", description="Assign value", default=0) @@ -91,7 +93,8 @@ class WM_OT_context_set_int(bpy.types.Operator): # same as enum class WM_OT_context_set_float(bpy.types.Operator): # same as enum '''Set a context value.''' bl_idname = "wm.context_set_float" - bl_label = "Context Set" + bl_label = "Context Set Float" + bl_undo = True path = rna_path_prop value = FloatProperty(name="Value", @@ -103,7 +106,8 @@ class WM_OT_context_set_float(bpy.types.Operator): # same as enum class WM_OT_context_set_string(bpy.types.Operator): # same as enum '''Set a context value.''' bl_idname = "wm.context_set_string" - bl_label = "Context Set" + bl_label = "Context Set String" + bl_undo = True path = rna_path_prop value = StringProperty(name="Value", @@ -115,7 +119,8 @@ class WM_OT_context_set_string(bpy.types.Operator): # same as enum class WM_OT_context_set_enum(bpy.types.Operator): '''Set a context value.''' bl_idname = "wm.context_set_enum" - bl_label = "Context Set" + bl_label = "Context Set Enum" + bl_undo = True path = rna_path_prop value = StringProperty(name="Value", @@ -125,10 +130,30 @@ class WM_OT_context_set_enum(bpy.types.Operator): execute = execute_context_assign +class WM_OT_context_set_value(bpy.types.Operator): + '''Set a context value.''' + bl_idname = "wm.context_set_value" + bl_label = "Context Set Value" + bl_undo = True + + path = rna_path_prop + value = StringProperty(name="Value", + description="Assignment value (as a string)", + maxlen=1024, default="") + + def execute(self, context): + if context_path_validate(context, self.properties.path) is Ellipsis: + return ('PASS_THROUGH',) + exec("context.%s=%s" % (self.properties.path, self.properties.value)) + return ('FINISHED',) + + class WM_OT_context_toggle(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_toggle" bl_label = "Context Toggle" + bl_undo = True + path = rna_path_prop def execute(self, context): @@ -146,6 +171,7 @@ class WM_OT_context_toggle_enum(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_toggle_enum" bl_label = "Context Toggle Values" + bl_undo = True path = rna_path_prop value_1 = StringProperty(name="Value", \ @@ -172,6 +198,8 @@ class WM_OT_context_cycle_int(bpy.types.Operator): vertex keys, groups' etc.''' bl_idname = "wm.context_cycle_int" bl_label = "Context Int Cycle" + bl_undo = True + path = rna_path_prop reverse = rna_reverse_prop @@ -203,6 +231,7 @@ class WM_OT_context_cycle_enum(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_cycle_enum" bl_label = "Context Enum Cycle" + bl_undo = True path = rna_path_prop reverse = rna_reverse_prop @@ -384,6 +413,7 @@ bpy.ops.add(WM_OT_context_set_int) bpy.ops.add(WM_OT_context_set_float) bpy.ops.add(WM_OT_context_set_string) bpy.ops.add(WM_OT_context_set_enum) +bpy.ops.add(WM_OT_context_set_value) bpy.ops.add(WM_OT_context_toggle) bpy.ops.add(WM_OT_context_toggle_enum) bpy.ops.add(WM_OT_context_cycle_enum) diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index fa0a6a8c5fa..2ec0e44e184 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -1121,6 +1121,28 @@ class VIEW3D_MT_edit_mesh_specials(bpy.types.Menu): layout.operator("mesh.select_vertex_path") +class VIEW3D_MT_edit_mesh_selection_mode(bpy.types.Menu): + bl_label = "Mesh Select Mode" + + def draw(self, context): + layout = self.layout + + layout.operator_context = 'INVOKE_REGION_WIN' + path = "tool_settings.edit_select_vertex;tool_settings.edit_select_edge;tool_settings.edit_select_face" + + prop = layout.operator("wm.context_set_value", text="Vertex") + prop.value = "(True, False, False)" + prop.path = "tool_settings.mesh_selection_mode" + + prop = layout.operator("wm.context_set_value", text="Edge") + prop.value = "(False, True, False)" + prop.path = "tool_settings.mesh_selection_mode" + + prop = layout.operator("wm.context_set_value", text="Face") + prop.value = "(False, False, True)" + prop.path = "tool_settings.mesh_selection_mode" + + class VIEW3D_MT_edit_mesh_vertices(bpy.types.Menu): bl_label = "Vertices" @@ -1915,6 +1937,7 @@ bpy.types.register(VIEW3D_MT_pose_showhide) bpy.types.register(VIEW3D_MT_edit_mesh) bpy.types.register(VIEW3D_MT_edit_mesh_specials) # Only as a menu for keybindings +bpy.types.register(VIEW3D_MT_edit_mesh_selection_mode) # Only as a menu for keybindings bpy.types.register(VIEW3D_MT_edit_mesh_vertices) bpy.types.register(VIEW3D_MT_edit_mesh_edges) bpy.types.register(VIEW3D_MT_edit_mesh_faces) diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 0fa6ff0188c..d1dde75771d 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -3682,57 +3682,6 @@ void EM_deselect_by_material(EditMesh *em, int index) EM_selectmode_flush(em); } -static void mesh_selection_type(ToolSettings *ts, EditMesh *em, int val) -{ - if(val>0) { - //if(ctrl) EM_convertsel(em, em->selectmode, SCE_SELECT_EDGE); - //if((ctrl)) EM_convertsel(em, em->selectmode, SCE_SELECT_FACE); - - em->selectmode= val; - EM_selectmode_set(em); - - /* note, em stores selectmode to be able to pass it on everywhere without scene, - this is only until all select modes and toolsettings are settled more */ - ts->selectmode= em->selectmode; -// if (EM_texFaceCheck()) - } -} - -static int mesh_selection_type_exec(bContext *C, wmOperator *op) -{ - ToolSettings *ts= CTX_data_tool_settings(C); - Object *obedit= CTX_data_edit_object(C); - EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); - - mesh_selection_type(ts, em, RNA_enum_get(op->ptr,"type")); - - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); - WM_event_add_notifier(C, NC_SCENE|ND_MODE, NULL); /* header redraw */ - - BKE_mesh_end_editmesh(obedit->data, em); - return OPERATOR_FINISHED; -} - -void MESH_OT_selection_type(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Selection Mode"; - ot->description= "Set the selection mode type."; - ot->idname= "MESH_OT_selection_type"; - - /* api callbacks */ - ot->invoke= WM_menu_invoke; - ot->exec= mesh_selection_type_exec; - - ot->poll= ED_operator_editmesh; - - /* flags */ - ot->flag= OPTYPE_UNDO; - - /* props */ - RNA_def_enum(ot->srna, "type", mesh_select_mode_items, 0, "Type", "Set the mesh selection type"); - -} /* ************************* SEAMS AND EDGES **************** */ static int editmesh_mark_seam(bContext *C, wmOperator *op) diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 5d9da374f2f..7b7257ae9cb 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -158,7 +158,6 @@ void MESH_OT_edges_select_sharp(struct wmOperatorType *ot); void MESH_OT_select_shortest_path(struct wmOperatorType *ot); void MESH_OT_select_similar(struct wmOperatorType *ot); void MESH_OT_select_random(struct wmOperatorType *ot); -void MESH_OT_selection_type(struct wmOperatorType *ot); void MESH_OT_loop_multi_select(struct wmOperatorType *ot); void MESH_OT_mark_seam(struct wmOperatorType *ot); void MESH_OT_mark_sharp(struct wmOperatorType *ot); diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 621e952fb6d..af25dbda16b 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -76,7 +76,6 @@ void ED_operatortypes_mesh(void) WM_operatortype_append(MESH_OT_select_linked); WM_operatortype_append(MESH_OT_select_linked_pick); WM_operatortype_append(MESH_OT_select_random); - WM_operatortype_append(MESH_OT_selection_type); WM_operatortype_append(MESH_OT_hide); WM_operatortype_append(MESH_OT_reveal); WM_operatortype_append(MESH_OT_select_by_number_vertices); @@ -240,7 +239,7 @@ void ED_keymap_mesh(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MESH_OT_select_similar", GKEY, KM_PRESS, KM_SHIFT, 0); /* selection mode */ - WM_keymap_add_item(keymap, "MESH_OT_selection_type", TABKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_menu(keymap, "VIEW3D_MT_edit_mesh_selection_mode", TABKEY, KM_PRESS, KM_CTRL, 0); /* hide */ WM_keymap_add_item(keymap, "MESH_OT_hide", HKEY, KM_PRESS, 0, 0); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index e771b495b96..90603f98c7a 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -164,7 +164,12 @@ typedef enum PropertyFlag { PROP_ID_SELF_CHECK = 1<<20, PROP_NEVER_NULL = 1<<18, - /* flag contains multiple enums */ + /* flag contains multiple enums. + * note: not to be confused with prop->enumbitflags + * this exposes the flag as multiple options in python and the UI. + * + * note: these can't be animated so use with care. + */ PROP_ENUM_FLAG = 1<<21, /* need context for update function */ diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c index 7239fc1ff3d..70d61b15d9f 100644 --- a/source/blender/makesrna/intern/rna_context.c +++ b/source/blender/makesrna/intern/rna_context.c @@ -100,6 +100,7 @@ static PointerRNA rna_Context_scene_get(PointerRNA *ptr) static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; + ptr->id.data= CTX_data_scene(C); return rna_pointer_inherit_refine(ptr, &RNA_ToolSettings, CTX_data_tool_settings(C)); } diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 1c14d0d4c06..5bb3c82395d 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -75,6 +75,9 @@ typedef struct PropertyDefRNA { int dnalengthfixed; int booleanbit, booleannegative; + + /* not to be confused with PROP_ENUM_FLAG + * this only allows one of the flags to be set at a time, clearing all others */ int enumbitflags; } PropertyDefRNA; diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index e4df352bcc8..ba389f66438 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -72,6 +72,7 @@ EnumPropertyItem proportional_editing_items[] = { {PROP_EDIT_CONNECTED, "CONNECTED", ICON_PROP_CON, "Connected", ""}, {0, NULL, 0, NULL, NULL}}; +/* keep for operators, not used here */ EnumPropertyItem mesh_select_mode_items[] = { {SCE_SELECT_VERTEX, "VERTEX", ICON_VERTEXSEL, "Vertex", "Vertex selection mode."}, {SCE_SELECT_EDGE, "EDGE", ICON_EDGESEL, "Edge", "Edge selection mode."}, @@ -91,6 +92,7 @@ EnumPropertyItem snap_element_items[] = { #include "DNA_anim_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" +#include "DNA_mesh_types.h" #include "BKE_context.h" #include "BKE_global.h" @@ -99,13 +101,18 @@ EnumPropertyItem snap_element_items[] = { #include "BKE_pointcache.h" #include "BKE_scene.h" #include "BKE_depsgraph.h" +#include "BKE_mesh.h" #include "BLI_threads.h" +#include "BLI_editVert.h" + +#include "WM_api.h" #include "ED_info.h" #include "ED_node.h" #include "ED_view3d.h" #include "ED_object.h" +#include "ED_mesh.h" #include "RE_pipeline.h" @@ -562,6 +569,38 @@ static void rna_Physics_update(Main *bmain, Scene *unused, PointerRNA *ptr) for(base = scene->base.first; base; base=base->next) BKE_ptcache_object_reset(scene, base->object, PTCACHE_RESET_DEPSGRAPH); } + +static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const int *value) +{ + Scene *scene= (Scene*)ptr->id.data; + ToolSettings *ts = (ToolSettings*)ptr->data; + int flag = (value[0] ? SCE_SELECT_VERTEX:0) | (value[1] ? SCE_SELECT_EDGE:0) | (value[2] ? SCE_SELECT_FACE:0); + + ts->selectmode = flag; + + if(scene->basact) { + Mesh *me= get_mesh(scene->basact->object); + if(me && me->edit_mesh && me->edit_mesh->selectmode != flag) { + me->edit_mesh->selectmode= flag; + EM_selectmode_set(me->edit_mesh); + } + } +} + +static void rna_Scene_editmesh_select_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Mesh *me= NULL; + + if(scene->basact) { + me= get_mesh(scene->basact->object); + if(me && me->edit_mesh==NULL) + me= NULL; + } + + WM_main_add_notifier(NC_GEOM|ND_SELECT, me); + WM_main_add_notifier(NC_SCENE|ND_MODE, NULL); /* header redraw */ +} + #else static void rna_def_transform_orientation(BlenderRNA *brna) @@ -736,10 +775,11 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, NULL); /* Mesh */ - prop= RNA_def_property(srna, "mesh_selection_mode", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_bitflag_sdna(prop, NULL, "selectmode"); - RNA_def_property_enum_items(prop, mesh_select_mode_items); - RNA_def_property_ui_text(prop, "Mesh Selection Mode", "Mesh selection and display mode."); + prop= RNA_def_property(srna, "mesh_selection_mode", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "selectmode", 1); + RNA_def_property_array(prop, 3); + RNA_def_property_boolean_funcs(prop, NULL, "rna_Scene_editmesh_select_mode_set"); + RNA_def_property_update(prop, 0, "rna_Scene_editmesh_select_mode_update"); prop= RNA_def_property(srna, "vertex_group_weight", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "vgroup_weight"); -- cgit v1.2.3