Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/curve/editcurve_select.c
| Show All 32 Lines | |||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_bitmap.h" | #include "BLI_bitmap.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_rand.h" | #include "BLI_rand.h" | ||||
| #include "BLI_heap.h" | #include "BLI_heap.h" | ||||
| #include "BLI_kdtree.h" | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | void ED_curve_nurb_deselect_all(Nurb *nu) | ||||
| else if (nu->bp) { | else if (nu->bp) { | ||||
| BPoint *bp; | BPoint *bp; | ||||
| for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | ||||
| bp->f1 &= ~SELECT; | bp->f1 &= ~SELECT; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| int ED_curve_select_count(View3D *v3d, struct EditNurb *editnurb) | |||||
dfelinto: Why is this not a static function? Are you planning to use this from a different file? | |||||
Not Done Inline ActionsI was following the style of the neighbouring functions, e.g. bool ED_curve_select_check. But maybe all similar functions should be static? zazizizou: I was following the style of the neighbouring functions, e.g. `bool ED_curve_select_check`. But… | |||||
| { | |||||
| int sel = 0; | |||||
Done Inline ActionsCode style, loose this extra line. dfelinto: Code style, loose this extra line. | |||||
| Nurb *nu; | |||||
| for (nu = editnurb->nurbs.first; nu; nu = nu->next) { | |||||
| sel += ED_curve_nurb_select_count(v3d, nu); | |||||
| } | |||||
| return sel; | |||||
| } | |||||
| bool ED_curve_select_check(View3D *v3d, struct EditNurb *editnurb) | bool ED_curve_select_check(View3D *v3d, struct EditNurb *editnurb) | ||||
| { | { | ||||
| Nurb *nu; | Nurb *nu; | ||||
| for (nu = editnurb->nurbs.first; nu; nu = nu->next) { | for (nu = editnurb->nurbs.first; nu; nu = nu->next) { | ||||
| if (ED_curve_nurb_select_check(v3d, nu)) { | if (ED_curve_nurb_select_check(v3d, nu)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,073 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Select Similar */ | /* Select Similar */ | ||||
| /** \name Select Similar | /** \name Select Similar | ||||
| * \{ */ | * \{ */ | ||||
| enum { | |||||
| SIM_CMP_EQ = 0, | |||||
| SIM_CMP_GT, | |||||
| SIM_CMP_LT, | |||||
| }; | |||||
| static const EnumPropertyItem curve_prop_similar_compare_types[] = { | static const EnumPropertyItem curve_prop_similar_compare_types[] = { | ||||
| {SIM_CMP_EQ, "EQUAL", 0, "Equal", ""}, | {SIM_CMP_EQ, "EQUAL", 0, "Equal", ""}, | ||||
| {SIM_CMP_GT, "GREATER", 0, "Greater", ""}, | {SIM_CMP_GT, "GREATER", 0, "Greater", ""}, | ||||
| {SIM_CMP_LT, "LESS", 0, "Less", ""}, | {SIM_CMP_LT, "LESS", 0, "Less", ""}, | ||||
| {0, NULL, 0, NULL, NULL} | {0, NULL, 0, NULL, NULL} | ||||
| }; | }; | ||||
| enum { | enum { | ||||
| SIMCURHAND_TYPE = 0, | SIMCURHAND_TYPE = 0, | ||||
| SIMCURHAND_RADIUS, | SIMCURHAND_RADIUS, | ||||
| SIMCURHAND_WEIGHT, | SIMCURHAND_WEIGHT, | ||||
| SIMCURHAND_DIRECTION, | SIMCURHAND_DIRECTION, | ||||
| }; | }; | ||||
| static const EnumPropertyItem curve_prop_similar_types[] = { | static const EnumPropertyItem curve_prop_similar_types[] = { | ||||
| {SIMCURHAND_TYPE, "TYPE", 0, "Type", ""}, | {SIMCURHAND_TYPE, "TYPE", 0, "Type", ""}, | ||||
| {SIMCURHAND_RADIUS, "RADIUS", 0, "Radius", ""}, | {SIMCURHAND_RADIUS, "RADIUS", 0, "Radius", ""}, | ||||
| {SIMCURHAND_WEIGHT, "WEIGHT", 0, "Weight", ""}, | {SIMCURHAND_WEIGHT, "WEIGHT", 0, "Weight", ""}, | ||||
| {SIMCURHAND_DIRECTION, "DIRECTION", 0, "Direction", ""}, | {SIMCURHAND_DIRECTION, "DIRECTION", 0, "Direction", ""}, | ||||
| {0, NULL, 0, NULL, NULL} | {0, NULL, 0, NULL, NULL} | ||||
| }; | }; | ||||
| static int curve_select_similar_cmp_fl(const float delta, const float thresh, const int compare) | static void curve_nurb_get_selected_type_in_tree(Nurb *nu, const int type, KDTree *tree) | ||||
| { | { | ||||
| switch (compare) { | float tree_entry[3] = {0.0f, 0.0f, 0.0f}; | ||||
| case SIM_CMP_EQ: | |||||
| return (fabsf(delta) <= thresh); | |||||
| case SIM_CMP_GT: | |||||
| return ((delta + thresh) >= 0.0f); | |||||
| case SIM_CMP_LT: | |||||
| return ((delta - thresh) <= 0.0f); | |||||
| default: | |||||
| BLI_assert(0); | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| static void curve_select_similar_direction__bezt(Nurb *nu, const float dir_ref[3], float angle_cos) | if (nu->type == CU_BEZIER) { | ||||
| { | |||||
| BezTriple *bezt; | BezTriple *bezt; | ||||
| int i; | int i; | ||||
| int tree_index = 0; | |||||
| for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { | for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { | ||||
| if (!bezt->hide) { | if (!bezt->hide && bezt->f1 & SELECT) { | ||||
| float dir[3]; | |||||
| BKE_nurb_bezt_calc_normal(nu, bezt, dir); | switch (type) { | ||||
| if (fabsf(dot_v3v3(dir_ref, dir)) >= angle_cos) { | case SIMCURHAND_RADIUS: | ||||
| select_beztriple(bezt, SELECT, SELECT, VISIBLE); | { | ||||
| float radius_ref = bezt->radius; | |||||
| tree_entry[0] = radius_ref; | |||||
| break; | |||||
| } | } | ||||
| case SIMCURHAND_WEIGHT: | |||||
| { | |||||
| float weight_ref = bezt->weight; | |||||
| tree_entry[0] = weight_ref; | |||||
| break; | |||||
| } | } | ||||
| case SIMCURHAND_DIRECTION: | |||||
| { | |||||
| BKE_nurb_bezt_calc_normal(nu, bezt, tree_entry); | |||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| BLI_kdtree_insert(tree, tree_index++, tree_entry); | |||||
| static void curve_select_similar_direction__bp(Nurb *nu, const float dir_ref[3], float angle_cos) | } | ||||
| { | } | ||||
| } | |||||
| else { | |||||
| BPoint *bp; | BPoint *bp; | ||||
| int i; | int i; | ||||
| int tree_index=0; | |||||
| for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | ||||
| if (!bp->hide) { | if (!bp->hide && bp->f1 & SELECT) { | ||||
| float dir[3]; | switch (type) { | ||||
| BKE_nurb_bpoint_calc_normal(nu, bp, dir); | case SIMCURHAND_RADIUS: | ||||
| if (fabsf(dot_v3v3(dir_ref, dir)) >= angle_cos) { | { | ||||
| select_bpoint(bp, SELECT, SELECT, VISIBLE); | float radius_ref = bp->radius; | ||||
| } | tree_entry[0] = radius_ref; | ||||
| } | break; | ||||
| } | |||||
| } | } | ||||
| case SIMCURHAND_WEIGHT: | |||||
| static bool curve_select_similar_direction(ListBase *editnurb, Curve *cu, float thresh) | |||||
| { | { | ||||
| Nurb *nu, *act_nu; | float weight_ref = bp->weight; | ||||
| void *act_vert; | tree_entry[0] = weight_ref; | ||||
| float dir[3]; | break; | ||||
| float angle_cos; | |||||
| if (!BKE_curve_nurb_vert_active_get(cu, &act_nu, &act_vert)) { | |||||
| return false; | |||||
| } | } | ||||
| case SIMCURHAND_DIRECTION: | |||||
| if (act_nu->type == CU_BEZIER) { | { | ||||
| BKE_nurb_bezt_calc_normal(act_nu, act_vert, dir); | BKE_nurb_bpoint_calc_normal(nu, bp, tree_entry); | ||||
| break; | |||||
| } | } | ||||
| else { | |||||
| BKE_nurb_bpoint_calc_normal(act_nu, act_vert, dir); | |||||
| } | } | ||||
| BLI_kdtree_insert(tree, tree_index++, tree_entry); | |||||
| /* map 0-1 to radians, 'cos' for comparison */ | |||||
| angle_cos = cosf(thresh * (float)M_PI_2); | |||||
| for (nu = editnurb->first; nu; nu = nu->next) { | |||||
| if (nu->type == CU_BEZIER) { | |||||
| curve_select_similar_direction__bezt(nu, dir, angle_cos); | |||||
| } | } | ||||
| else { | |||||
| curve_select_similar_direction__bp(nu, dir, angle_cos); | |||||
| } | } | ||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| static void curve_select_similar_radius__bezt(Nurb *nu, float radius_ref, int compare, float thresh) | static bool curve_nurb_select_similar_type(Nurb *nu, const int type, const KDTree *tree, const float thresh, const int compare) | ||||
| { | { | ||||
| bool changed = false; | |||||
| float tree_entry[3] = {0.0f, 0.0f, 0.0f}; | |||||
| if (nu->type == CU_BEZIER) { | |||||
| BezTriple *bezt; | BezTriple *bezt; | ||||
| int i; | int i; | ||||
| for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { | for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { | ||||
| if (!bezt->hide) { | if (!bezt->hide) { | ||||
| if (curve_select_similar_cmp_fl(bezt->radius - radius_ref, thresh, compare)) { | bool select = false; | ||||
| select_beztriple(bezt, SELECT, SELECT, VISIBLE); | |||||
| switch (type) { | |||||
| case SIMCURHAND_RADIUS: | |||||
| { | |||||
| float radius_ref = bezt->radius; | |||||
| tree_entry[0] = radius_ref; | |||||
| if (ED_select_similar_compare_float_tree(tree, radius_ref, thresh, compare)) { | |||||
| select = true; | |||||
| } | } | ||||
| break; | |||||
| } | } | ||||
| case SIMCURHAND_WEIGHT: | |||||
| { | |||||
| float weight_ref = bezt->weight; | |||||
| tree_entry[0] = weight_ref; | |||||
| if (ED_select_similar_compare_float_tree(tree, weight_ref, thresh, compare)) { | |||||
| select = true; | |||||
| } | } | ||||
| break; | |||||
| } | } | ||||
| case SIMCURHAND_DIRECTION: | |||||
| static void curve_select_similar_radius__bp(Nurb *nu, float radius_ref, int compare, float thresh) | |||||
| { | { | ||||
| BPoint *bp; | float dir[3]; | ||||
| int i; | BKE_nurb_bezt_calc_normal(nu, bezt, dir); | ||||
| float thresh_cos = cosf(thresh * (float)M_PI_2); | |||||
| for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | KDTreeNearest nearest; | ||||
| if (!bp->hide) { | if (BLI_kdtree_find_nearest(tree, dir, &nearest) != -1) { | ||||
| if (curve_select_similar_cmp_fl(bp->radius - radius_ref, thresh, compare)) { | float orient = angle_normalized_v3v3(dir, nearest.co); | ||||
| select_bpoint(bp, SELECT, SELECT, VISIBLE); | float delta = thresh_cos - fabsf(cosf(orient)); | ||||
| if (ED_select_similar_compare_float(delta, thresh, compare)) { | |||||
| select = true; | |||||
| } | } | ||||
| } | } | ||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| static bool curve_select_similar_radius(ListBase *editnurb, Curve *cu, float compare, float thresh) | if (select) { | ||||
| { | select_beztriple(bezt, SELECT, SELECT, VISIBLE); | ||||
| Nurb *nu, *act_nu; | changed = true; | ||||
| void *act_vert; | |||||
| float radius_ref; | |||||
| if (!BKE_curve_nurb_vert_active_get(cu, &act_nu, &act_vert)) { | |||||
| return false; | |||||
| } | } | ||||
| if (act_nu->type == CU_BEZIER) { | |||||
| radius_ref = ((BezTriple *)act_vert)->radius; | |||||
| } | } | ||||
| else { | |||||
| radius_ref = ((BPoint *)act_vert)->radius; | |||||
| } | } | ||||
| } | |||||
| else { | |||||
| BPoint *bp; | |||||
| int i; | |||||
| /* make relative */ | for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | ||||
| thresh *= radius_ref; | if (!bp->hide) { | ||||
| bool select = false; | |||||
| for (nu = editnurb->first; nu; nu = nu->next) { | switch (type) { | ||||
| if (nu->type == CU_BEZIER) { | case SIMCURHAND_RADIUS: | ||||
| curve_select_similar_radius__bezt(nu, radius_ref, compare, thresh); | { | ||||
| float radius_ref = bp->radius; | |||||
| tree_entry[0] = radius_ref; | |||||
| if (ED_select_similar_compare_float_tree(tree, radius_ref, thresh, compare)) { | |||||
| select = true; | |||||
| } | } | ||||
| else { | break; | ||||
| curve_select_similar_radius__bp(nu, radius_ref, compare, thresh); | |||||
| } | } | ||||
| case SIMCURHAND_WEIGHT: | |||||
| { | |||||
| float weight_ref = bp->weight; | |||||
| tree_entry[0] = weight_ref; | |||||
| if (ED_select_similar_compare_float_tree(tree, weight_ref, thresh, compare)) { | |||||
| select = true; | |||||
| } | } | ||||
| break; | |||||
| return true; | |||||
| } | } | ||||
| case SIMCURHAND_DIRECTION: | |||||
| static void curve_select_similar_weight__bezt(Nurb *nu, float weight_ref, int compare, float thresh) | |||||
| { | { | ||||
| BezTriple *bezt; | float dir[3]; | ||||
| int i; | BKE_nurb_bpoint_calc_normal(nu, bp, dir); | ||||
| /* Map 0-1 to radians, 'cos' for comparison. */ | |||||
| for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) { | float thresh_cos = cosf(thresh * (float)M_PI_2); | ||||
| if (!bezt->hide) { | KDTreeNearest nearest; | ||||
| if (curve_select_similar_cmp_fl(bezt->weight - weight_ref, thresh, compare)) { | if (BLI_kdtree_find_nearest(tree, dir, &nearest) != -1) { | ||||
| select_beztriple(bezt, SELECT, SELECT, VISIBLE); | float orient = angle_normalized_v3v3(dir, nearest.co); | ||||
| float delta = fabsf(cosf(orient)) - thresh_cos; | |||||
| if (ED_select_similar_compare_float(delta, thresh, compare)) { | |||||
| select = true; | |||||
| } | } | ||||
| } | } | ||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| static void curve_select_similar_weight__bp(Nurb *nu, float weight_ref, int compare, float thresh) | if (select) { | ||||
| { | |||||
| BPoint *bp; | |||||
| int i; | |||||
| for (i = nu->pntsu * nu->pntsv, bp = nu->bp; i--; bp++) { | |||||
| if (!bp->hide) { | |||||
| if (curve_select_similar_cmp_fl(bp->weight - weight_ref, thresh, compare)) { | |||||
| select_bpoint(bp, SELECT, SELECT, VISIBLE); | select_bpoint(bp, SELECT, SELECT, VISIBLE); | ||||
| changed = true; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return changed; | |||||
| } | |||||
| static bool curve_select_similar_weight(ListBase *editnurb, Curve *cu, float compare, float thresh) | static int curve_select_similar_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Nurb *nu, *act_nu; | /* Get props. */ | ||||
| void *act_vert; | const int optype = RNA_enum_get(op->ptr, "type"); | ||||
| float weight_ref; | const float thresh = RNA_float_get(op->ptr, "threshold"); | ||||
| const int compare = RNA_enum_get(op->ptr, "compare"); | |||||
| if (!BKE_curve_nurb_vert_active_get(cu, &act_nu, &act_vert)) | |||||
| return false; | |||||
| if (act_nu->type == CU_BEZIER) { | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| weight_ref = ((BezTriple *)act_vert)->weight; | View3D *v3d = CTX_wm_view3d(C); | ||||
| } | int tot_nurbs_selected_all = 0; | ||||
| else { | uint objects_len = 0; | ||||
| weight_ref = ((BPoint *)act_vert)->weight; | Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); | ||||
| } | bool changed_multi = false; | ||||
| for (nu = editnurb->first; nu; nu = nu->next) { | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| if (nu->type == CU_BEZIER) { | Object *obedit = objects[ob_index]; | ||||
| curve_select_similar_weight__bezt(nu, weight_ref, compare, thresh); | Curve *cu = obedit->data; | ||||
| } | tot_nurbs_selected_all += ED_curve_select_count(v3d, cu->editnurb); | ||||
| else { | |||||
| curve_select_similar_weight__bp(nu, weight_ref, compare, thresh); | |||||
| } | |||||
| } | } | ||||
| return true; | if (tot_nurbs_selected_all == 0) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No control point selected"); | |||||
| MEM_freeN(objects); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | } | ||||
| static bool curve_select_similar_type(ListBase *editnurb, Curve *cu) | KDTree *tree = NULL; | ||||
| { | short type_ref = 0; | ||||
| Nurb *nu, *act_nu; | |||||
| int type_ref; | |||||
| /* Get active nurb type */ | |||||
| act_nu = BKE_curve_nurb_active_get(cu); | |||||
| if (!act_nu) | switch (optype) { | ||||
| return false; | case SIMCURHAND_RADIUS: | ||||
| case SIMCURHAND_WEIGHT: | |||||
| case SIMCURHAND_DIRECTION: | |||||
| tree = BLI_kdtree_new(tot_nurbs_selected_all); | |||||
| break; | |||||
| } | |||||
| /* Get the active nurb type */ | /* Get type of selected control points. */ | ||||
| type_ref = act_nu->type; | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| Object *obedit = objects[ob_index]; | |||||
| Curve *cu = obedit->data; | |||||
| EditNurb *editnurb = cu->editnurb; | |||||
Not Done Inline ActionsComments should start with a capital letter and end with a full stop: dfelinto: Comments should start with a capital letter and end with a full stop:
`/* Get type of selected… | |||||
| for (nu = editnurb->first; nu; nu = nu->next) { | Nurb *nu; | ||||
| if (nu->type == type_ref) { | for (nu = editnurb->nurbs.first; nu; nu = nu->next) { | ||||
| ED_curve_nurb_select_all(nu); | if (!ED_curve_nurb_select_check(v3d, nu)) { | ||||
Not Done Inline ActionsDo a short break: if (!ED_curve...()) {
continue;
}dfelinto: Do a short break:
```
if (!ED_curve...()) {
continue;
}
``` | |||||
| continue; | |||||
| } | |||||
| switch (optype) { | |||||
| case SIMCURHAND_TYPE: | |||||
| { | |||||
| type_ref |= nu->type; | |||||
| break; | |||||
| } | |||||
| case SIMCURHAND_RADIUS: | |||||
| case SIMCURHAND_WEIGHT: | |||||
| case SIMCURHAND_DIRECTION: | |||||
| curve_nurb_get_selected_type_in_tree(nu, optype, tree); | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| return true; | if (tree != NULL) { | ||||
| BLI_kdtree_balance(tree); | |||||
| } | } | ||||
| static int curve_select_similar_exec(bContext *C, wmOperator *op) | /* Select control points with desired type. */ | ||||
| { | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = objects[ob_index]; | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| ListBase *editnurb = object_editcurve_get(obedit); | EditNurb *editnurb = cu->editnurb; | ||||
| bool changed = false; | bool changed = false; | ||||
| Nurb *nu; | |||||
| /* Get props */ | for (nu = editnurb->nurbs.first; nu; nu = nu->next) { | ||||
| const int type = RNA_enum_get(op->ptr, "type"); | switch (optype) { | ||||
| const float thresh = RNA_float_get(op->ptr, "threshold"); | |||||
| const int compare = RNA_enum_get(op->ptr, "compare"); | |||||
| switch (type) { | |||||
| case SIMCURHAND_TYPE: | case SIMCURHAND_TYPE: | ||||
| changed = curve_select_similar_type(editnurb, cu); | { | ||||
| if (nu->type & type_ref) { | |||||
| ED_curve_nurb_select_all(nu); | |||||
| changed = true; | |||||
| } | |||||
| break; | break; | ||||
| } | |||||
| case SIMCURHAND_RADIUS: | case SIMCURHAND_RADIUS: | ||||
| changed = curve_select_similar_radius(editnurb, cu, compare, thresh); | |||||
| break; | |||||
| case SIMCURHAND_WEIGHT: | case SIMCURHAND_WEIGHT: | ||||
| changed = curve_select_similar_weight(editnurb, cu, compare, thresh); | |||||
| break; | |||||
| case SIMCURHAND_DIRECTION: | case SIMCURHAND_DIRECTION: | ||||
| changed = curve_select_similar_direction(editnurb, cu, thresh); | changed = curve_nurb_select_similar_type(nu, optype, tree, thresh, compare); | ||||
| break; | break; | ||||
| } | } | ||||
| } | |||||
| if (changed) { | if (changed) { | ||||
| changed_multi = true; | |||||
| DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE); | DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE); | ||||
| WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | ||||
| return OPERATOR_FINISHED; | |||||
| } | } | ||||
| else { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | } | ||||
| MEM_freeN(objects); | |||||
| if (tree != NULL) { | |||||
| BLI_kdtree_free(tree); | |||||
| } | |||||
| return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | |||||
Not Done Inline ActionsNo need for the parenthesis around changed_multi. dfelinto: No need for the parenthesis around changed_multi. | |||||
| } | } | ||||
| void CURVE_OT_select_similar(wmOperatorType *ot) | void CURVE_OT_select_similar(wmOperatorType *ot) | ||||
Not Done Inline ActionsWhy to implement a _exec_multi? Why not just replace the _exec() function? dfelinto: Why to implement a _exec_multi? Why not just replace the _exec() function? | |||||
Not Done Inline Actionswill do with the final patch, just wanted to keep the original for reference zazizizou: will do with the final patch, just wanted to keep the original for reference | |||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Select Similar"; | ot->name = "Select Similar"; | ||||
| ot->idname = "CURVE_OT_select_similar"; | ot->idname = "CURVE_OT_select_similar"; | ||||
| ot->description = "Select similar curve points by property type"; | ot->description = "Select similar curve points by property type"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
Done Inline ActionsUse ELEM instead: dfelinto: Use ELEM instead:
if (ELEM, type, SIMCURHAND_RADIUS, SIMCURHAND_WEIGHT, ...)) | |||||
| ot->invoke = WM_menu_invoke; | ot->invoke = WM_menu_invoke; | ||||
| ot->exec = curve_select_similar_exec; | ot->exec = curve_select_similar_exec; | ||||
| ot->poll = ED_operator_editsurfcurve; | ot->poll = ED_operator_editsurfcurve; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| Show All 13 Lines | |||||
| static float curve_calc_dist_pair(const Nurb *nu, int a, int b) | static float curve_calc_dist_pair(const Nurb *nu, int a, int b) | ||||
| { | { | ||||
| const float *a_fl, *b_fl; | const float *a_fl, *b_fl; | ||||
| if (nu->type == CU_BEZIER) { | if (nu->type == CU_BEZIER) { | ||||
| a_fl = nu->bezt[a].vec[1]; | a_fl = nu->bezt[a].vec[1]; | ||||
| b_fl = nu->bezt[b].vec[1]; | b_fl = nu->bezt[b].vec[1]; | ||||
| } | } | ||||
Done Inline ActionsIt is overkill to use gset here if there is only two options. Use bitflags instead. dfelinto: It is overkill to use gset here if there is only two options. Use bitflags instead. | |||||
| else { | else { | ||||
| a_fl = nu->bp[a].vec; | a_fl = nu->bp[a].vec; | ||||
| b_fl = nu->bp[b].vec; | b_fl = nu->bp[b].vec; | ||||
| } | } | ||||
| return len_v3v3(a_fl, b_fl); | return len_v3v3(a_fl, b_fl); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst) | ||||
| } *data; | } *data; | ||||
| /* init connectivity data */ | /* init connectivity data */ | ||||
| data = MEM_mallocN(sizeof(*data) * vert_num, __func__); | data = MEM_mallocN(sizeof(*data) * vert_num, __func__); | ||||
| for (i = 0; i < vert_num; i++) { | for (i = 0; i < vert_num; i++) { | ||||
| data[i].vert = i; | data[i].vert = i; | ||||
| data[i].vert_prev = -1; | data[i].vert_prev = -1; | ||||
| data[i].cost = FLT_MAX; | data[i].cost = FLT_MAX; | ||||
| } | } | ||||
Done Inline ActionsNo need to actually count the changed ones. Just use a bool, like changed_multi. dfelinto: No need to actually count the changed ones. Just use a bool, like `changed_multi`. | |||||
| /* init heap */ | /* init heap */ | ||||
| heap = BLI_heap_new(); | heap = BLI_heap_new(); | ||||
| vert_curr = data[vert_src].vert; | vert_curr = data[vert_src].vert; | ||||
| BLI_heap_insert(heap, 0.0f, &data[vert_src].vert); | BLI_heap_insert(heap, 0.0f, &data[vert_src].vert); | ||||
| data[vert_src].cost = 0.0f; | data[vert_src].cost = 0.0f; | ||||
| data[vert_src].vert_prev = vert_src; /* nop */ | data[vert_src].vert_prev = vert_src; /* nop */ | ||||
| ▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines | |||||
Why is this not a static function? Are you planning to use this from a different file?