GPencil: Add lock icon to Vertex Groups list
authorAntonioya <blendergit@gmail.com>
Tue, 16 Apr 2019 09:27:36 +0000 (11:27 +0200)
committerAntonioya <blendergit@gmail.com>
Tue, 16 Apr 2019 11:10:04 +0000 (13:10 +0200)
Also check this flag in operators.

Note: This is required for the development of the new Normalize All operator.

release/scripts/startup/bl_ui/properties_data_gpencil.py
source/blender/editors/gpencil/gpencil_brush.c
source/blender/editors/gpencil/gpencil_data.c

index 0348b24..5d11373 100644 (file)
@@ -342,8 +342,8 @@ class GPENCIL_UL_vgroups(UIList):
         vgroup = item
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
         vgroup = item
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
-            icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
-            layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
+            icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
+            layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
         elif self.layout_type == 'GRID':
             layout.alignment = 'CENTER'
             layout.label(text="", icon_value=icon)
         elif self.layout_type == 'GRID':
             layout.alignment = 'CENTER'
             layout.label(text="", icon_value=icon)
index e7e6d7a..8f64ec1 100644 (file)
@@ -929,6 +929,12 @@ static bool gp_brush_weight_apply(
                        gso->vrgroup = 0;
                }
        }
                        gso->vrgroup = 0;
                }
        }
+       else {
+               bDeformGroup *defgroup = BLI_findlink(&gso->object->defbase, gso->vrgroup);
+               if (defgroup->flag & DG_LOCK_WEIGHT) {
+                       return false;
+               }
+       }
        /* get current weight */
        MDeformWeight *dw = defvert_verify_index(dvert, gso->vrgroup);
        float curweight = dw ? dw->weight : 0.0f;
        /* get current weight */
        MDeformWeight *dw = defvert_verify_index(dvert, gso->vrgroup);
        float curweight = dw ? dw->weight : 0.0f;
index 81da4ab..52c4354 100644 (file)
@@ -1725,19 +1725,26 @@ void GPENCIL_OT_vertex_group_deselect(wmOperatorType *ot)
 }
 
 /* invert */
 }
 
 /* invert */
-static int gpencil_vertex_group_invert_exec(bContext *C, wmOperator *UNUSED(op))
+static int gpencil_vertex_group_invert_exec(bContext *C, wmOperator *op)
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
        Object *ob = CTX_data_active_object(C);
 
        /* sanity checks */
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
        Object *ob = CTX_data_active_object(C);
 
        /* sanity checks */
-       if (ELEM(NULL, ts, ob, ob->data))
+       if (ELEM(NULL, ts, ob, ob->data)) {
                return OPERATOR_CANCELLED;
                return OPERATOR_CANCELLED;
+       }
 
        MDeformVert *dvert;
        const int def_nr = ob->actdef - 1;
 
        MDeformVert *dvert;
        const int def_nr = ob->actdef - 1;
-       if (!BLI_findlink(&ob->defbase, def_nr))
+       bDeformGroup *defgroup = BLI_findlink(&ob->defbase, def_nr);
+       if (defgroup == NULL) {
+               return OPERATOR_CANCELLED;
+       }
+       if (defgroup->flag & DG_LOCK_WEIGHT) {
+               BKE_report(op->reports, RPT_ERROR, "Current Vertex Group is locked");
                return OPERATOR_CANCELLED;
                return OPERATOR_CANCELLED;
+       }
 
        CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
        {
 
        CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
        {
@@ -1790,15 +1797,22 @@ static int gpencil_vertex_group_smooth_exec(bContext *C, wmOperator *op)
        Object *ob = CTX_data_active_object(C);
 
        /* sanity checks */
        Object *ob = CTX_data_active_object(C);
 
        /* sanity checks */
-       if (ELEM(NULL, ts, ob, ob->data))
+       if (ELEM(NULL, ts, ob, ob->data)) {
                return OPERATOR_CANCELLED;
                return OPERATOR_CANCELLED;
-
-       bGPDspoint *pta, *ptb, *ptc;
-       MDeformVert *dverta, *dvertb;
+       }
 
        const int def_nr = ob->actdef - 1;
 
        const int def_nr = ob->actdef - 1;
-       if (!BLI_findlink(&ob->defbase, def_nr))
+       bDeformGroup *defgroup = BLI_findlink(&ob->defbase, def_nr);
+       if (defgroup == NULL) {
                return OPERATOR_CANCELLED;
                return OPERATOR_CANCELLED;
+       }
+       if (defgroup->flag & DG_LOCK_WEIGHT) {
+               BKE_report(op->reports, RPT_ERROR, "Current Vertex Group is locked");
+               return OPERATOR_CANCELLED;
+       }
+
+       bGPDspoint *pta, *ptb, *ptc;
+       MDeformVert *dverta, *dvertb;
 
        CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
        {
 
        CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
        {
@@ -1874,19 +1888,26 @@ void GPENCIL_OT_vertex_group_smooth(wmOperatorType *ot)
 }
 
 /* normalize */
 }
 
 /* normalize */
-static int gpencil_vertex_group_normalize_exec(bContext *C, wmOperator *UNUSED(op))
+static int gpencil_vertex_group_normalize_exec(bContext *C, wmOperator *op)
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
        Object *ob = CTX_data_active_object(C);
 
        /* sanity checks */
 {
        ToolSettings *ts = CTX_data_tool_settings(C);
        Object *ob = CTX_data_active_object(C);
 
        /* sanity checks */
-       if (ELEM(NULL, ts, ob, ob->data))
+       if (ELEM(NULL, ts, ob, ob->data)) {
                return OPERATOR_CANCELLED;
                return OPERATOR_CANCELLED;
+       }
 
        MDeformVert *dvert;
        const int def_nr = ob->actdef - 1;
 
        MDeformVert *dvert;
        const int def_nr = ob->actdef - 1;
-       if (!BLI_findlink(&ob->defbase, def_nr))
+       bDeformGroup *defgroup = BLI_findlink(&ob->defbase, def_nr);
+       if (defgroup == NULL) {
                return OPERATOR_CANCELLED;
                return OPERATOR_CANCELLED;
+       }
+       if (defgroup->flag & DG_LOCK_WEIGHT) {
+               BKE_report(op->reports, RPT_ERROR, "Current Vertex Group is locked");
+               return OPERATOR_CANCELLED;
+       }
 
        CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
        {
 
        CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
        {