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:
authorSergey Sharybin <sergey.vfx@gmail.com>2010-05-10 21:32:11 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2010-05-10 21:32:11 +0400
commit8d9e55122f94712258b1a4e4d6aacff15864fe31 (patch)
tree32e50afac3c9f49055daedf31ea0c4e0dfcf6d02
parent50b412939836b3033841fb82918c67ddbcf5c399 (diff)
"Every Nth number of Points" operator for curves/surfaces
This is replacement of old "Select every Nth" operator with de-select strategy to make the same behaviour as for meshes.
-rw-r--r--release/scripts/ui/space_view3d.py4
-rw-r--r--source/blender/editors/curve/curve_intern.h2
-rw-r--r--source/blender/editors/curve/curve_ops.c2
-rw-r--r--source/blender/editors/curve/editcurve.c123
-rw-r--r--source/blender/editors/include/ED_curve.h2
5 files changed, 113 insertions, 20 deletions
diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py
index a8fc4eb89af..8be176843fc 100644
--- a/release/scripts/ui/space_view3d.py
+++ b/release/scripts/ui/space_view3d.py
@@ -523,7 +523,7 @@ class VIEW3D_MT_select_edit_curve(bpy.types.Menu):
layout.operator("curve.select_all", text="Select/Deselect All")
layout.operator("curve.select_inverse")
layout.operator("curve.select_random")
- layout.operator("curve.select_every_nth")
+ layout.operator("curve.select_nth", text="Every Nth Number of Points")
layout.separator()
@@ -552,7 +552,7 @@ class VIEW3D_MT_select_edit_surface(bpy.types.Menu):
layout.operator("curve.select_all", text="Select/Deselect All")
layout.operator("curve.select_inverse")
layout.operator("curve.select_random")
- layout.operator("curve.select_every_nth")
+ layout.operator("curve.select_nth", text="Every Nth Number of Points")
layout.separator()
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index d3b377e2a67..a9f9aac70d5 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -96,7 +96,7 @@ void CURVE_OT_select_previous(struct wmOperatorType *ot);
void CURVE_OT_select_more(struct wmOperatorType *ot);
void CURVE_OT_select_less(struct wmOperatorType *ot);
void CURVE_OT_select_random(struct wmOperatorType *ot);
-void CURVE_OT_select_every_nth(struct wmOperatorType *ot);
+void CURVE_OT_select_nth(struct wmOperatorType *ot);
void CURVE_OT_switch_direction(struct wmOperatorType *ot);
void CURVE_OT_subdivide(struct wmOperatorType *ot);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index e0340ce67c6..fa341ee19ef 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -111,7 +111,7 @@ void ED_operatortypes_curve(void)
WM_operatortype_append(CURVE_OT_select_more);
WM_operatortype_append(CURVE_OT_select_less);
WM_operatortype_append(CURVE_OT_select_random);
- WM_operatortype_append(CURVE_OT_select_every_nth);
+ WM_operatortype_append(CURVE_OT_select_nth);
WM_operatortype_append(CURVE_OT_switch_direction);
WM_operatortype_append(CURVE_OT_subdivide);
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 22976c7e5d6..5c64b82ec87 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4272,37 +4272,128 @@ void CURVE_OT_select_random(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first.");
}
-/********************** select every nth *********************/
+/********************* every nth number of point *******************/
-static int select_every_nth_exec(bContext *C, wmOperator *op)
+static int point_on_nurb(Nurb *nu, void *point)
+{
+ if (nu->bezt) {
+ BezTriple *bezt= (BezTriple*)point;
+ return bezt >= nu->bezt && bezt < nu->bezt + nu->pntsu;
+ } else {
+ BPoint *bp= (BPoint*)point;
+ return bp >= nu->bp && bp < nu->bp + nu->pntsu * nu->pntsv;
+ }
+}
+
+static void select_nth_bezt(Nurb *nu, BezTriple *bezt, int nth)
+{
+ int a, start;
+
+ start= bezt - nu->bezt;
+ a= nu->pntsu;
+ bezt= nu->bezt + a - 1;
+
+ while (a--) {
+ if (abs(start - a) % nth) {
+ select_beztriple(bezt, DESELECT, 1, HIDDEN);
+ }
+
+ bezt--;
+ }
+}
+
+static void select_nth_bp(Nurb *nu, BPoint *bp, int nth)
+{
+ int a, startrow, startpnt;
+ int dist, row, pnt;
+
+ startrow= (bp - nu->bp) / nu->pntsu;
+ startpnt= (bp - nu->bp) % nu->pntsu;
+
+ a= nu->pntsu * nu->pntsv;
+ bp= nu->bp + a - 1;
+ row = nu->pntsv - 1;
+ pnt = nu->pntsu - 1;
+
+ while (a--) {
+ dist= abs(pnt - startpnt) + abs(row - startrow);
+ if (dist % nth) {
+ select_bpoint(bp, DESELECT, 1, HIDDEN);
+ }
+
+ pnt--;
+ if (pnt < 0) {
+ pnt= nu->pntsu - 1;
+ row--;
+ }
+
+ bp--;
+ }
+}
+
+int CU_select_nth(Object *obedit, int nth)
+{
+ Curve *cu= (Curve*)obedit->data;
+ ListBase *nubase= cu->editnurb;
+ Nurb *nu;
+ int ok=0;
+
+ /* Search nurb to which selected point belongs to */
+ nu= nubase->first;
+ while (nu) {
+ if (point_on_nurb(nu, cu->lastsel)) {
+ ok= 1;
+ break;
+ }
+ nu= nu->next;
+ }
+
+ if (!ok) return 0;
+
+ if (nu->bezt) {
+ select_nth_bezt(nu, cu->lastsel, nth);
+ } else {
+ select_nth_bp(nu, cu->lastsel, nth);
+ }
+
+ return 1;
+}
+
+static int select_nth_exec(bContext *C, wmOperator *op)
{
Object *obedit= CTX_data_edit_object(C);
- ListBase *editnurb= curve_get_editcurve(obedit);
- int n= RNA_int_get(op->ptr, "n");
-
- select_adjacent_cp(editnurb, n, 1, SELECT);
- select_adjacent_cp(editnurb, -n, 1, SELECT);
-
+ int nth= RNA_int_get(op->ptr, "nth");
+
+ if (!CU_select_nth(obedit, nth)) {
+ if (obedit->type == OB_SURF) {
+ BKE_report(op->reports, RPT_ERROR, "Surface hasn't got active point");
+ } else {
+ BKE_report(op->reports, RPT_ERROR, "Curve hasn't got active point");
+ }
+
+ return OPERATOR_CANCELLED;
+ }
+
WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
}
-void CURVE_OT_select_every_nth(wmOperatorType *ot)
+void CURVE_OT_select_nth(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Select Every Nth";
- ot->idname= "CURVE_OT_select_every_nth";
-
+ ot->name= "Select Nth";
+ ot->description= "";
+ ot->idname= "CURVE_OT_select_nth";
+
/* api callbacks */
- ot->exec= select_every_nth_exec;
+ ot->exec= select_nth_exec;
ot->poll= ED_operator_editsurfcurve;
-
+
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
- /* properties */
- RNA_def_int(ot->srna, "n", 2, 2, INT_MAX, "N", "Select every Nth element", 2, 25);
+ RNA_def_int(ot->srna, "nth", 2, 2, 100, "Nth Selection", "", 1, INT_MAX);
}
/********************** add duplicate operator *********************/
diff --git a/source/blender/editors/include/ED_curve.h b/source/blender/editors/include/ED_curve.h
index 3710d4bc4cc..a229d919e77 100644
--- a/source/blender/editors/include/ED_curve.h
+++ b/source/blender/editors/include/ED_curve.h
@@ -71,5 +71,7 @@ void free_editText (struct Object *obedit);
void ED_text_to_object(struct bContext *C, struct Text *text, int split_lines);
+int CU_select_nth(struct Object *obedit, int nth);
+
#endif /* ED_CURVE_H */