Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/curve/editcurve_select.c
| Show First 20 Lines • Show All 211 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; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| bool ED_curve_select_check(View3D *v3d, struct EditNurb *editnurb) | bool ED_curve_select_check(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… | |||||
| { | { | ||||
| Nurb *nu; | Nurb *nu; | ||||
Done Inline ActionsCode style, loose this extra line. dfelinto: Code style, loose this extra line. | |||||
| 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; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| ▲ Show 20 Lines • Show All 1,197 Lines • ▼ Show 20 Lines | if (!bezt->hide) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void curve_select_similar_weight__bp(Nurb *nu, float weight_ref, int compare, float thresh) | static void curve_select_similar_weight__bp(Nurb *nu, float weight_ref, int compare, float thresh) | ||||
| { | { | ||||
| BPoint *bp; | BPoint *bp; | ||||
| int i; | int i; | ||||
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 (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) { | ||||
| if (curve_select_similar_cmp_fl(bp->weight - weight_ref, thresh, compare)) { | if (curve_select_similar_cmp_fl(bp->weight - weight_ref, thresh, compare)) { | ||||
| select_bpoint(bp, SELECT, SELECT, VISIBLE); | select_bpoint(bp, SELECT, SELECT, VISIBLE); | ||||
| } | } | ||||
| } | } | ||||
Not Done Inline ActionsDo a short break: if (!ED_curve...()) {
continue;
}dfelinto: Do a short break:
```
if (!ED_curve...()) {
continue;
}
``` | |||||
| } | } | ||||
| } | } | ||||
| static bool curve_select_similar_weight(ListBase *editnurb, Curve *cu, float compare, float thresh) | static bool curve_select_similar_weight(ListBase *editnurb, Curve *cu, float compare, float thresh) | ||||
| { | { | ||||
| Nurb *nu, *act_nu; | Nurb *nu, *act_nu; | ||||
| void *act_vert; | void *act_vert; | ||||
| float weight_ref; | float weight_ref; | ||||
| Show All 40 Lines | for (nu = editnurb->first; nu; nu = nu->next) { | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int curve_select_similar_exec(bContext *C, wmOperator *op) | static int curve_select_similar_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *obedit = CTX_data_edit_object(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Curve *cu = obedit->data; | View3D *v3d = CTX_wm_view3d(C); | ||||
| ListBase *editnurb = object_editcurve_get(obedit); | uint objects_len = 0; | ||||
| bool changed = false; | Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); | ||||
| int changed_tot = 0; | |||||
| /* Get props */ | /* Get props */ | ||||
| const int type = RNA_enum_get(op->ptr, "type"); | const int type = RNA_enum_get(op->ptr, "type"); | ||||
| const float thresh = RNA_float_get(op->ptr, "threshold"); | const float thresh = RNA_float_get(op->ptr, "threshold"); | ||||
| const int compare = RNA_enum_get(op->ptr, "compare"); | const int compare = RNA_enum_get(op->ptr, "compare"); | ||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | |||||
| Object *obedit = objects[ob_index]; | |||||
| ListBase *editnurb = object_editcurve_get(obedit); | |||||
| Curve *cu = obedit->data; | |||||
| bool changed = false; | |||||
| if (!ED_curve_select_check(v3d, cu->editnurb)) { | |||||
| continue; | |||||
| } | |||||
| switch (type) { | switch (type) { | ||||
| case SIMCURHAND_TYPE: | case SIMCURHAND_TYPE: | ||||
| changed = curve_select_similar_type(editnurb, cu); | changed = curve_select_similar_type(editnurb, cu); | ||||
| break; | break; | ||||
| case SIMCURHAND_RADIUS: | case SIMCURHAND_RADIUS: | ||||
| changed = curve_select_similar_radius(editnurb, cu, compare, thresh); | changed = curve_select_similar_radius(editnurb, cu, compare, thresh); | ||||
| break; | break; | ||||
| case SIMCURHAND_WEIGHT: | case SIMCURHAND_WEIGHT: | ||||
| changed = curve_select_similar_weight(editnurb, cu, compare, thresh); | changed = curve_select_similar_weight(editnurb, cu, compare, thresh); | ||||
| break; | break; | ||||
| case SIMCURHAND_DIRECTION: | case SIMCURHAND_DIRECTION: | ||||
| changed = curve_select_similar_direction(editnurb, cu, thresh); | changed = curve_select_similar_direction(editnurb, cu, thresh); | ||||
| break; | break; | ||||
| } | } | ||||
| if (changed) { | if (changed) { | ||||
| changed_tot++; | |||||
| 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 { | } | ||||
Not Done Inline ActionsNo need for the parenthesis around changed_multi. dfelinto: No need for the parenthesis around changed_multi. | |||||
| MEM_freeN(objects); | |||||
| if (changed_tot == 0) { | |||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| } | } | ||||
| 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?