Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-12-27 09:46:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-12-27 10:01:11 +0300
commitf820c45534c653c7a2baa799b99067710def136b (patch)
tree7f08c2e1fa8e5aa2dbdbe38c64a1684495df124f
parentb254905c384d87764cd92ed631f86f3f97caa4de (diff)
WM: add checker_interval utility functions
-rw-r--r--source/blender/editors/curve/editcurve_select.c27
-rw-r--r--source/blender/editors/include/ED_curve.h1
-rw-r--r--source/blender/editors/mesh/editmesh_select.c27
-rw-r--r--source/blender/windowmanager/WM_api.h10
-rw-r--r--source/blender/windowmanager/intern/wm_operator_props.c32
5 files changed, 65 insertions, 32 deletions
diff --git a/source/blender/editors/curve/editcurve_select.c b/source/blender/editors/curve/editcurve_select.c
index 34ac3b8bb97..4855f9d1e6c 100644
--- a/source/blender/editors/curve/editcurve_select.c
+++ b/source/blender/editors/curve/editcurve_select.c
@@ -1075,7 +1075,7 @@ void CURVE_OT_select_random(wmOperatorType *ot)
/********************* every nth number of point *******************/
-static void select_nth_bezt(Nurb *nu, BezTriple *bezt, int nth, int skip, int offset)
+static void select_nth_bezt(Nurb *nu, BezTriple *bezt, const struct CheckerIntervalParams *params)
{
int a, start;
@@ -1085,7 +1085,7 @@ static void select_nth_bezt(Nurb *nu, BezTriple *bezt, int nth, int skip, int of
while (a--) {
const int depth = abs(start - a);
- if ((offset + depth) % (skip + nth) >= skip) {
+ if (WM_operator_properties_checker_interval_test(params, depth)) {
select_beztriple(bezt, DESELECT, SELECT, HIDDEN);
}
@@ -1093,7 +1093,7 @@ static void select_nth_bezt(Nurb *nu, BezTriple *bezt, int nth, int skip, int of
}
}
-static void select_nth_bp(Nurb *nu, BPoint *bp, int nth, int skip, int offset)
+static void select_nth_bp(Nurb *nu, BPoint *bp, const struct CheckerIntervalParams *params)
{
int a, startrow, startpnt;
int row, pnt;
@@ -1108,7 +1108,7 @@ static void select_nth_bp(Nurb *nu, BPoint *bp, int nth, int skip, int offset)
while (a--) {
const int depth = abs(pnt - startpnt) + abs(row - startrow);
- if ((offset + depth) % (skip + nth) >= skip) {
+ if (WM_operator_properties_checker_interval_test(params, depth)) {
select_bpoint(bp, DESELECT, SELECT, HIDDEN);
}
@@ -1122,7 +1122,7 @@ static void select_nth_bp(Nurb *nu, BPoint *bp, int nth, int skip, int offset)
}
}
-bool ED_curve_select_nth(Curve *cu, int nth, int skip, int offset)
+static bool ed_curve_select_nth(Curve *cu, const struct CheckerIntervalParams *params)
{
Nurb *nu = NULL;
void *vert = NULL;
@@ -1131,10 +1131,10 @@ bool ED_curve_select_nth(Curve *cu, int nth, int skip, int offset)
return false;
if (nu->bezt) {
- select_nth_bezt(nu, vert, nth, skip, offset);
+ select_nth_bezt(nu, vert, params);
}
else {
- select_nth_bp(nu, vert, nth, skip, offset);
+ select_nth_bp(nu, vert, params);
}
return true;
@@ -1143,14 +1143,11 @@ bool ED_curve_select_nth(Curve *cu, int nth, int skip, int offset)
static int select_nth_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
- const int nth = RNA_int_get(op->ptr, "nth") - 1;
- const int skip = RNA_int_get(op->ptr, "skip");
- int offset = RNA_int_get(op->ptr, "offset");
+ struct CheckerIntervalParams op_params;
- /* so input of offset zero ends up being (nth - 1) */
- offset = mod_i(offset, nth + skip);
+ WM_operator_properties_checker_interval_from_op(op, &op_params);
- if (!ED_curve_select_nth(obedit->data, nth, skip, offset)) {
+ if (!ed_curve_select_nth(obedit->data, &op_params)) {
if (obedit->type == OB_SURF) {
BKE_report(op->reports, RPT_ERROR, "Surface has not got active point");
}
@@ -1180,9 +1177,7 @@ void CURVE_OT_select_nth(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- RNA_def_int(ot->srna, "nth", 2, 2, INT_MAX, "Nth Selection", "", 2, 100);
- RNA_def_int(ot->srna, "skip", 1, 1, INT_MAX, "Skip", "", 1, 100);
- RNA_def_int(ot->srna, "offset", 0, INT_MIN, INT_MAX, "Offset", "", -100, 100);
+ WM_operator_properties_checker_interval(ot, false);
}
diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h
index ad3b41577c3..278e3f97ba7 100644
--- a/source/blender/editors/include/ED_curve.h
+++ b/source/blender/editors/include/ED_curve.h
@@ -71,7 +71,6 @@ bool ED_curve_select_check(struct Curve *cu, struct EditNurb *editnurb);
void ED_curve_deselect_all(struct EditNurb *editnurb);
void ED_curve_select_all(struct EditNurb *editnurb);
void ED_curve_select_swap(struct EditNurb *editnurb, bool hide_handles);
-bool ED_curve_select_nth(struct Curve *cu, int nth, int skip, int offset);
/* editfont.h */
void undo_push_font(struct bContext *C, const char *name);
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index f318c38e3bb..fba775518c7 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -3162,7 +3162,9 @@ static bool bm_edge_is_select_isolated(BMEdge *e)
/* Walk all reachable elements of the same type as h_act in breadth-first
* order, starting from h_act. Deselects elements if the depth when they
* are reached is not a multiple of "nth". */
-static void walker_deselect_nth(BMEditMesh *em, int nth, int skip, int offset, BMHeader *h_act)
+static void walker_deselect_nth(
+ BMEditMesh *em, const struct CheckerIntervalParams *op_params,
+ BMHeader *h_act)
{
BMElem *ele;
BMesh *bm = em->bm;
@@ -3229,7 +3231,7 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int skip, int offset, B
if (!BM_elem_flag_test(ele, BM_ELEM_TAG)) {
/* Deselect elements that aren't at "nth" depth from active */
const int depth = BMW_current_depth(&walker) - 1;
- if ((offset + depth) % (skip + nth) >= skip) {
+ if (WM_operator_properties_checker_interval_test(op_params, depth)) {
BM_elem_select_set(bm, ele, false);
}
BM_elem_flag_enable(ele, BM_ELEM_TAG);
@@ -3296,7 +3298,7 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed,
}
}
-static bool edbm_deselect_nth(BMEditMesh *em, int nth, int skip, int offset)
+static bool edbm_deselect_nth(BMEditMesh *em, const struct CheckerIntervalParams *op_params)
{
BMVert *v;
BMEdge *e;
@@ -3305,15 +3307,15 @@ static bool edbm_deselect_nth(BMEditMesh *em, int nth, int skip, int offset)
deselect_nth_active(em, &v, &e, &f);
if (v) {
- walker_deselect_nth(em, nth, skip, offset, &v->head);
+ walker_deselect_nth(em, op_params, &v->head);
return true;
}
else if (e) {
- walker_deselect_nth(em, nth, skip, offset, &e->head);
+ walker_deselect_nth(em, op_params, &e->head);
return true;
}
else if (f) {
- walker_deselect_nth(em, nth, skip, offset, &f->head);
+ walker_deselect_nth(em, op_params, &f->head);
return true;
}
@@ -3324,14 +3326,11 @@ static int edbm_select_nth_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
- const int nth = RNA_int_get(op->ptr, "nth") - 1;
- const int skip = RNA_int_get(op->ptr, "skip");
- int offset = RNA_int_get(op->ptr, "offset");
+ struct CheckerIntervalParams op_params;
- /* so input of offset zero ends up being (nth - 1) */
- offset = mod_i(offset, nth + skip);
+ WM_operator_properties_checker_interval_from_op(op, &op_params);
- if (edbm_deselect_nth(em, nth, skip, offset) == false) {
+ if (edbm_deselect_nth(em, &op_params) == false) {
BKE_report(op->reports, RPT_ERROR, "Mesh has no active vert/edge/face");
return OPERATOR_CANCELLED;
}
@@ -3356,9 +3355,7 @@ void MESH_OT_select_nth(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
- RNA_def_int(ot->srna, "nth", 2, 2, INT_MAX, "Nth Selection", "", 2, 100);
- RNA_def_int(ot->srna, "skip", 1, 1, INT_MAX, "Skip", "", 1, 100);
- RNA_def_int(ot->srna, "offset", 0, INT_MIN, INT_MAX, "Offset", "", -100, 100);
+ WM_operator_properties_checker_interval(ot, false);
}
void em_setup_viewcontext(bContext *C, ViewContext *vc)
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 9d1f4457013..3f89140888b 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -302,6 +302,16 @@ void WM_operator_properties_select_all(struct wmOperatorType *ot);
void WM_operator_properties_select_action(struct wmOperatorType *ot, int default_action);
void WM_operator_properties_select_action_simple(struct wmOperatorType *ot, int default_action);
void WM_operator_properties_select_random(struct wmOperatorType *ot);
+struct CheckerIntervalParams {
+ int nth; /* bypass when set to zero */
+ int skip;
+ int offset;
+};
+void WM_operator_properties_checker_interval(struct wmOperatorType *ot, bool nth_can_disable);
+void WM_operator_properties_checker_interval_from_op(
+ struct wmOperator *op, struct CheckerIntervalParams *op_params);
+bool WM_operator_properties_checker_interval_test(
+ const struct CheckerIntervalParams *op_params, int depth);
/* MOVE THIS SOMEWHERE ELSE */
diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c
index a59fbf9d528..c74bb46356d 100644
--- a/source/blender/windowmanager/intern/wm_operator_props.c
+++ b/source/blender/windowmanager/intern/wm_operator_props.c
@@ -31,6 +31,7 @@
#include "DNA_space_types.h"
#include "BLI_rect.h"
+#include "BLI_math_base.h"
#include "UI_resources.h"
@@ -248,3 +249,34 @@ void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
}
+
+/**
+ * \param nth_can_disable: Enable if we want to be able to select no interval at all.
+ */
+void WM_operator_properties_checker_interval(wmOperatorType *ot, bool nth_can_disable)
+{
+ const int nth_default = nth_can_disable ? 1 : 2;
+ const int nth_min = min_ii(nth_default, 2);
+ RNA_def_int(ot->srna, "nth", nth_default, nth_min, INT_MAX, "Nth Selection", "", nth_min, 100);
+ RNA_def_int(ot->srna, "skip", 1, 1, INT_MAX, "Skip", "", 1, 100);
+ RNA_def_int(ot->srna, "offset", 0, INT_MIN, INT_MAX, "Offset", "", -100, 100);
+}
+
+void WM_operator_properties_checker_interval_from_op(
+ struct wmOperator *op, struct CheckerIntervalParams *op_params)
+{
+ const int nth = RNA_int_get(op->ptr, "nth") - 1;
+ const int skip = RNA_int_get(op->ptr, "skip");
+ int offset = RNA_int_get(op->ptr, "offset");
+
+ op_params->nth = nth;
+ op_params->skip = skip;
+ op_params->offset = mod_i(offset, nth + skip); /* so input of offset zero ends up being (nth - 1) */
+}
+
+bool WM_operator_properties_checker_interval_test(
+ const struct CheckerIntervalParams *op_params, int depth)
+{
+ return ((op_params->nth == 0) ||
+ ((op_params->offset + depth) % (op_params->skip + op_params->nth) >= op_params->skip));
+}