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:
authorMatt Ebb <matt@mke3.net>2010-01-11 08:32:01 +0300
committerMatt Ebb <matt@mke3.net>2010-01-11 08:32:01 +0300
commit7bbf4f660507b95711ccd67bdc36bc5e1ee8c26f (patch)
treed243d299b6ebdf7799e13b4754e7f276c779da8e /source/blender/editors
parente0dd3fe5872ba37ff188e292b80b46fcf8df413c (diff)
* Removed popups from curve select random and Nth, also edited
select random code to use the same logic as select random for meshes (with extend property as well)
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/curve/editcurve.c86
1 files changed, 29 insertions, 57 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index a109e9149cf..40edac0ffce 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4146,83 +4146,56 @@ void CURVE_OT_select_less(wmOperatorType *ot)
/********************** select random *********************/
-/* this function could be moved elsewhere as it can be reused in other parts of the source needing randomized list */
-/* returns list containing -1 in indices that have been left out of the list. otherwise index contains reference */
-/* to next index. basically *list contains a linked list */
-static void generate_pickable_list(int *list, int size, int pickamount)
+static void selectrandom_curve(ListBase *editnurb, float randfac)
{
- int i, j, removable;
-
- BLI_srand( BLI_rand() ); /* random seed */
-
- /* generate list in form 0->1, 1->2, 2->3, ... i-2->i-1, i->0 */
- for(i=0; i<size; i++) {
- if(i == size-1) list[i]= 0;
- else list[i]= i+1;
- }
-
- for(i=0; i<size-pickamount; i++) {
- removable= floor(BLI_frand()*(size-1)+0.5); /* with rounding. frand returns [0,1] */
-
- /* seek proper item as the one randomly selected might not be appropriate */
- for(j=0; j<size; j++, removable++) {
- if(list[removable] != -1) break;
- if(removable == size-1) removable= -1;
- }
-
- /* pick unwanted item out of the list */
- list[list[removable]]= -1; /* mark former last as invalid */
-
- if(list[removable] == size-1) list[removable]= 0;
- else list[removable]= list[removable]+1;
- }
-}
-
-static int select_random_exec(bContext *C, wmOperator *op)
-{
- Object *obedit= CTX_data_edit_object(C);
- ListBase *editnurb= curve_get_editcurve(obedit);
Nurb *nu;
BezTriple *bezt;
BPoint *bp;
- float percent= RNA_float_get(op->ptr, "percent");
- int amounttoselect, amountofcps, a, i, k= 0;
- int *itemstobeselected;
-
- if(percent == 0.0f)
- return OPERATOR_CANCELLED;
+ int a;
- amountofcps= count_curveverts_without_handles(editnurb);
- itemstobeselected= MEM_callocN(sizeof(int) * amountofcps, "selectitems");
- amounttoselect= floor(percent * amountofcps + 0.5);
- generate_pickable_list(itemstobeselected, amountofcps, amounttoselect);
+ BLI_srand( BLI_rand() ); /* random seed */
- /* select elements */
- for(i=1, nu= editnurb->first; nu; nu= nu->next) {
+ for(nu= editnurb->first; nu; nu= nu->next) {
if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
- if(itemstobeselected[k] != -1) select_beztriple(bezt, SELECT, 1, VISIBLE);
- k++;
+ if (BLI_frand() < randfac)
+ select_beztriple(bezt, SELECT, 1, VISIBLE);
bezt++;
}
}
else {
bp= nu->bp;
a= nu->pntsu*nu->pntsv;
+
while(a--) {
- if(itemstobeselected[k] != -1) select_bpoint(bp, SELECT, 1, VISIBLE);
- k++;
+ if (BLI_frand() < randfac)
+ select_bpoint(bp, SELECT, 1, VISIBLE);
bp++;
}
}
}
-
- MEM_freeN(itemstobeselected);
+}
- WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+static int select_random_exec(bContext *C, wmOperator *op)
+{
+ Object *obedit= CTX_data_edit_object(C);
+ ListBase *editnurb= curve_get_editcurve(obedit);
+ Nurb *nu;
+ BezTriple *bezt;
+ BPoint *bp;
+ int amounttoselect, amountofcps, a, i, k= 0;
+ int *itemstobeselected;
+ float percent;
+ if(!RNA_boolean_get(op->ptr, "extend"))
+ CU_deselect_all(obedit);
+
+ selectrandom_curve(editnurb, RNA_float_get(op->ptr, "percent")/100.0f);
+
+ WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+
return OPERATOR_FINISHED;
}
@@ -4234,14 +4207,14 @@ void CURVE_OT_select_random(wmOperatorType *ot)
/* api callbacks */
ot->exec= select_random_exec;
- ot->invoke= WM_operator_props_popup;
ot->poll= ED_operator_editsurfcurve;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
- RNA_def_float_percentage(ot->srna, "percent", 0.5f, 0.0f, 1.0f, "Percent", "Percentage of vertices to select randomly.", 0.0001f, 1.0f);
+ RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly.", 0.f, 100.0f);
+ RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first.");
}
/********************** select every nth *********************/
@@ -4268,7 +4241,6 @@ void CURVE_OT_select_every_nth(wmOperatorType *ot)
/* api callbacks */
ot->exec= select_every_nth_exec;
- ot->invoke= WM_operator_props_popup;
ot->poll= ED_operator_editsurfcurve;
/* flags */