Lattice Editmode: Select Mirror
authorCampbell Barton <ideasman42@gmail.com>
Mon, 9 Dec 2013 04:40:41 +0000 (15:40 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 9 Dec 2013 04:41:54 +0000 (15:41 +1100)
patch originally by Philipp Oeser with some edits.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_lattice.c
source/blender/editors/object/object_ops.c
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_object.c

index dd3710fe8e8c1b2def4c60e9cff8f762c3906854..8174ef3261a26b4c3c92ea307013443e4b09405a 100644 (file)
@@ -746,6 +746,7 @@ class VIEW3D_MT_select_edit_lattice(Menu):
 
         layout.separator()
 
+        layout.operator("lattice.select_mirror")
         layout.operator("lattice.select_random")
         layout.operator("lattice.select_all").action = 'TOGGLE'
         layout.operator("lattice.select_all", text="Inverse").action = 'INVERT'
index ce509e2ffe77dc4278fe85a59e31914f61f388da..536f3f05ab23e4ae6150ff02d35fb2ea1bb3b0fe 100644 (file)
@@ -142,6 +142,7 @@ void LATTICE_OT_select_more(struct wmOperatorType *ot);
 void LATTICE_OT_select_less(struct wmOperatorType *ot);
 void LATTICE_OT_select_ungrouped(struct wmOperatorType *ot);
 void LATTICE_OT_select_random(struct wmOperatorType *ot);
+void LATTICE_OT_select_mirror(struct wmOperatorType *ot);
 void LATTICE_OT_make_regular(struct wmOperatorType *ot);
 void LATTICE_OT_flip(struct wmOperatorType *ot);
 
index 6379d23800a7dc1a47ebabf6e0b3a9f411441d73..fdc9a604c07563e2da179e47212ff127d22c2b8b 100644 (file)
@@ -49,6 +49,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
@@ -226,6 +227,78 @@ void LATTICE_OT_select_random(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
 }
 
+
+/* -------------------------------------------------------------------- */
+/* Select Mirror Operator */
+
+static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
+       const bool extend = RNA_boolean_get(op->ptr, "extend");
+       const int axis = RNA_enum_get(op->ptr, "axis");
+       bool flip_uvw[3] = {false};
+       int tot, i;
+       BPoint *bp;
+       BLI_bitmap *selpoints;
+
+       tot = lt->pntsu * lt->pntsv * lt->pntsw;
+
+       flip_uvw[axis] = true;
+
+       if (!extend) {
+               lt->actbp = LT_ACTBP_NONE;
+       }
+
+       /* store "original" selection */
+       selpoints = BLI_BITMAP_NEW(tot, __func__);
+       BKE_lattice_bitmap_from_flag(lt, selpoints, SELECT, false, false);
+
+       /* actual (de)selection */
+       for (i = 0; i < tot; i++) {
+               const int i_flip = BKE_lattice_index_flip(lt, i, flip_uvw[0], flip_uvw[1], flip_uvw[2]);
+               bp = &lt->def[i];
+               if (!bp->hide) {
+                       if (BLI_BITMAP_GET(selpoints, i_flip)) {
+                               bp->f1 |= SELECT;
+                       }
+                       else {
+                               if (!extend) {
+                                       bp->f1 &= ~SELECT;
+                               }
+                       }
+               }
+       }
+
+
+       MEM_freeN(selpoints);
+
+       WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void LATTICE_OT_select_mirror(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Select Mirror";
+       ot->description = "Select mirrored lattice points";
+       ot->idname = "LATTICE_OT_select_mirror";
+
+       /* api callbacks */
+       ot->exec = lattice_select_mirror_exec;
+       ot->poll = ED_operator_editlattice;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_enum(ot->srna, "axis", object_axis_unsigned_items, 0, "Axis", "");
+
+       RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
+}
+
+
 /************************** Select More/Less Operator *************************/
 
 static bool lattice_test_bitmap_uvw(Lattice *lt, BLI_bitmap *selpoints, int u, int v, int w, const bool selected)
index 74ac487b6873b34a2b0fafa799843a576b1e8450..efebbe8ddd71b842b8d29412bbd67551e6d1ba95 100644 (file)
@@ -224,6 +224,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(LATTICE_OT_select_less);
        WM_operatortype_append(LATTICE_OT_select_ungrouped);
        WM_operatortype_append(LATTICE_OT_select_random);
+       WM_operatortype_append(LATTICE_OT_select_mirror);
        WM_operatortype_append(LATTICE_OT_make_regular);
        WM_operatortype_append(LATTICE_OT_flip);
 
index 2fb1af7417310ccdeb36dca9e681196c8ee3446b..34f5d1f3064fb87e110c170b0bb5be093c46ad40 100644 (file)
@@ -114,6 +114,7 @@ extern EnumPropertyItem rigidbody_object_shape_items[];
 extern EnumPropertyItem rigidbody_constraint_type_items[];
 
 extern EnumPropertyItem object_axis_items[];
+extern EnumPropertyItem object_axis_unsigned_items[];
 
 extern EnumPropertyItem controller_type_items[];
 
index eb0f30216f2f3d6ed644b5df26afe188e80b32b4..184e067299e8fee036142f926e707616e73e579d 100644 (file)
@@ -165,6 +165,14 @@ EnumPropertyItem object_axis_items[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
+/* for general use (not just object) */
+EnumPropertyItem object_axis_unsigned_items[] = {
+       {0, "X", 0, "X", ""},
+       {1, "Y", 0, "Y", ""},
+       {2, "Z", 0, "Z", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
 #ifdef RNA_RUNTIME
 
 #include "BLI_math.h"