Bugfix [#35936] Can't create new vertex group when using Ctrl G menu

This was caused by r.57812

There were two problems here:
  1) vertex_group_vert_select_unlocked_poll()  had faulty logic which meant that
it always failed when there were no vgroups present yet - the final return
always just fell through
  2) Since the "Assign to New Groups" option was actually implemented using the
same operator as "Assign to Active Group" (just with an extra parameter set), if
the active group was locked, it was not possible to "Assign to New Group" (even
though a new group would not be locked).
This commit is contained in:
Joshua Leung 2013-07-01 13:02:53 +00:00
parent 61d37cd47c
commit 4f3f95751a
5 changed files with 37 additions and 12 deletions

@ -215,7 +215,7 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
row = layout.row()
sub = row.row(align=True)
sub.operator("object.vertex_group_assign", text="Assign").new = False
sub.operator("object.vertex_group_assign", text="Assign")
sub.operator("object.vertex_group_remove_from", text="Remove")
sub = row.row(align=True)

@ -1312,13 +1312,13 @@ class VIEW3D_MT_vertex_group(Menu):
layout = self.layout
layout.operator_context = 'EXEC_AREA'
layout.operator("object.vertex_group_assign", text="Assign to New Group").new = True
layout.operator("object.vertex_group_assign_new")
ob = context.active_object
if ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex):
if ob.vertex_groups.active:
layout.separator()
layout.operator("object.vertex_group_assign", text="Assign to Active Group").new = False
layout.operator("object.vertex_group_assign", text="Assign to Active Group")
layout.operator("object.vertex_group_remove_from", text="Remove from Active Group").use_all_groups = False
layout.operator("object.vertex_group_remove_from", text="Remove from All").use_all_groups = True
layout.separator()

@ -203,6 +203,7 @@ void CONSTRAINT_OT_followpath_path_animate(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_add(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_remove(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_assign(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_assign_new(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_remove_from(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_select(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot);

@ -175,6 +175,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_vertex_group_add);
WM_operatortype_append(OBJECT_OT_vertex_group_remove);
WM_operatortype_append(OBJECT_OT_vertex_group_assign);
WM_operatortype_append(OBJECT_OT_vertex_group_assign_new);
WM_operatortype_append(OBJECT_OT_vertex_group_remove_from);
WM_operatortype_append(OBJECT_OT_vertex_group_select);
WM_operatortype_append(OBJECT_OT_vertex_group_deselect);

@ -2993,7 +2993,7 @@ static int vertex_group_vert_select_unlocked_poll(bContext *C)
return !(dg->flag & DG_LOCK_WEIGHT);
}
}
return 0;
return 1;
}
static int vertex_group_vert_select_mesh_poll(bContext *C)
@ -3080,10 +3080,7 @@ static int vertex_group_assign_exec(bContext *C, wmOperator *op)
{
ToolSettings *ts = CTX_data_tool_settings(C);
Object *ob = ED_object_context(C);
if (RNA_boolean_get(op->ptr, "new"))
ED_vgroup_add(ob);
vgroup_assign_verts(ob, ts->vgroup_weight);
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@ -3094,9 +3091,9 @@ static int vertex_group_assign_exec(bContext *C, wmOperator *op)
void OBJECT_OT_vertex_group_assign(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Assign Vertex Group";
ot->name = "Assign to Vertex Group";
ot->idname = "OBJECT_OT_vertex_group_assign";
ot->description = "Assign the selected vertices to the active (or a new) vertex group";
ot->description = "Assign the selected vertices to the active vertex group";
/* api callbacks */
ot->poll = vertex_group_vert_select_unlocked_poll;
@ -3107,9 +3104,35 @@ void OBJECT_OT_vertex_group_assign(wmOperatorType *ot)
* isn't stored in local edit mode stack and toggling "new" property will
* lead to creating plenty of new vertex groups (see [#29527], sergey) */
ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
}
/* properties */
RNA_def_boolean(ot->srna, "new", 0, "New", "Assign vertex to new vertex group");
/* NOTE: just a wrapper around vertex_group_assign_exec(), except we add these to a new group */
static int vertex_group_assign_new_exec(bContext *C, wmOperator *op)
{
/* create new group... */
Object *ob = ED_object_context(C);
ED_vgroup_add(ob);
/* assign selection to new group */
return vertex_group_assign_exec(C, op);
}
void OBJECT_OT_vertex_group_assign_new(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Assign to New Group";
ot->idname = "OBJECT_OT_vertex_group_assign_new";
ot->description = "Assign the selected vertices to a new vertex group";
/* api callbacks */
ot->poll = vertex_group_vert_select_poll;
ot->exec = vertex_group_assign_new_exec;
/* flags */
/* redo operator will fail in this case because vertex group assignment
* isn't stored in local edit mode stack and toggling "new" property will
* lead to creating plenty of new vertex groups (see [#29527], sergey) */
ot->flag = /*OPTYPE_REGISTER|*/ OPTYPE_UNDO;
}
static int vertex_group_remove_from_exec(bContext *C, wmOperator *op)