[Bf-blender-cvs] [ccee8d8] hair_immediate_fixes: Select/Deselect All operator for hair edit mode.
Lukas Tönne
noreply at git.blender.org
Mon Jan 5 18:53:18 CET 2015
Commit: ccee8d8b03552e6f1b3a9d23e06b16ff6b572275
Author: Lukas Tönne
Date: Mon Jan 5 18:52:51 2015 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rBccee8d8b03552e6f1b3a9d23e06b16ff6b572275
Select/Deselect All operator for hair edit mode.
===================================================================
M source/blender/editors/hair/hair_edit.c
M source/blender/editors/hair/hair_intern.h
M source/blender/editors/hair/hair_ops.c
M source/blender/editors/hair/hair_select.c
===================================================================
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index 4be4570..3a92340 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -118,6 +118,18 @@ static bool apply_hair_edit(Object *ob)
return false;
}
+int ED_hair_edit_poll(bContext *C)
+{
+ Object *obact;
+
+ obact = CTX_data_active_object(C);
+ if ((obact && obact->mode & OB_MODE_HAIR_EDIT) && CTX_wm_region_view3d(C)) {
+ return true;
+ }
+
+ return false;
+}
+
/* ==== BMesh utilities ==== */
@@ -250,18 +262,6 @@ void hair_init_viewdata(bContext *C, HairViewData *viewdata)
}
}
-static int hair_stroke_poll(bContext *C)
-{
- Object *obact;
-
- obact = CTX_data_active_object(C);
- if ((obact && obact->mode & OB_MODE_HAIR_EDIT) && CTX_wm_region_view3d(C)) {
- return true;
- }
-
- return false;
-}
-
typedef struct HairStroke {
Scene *scene;
Object *ob;
@@ -476,7 +476,7 @@ void HAIR_OT_stroke(wmOperatorType *ot)
ot->invoke = hair_stroke_invoke;
ot->modal = hair_stroke_modal;
ot->cancel = hair_stroke_cancel;
- ot->poll = hair_stroke_poll;
+ ot->poll = ED_hair_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index 28795e5..56e3bc1 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -41,9 +41,12 @@ struct bContext;
struct wmOperatorType;
int hair_edit_toggle_poll(struct bContext *C);
+int ED_hair_edit_poll(struct bContext *C);
void HAIR_OT_hair_edit_toggle(struct wmOperatorType *ot);
+void HAIR_OT_select_all(struct wmOperatorType *ot);
+
void HAIR_OT_stroke(struct wmOperatorType *ot);
diff --git a/source/blender/editors/hair/hair_ops.c b/source/blender/editors/hair/hair_ops.c
index f2672fe..9792c79 100644
--- a/source/blender/editors/hair/hair_ops.c
+++ b/source/blender/editors/hair/hair_ops.c
@@ -49,6 +49,8 @@ void ED_operatortypes_hair(void)
{
WM_operatortype_append(HAIR_OT_hair_edit_toggle);
+ WM_operatortype_append(HAIR_OT_select_all);
+
WM_operatortype_append(HAIR_OT_stroke);
}
@@ -122,6 +124,11 @@ void ED_keymap_hair(wmKeyConfig *keyconf)
keymap = WM_keymap_find(keyconf, "Hair", 0, 0);
keymap->poll = hair_poll;
+ kmi = WM_keymap_add_item(keymap, "HAIR_OT_select_all", AKEY, KM_PRESS, 0, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
+ kmi = WM_keymap_add_item(keymap, "HAIR_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
+
kmi = WM_keymap_add_item(keymap, "HAIR_OT_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
ed_keymap_hair_brush_switch(keymap, "hair_edit");
diff --git a/source/blender/editors/hair/hair_select.c b/source/blender/editors/hair/hair_select.c
index 7a84f2b..070413f 100644
--- a/source/blender/editors/hair/hair_select.c
+++ b/source/blender/editors/hair/hair_select.c
@@ -47,6 +47,8 @@
#include "bmesh.h"
+#include "RNA_access.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -58,7 +60,36 @@
typedef bool (*TestVertexCb)(void *userdata, struct BMVert *v);
-static int hair_select_verts(BMEditStrands *edit, HairEditSelectMode select_mode, bool select, TestVertexCb cb, void *userdata)
+BLI_INLINE bool apply_select_action_flag(BMVert *v, int action)
+{
+ bool cursel = BM_elem_flag_test_bool(v, BM_ELEM_SELECT);
+ bool newsel;
+
+ switch (action) {
+ case SEL_SELECT:
+ newsel = true;
+ break;
+ case SEL_DESELECT:
+ newsel = false;
+ break;
+ case SEL_INVERT:
+ newsel = !cursel;
+ break;
+ case SEL_TOGGLE:
+ /* toggle case should be converted to SELECT or DESELECT based on global state */
+ BLI_assert(false);
+ break;
+ }
+
+ if (newsel != cursel) {
+ BM_elem_flag_set(v, BM_ELEM_SELECT, newsel);
+ return true;
+ }
+ else
+ return false;
+}
+
+static int hair_select_verts(BMEditStrands *edit, HairEditSelectMode select_mode, int action, TestVertexCb cb, void *userdata)
{
BMesh *bm = edit->bm;
@@ -73,26 +104,22 @@ static int hair_select_verts(BMEditStrands *edit, HairEditSelectMode select_mode
break;
case HAIR_SELECT_VERTEX:
BM_ITER_MESH(v, &iter, edit->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test_bool(v, BM_ELEM_SELECT) == select)
- continue;
if (!cb(userdata, v))
continue;
- BM_elem_flag_set(v, BM_ELEM_SELECT, select);
- ++tot;
+ if (apply_select_action_flag(v, action))
+ ++tot;
}
break;
case HAIR_SELECT_TIP:
BM_ITER_MESH(v, &iter, edit->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test_bool(v, BM_ELEM_SELECT) == select)
- continue;
if (!BM_strands_vert_is_tip(v))
continue;
if (!cb(userdata, v))
continue;
- BM_elem_flag_set(v, BM_ELEM_SELECT, select);
- ++tot;
+ if (apply_select_action_flag(v, action))
+ ++tot;
}
break;
}
@@ -104,6 +131,58 @@ static int hair_select_verts(BMEditStrands *edit, HairEditSelectMode select_mode
/* ------------------------------------------------------------------------- */
+/************************ select/deselect all operator ************************/
+
+static bool test_vertex_all(void *UNUSED(userdata), struct BMVert *UNUSED(v))
+{
+ return true;
+}
+
+static int select_all_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+ BMEditStrands *edit = BKE_editstrands_from_object(ob);
+ HairEditSettings *settings = &scene->toolsettings->hair_edit;
+ int action = RNA_enum_get(op->ptr, "action");
+
+ if (!edit)
+ return 0;
+
+ /* toggle action depends on current global selection state */
+ if (action == SEL_TOGGLE) {
+ if (edit->bm->totvertsel == 0)
+ action = SEL_SELECT;
+ else
+ action = SEL_DESELECT;
+ }
+
+ hair_select_verts(edit, settings->select_mode, action, test_vertex_all, NULL);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW | NA_SELECTED, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void HAIR_OT_select_all(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select/Deselect All";
+ ot->idname = "HAIR_OT_select_all";
+ ot->description = "Select/Deselect all hair vertices";
+
+ /* api callbacks */
+ ot->exec = select_all_exec;
+ ot->poll = ED_hair_edit_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ WM_operator_properties_select_all(ot);
+}
+
+/************************ circle select operator ************************/
+
typedef struct TestVertexCirleData {
HairViewData viewdata;
float mval[2];
@@ -124,6 +203,7 @@ int ED_hair_circle_select(bContext *C, bool select, const int mval[2], float rad
Object *ob = CTX_data_active_object(C);
BMEditStrands *edit = BKE_editstrands_from_object(ob);
HairEditSettings *settings = &scene->toolsettings->hair_edit;
+ int action = select ? SEL_SELECT : SEL_DESELECT;
TestVertexCirleData data;
int tot;
@@ -136,7 +216,7 @@ int ED_hair_circle_select(bContext *C, bool select, const int mval[2], float rad
data.mval[1] = mval[1];
data.radsq = radius * radius;
- tot = hair_select_verts(edit, settings->select_mode, select, test_vertex_circle, &data);
+ tot = hair_select_verts(edit, settings->select_mode, action, test_vertex_circle, &data);
return tot;
}
More information about the Bf-blender-cvs
mailing list