[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28716] trunk/blender: " Every Nth number of Points" operator for curves/surfaces
Sergey Sharybin
g.ulairi at gmail.com
Mon May 10 19:32:11 CEST 2010
Revision: 28716
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28716
Author: nazgul
Date: 2010-05-10 19:32:11 +0200 (Mon, 10 May 2010)
Log Message:
-----------
"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.
Modified Paths:
--------------
trunk/blender/release/scripts/ui/space_view3d.py
trunk/blender/source/blender/editors/curve/curve_intern.h
trunk/blender/source/blender/editors/curve/curve_ops.c
trunk/blender/source/blender/editors/curve/editcurve.c
trunk/blender/source/blender/editors/include/ED_curve.h
Modified: trunk/blender/release/scripts/ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/ui/space_view3d.py 2010-05-10 17:16:32 UTC (rev 28715)
+++ trunk/blender/release/scripts/ui/space_view3d.py 2010-05-10 17:32:11 UTC (rev 28716)
@@ -523,7 +523,7 @@
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 @@
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()
Modified: trunk/blender/source/blender/editors/curve/curve_intern.h
===================================================================
--- trunk/blender/source/blender/editors/curve/curve_intern.h 2010-05-10 17:16:32 UTC (rev 28715)
+++ trunk/blender/source/blender/editors/curve/curve_intern.h 2010-05-10 17:32:11 UTC (rev 28716)
@@ -96,7 +96,7 @@
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);
Modified: trunk/blender/source/blender/editors/curve/curve_ops.c
===================================================================
--- trunk/blender/source/blender/editors/curve/curve_ops.c 2010-05-10 17:16:32 UTC (rev 28715)
+++ trunk/blender/source/blender/editors/curve/curve_ops.c 2010-05-10 17:32:11 UTC (rev 28716)
@@ -111,7 +111,7 @@
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);
Modified: trunk/blender/source/blender/editors/curve/editcurve.c
===================================================================
--- trunk/blender/source/blender/editors/curve/editcurve.c 2010-05-10 17:16:32 UTC (rev 28715)
+++ trunk/blender/source/blender/editors/curve/editcurve.c 2010-05-10 17:32:11 UTC (rev 28716)
@@ -4272,37 +4272,128 @@
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 *********************/
Modified: trunk/blender/source/blender/editors/include/ED_curve.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_curve.h 2010-05-10 17:16:32 UTC (rev 28715)
+++ trunk/blender/source/blender/editors/include/ED_curve.h 2010-05-10 17:32:11 UTC (rev 28716)
@@ -71,5 +71,7 @@
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 */
More information about the Bf-blender-cvs
mailing list