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; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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,227 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 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | case SIMCURHAND_RADIUS: | ||||
| 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; | ||||
| } | } | ||||
Not Done Inline ActionsNo need for the parenthesis around changed_multi. dfelinto: No need for the parenthesis around changed_multi. | |||||
| if (changed) { | if (changed) { | ||||
| 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; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| static int curve_select_similar_exec_multi(bContext *C, wmOperator *op) | |||||
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 | |||||
| { | |||||
| /* Get props */ | |||||
| const int op_type = RNA_enum_get(op->ptr, "type"); | |||||
| const float thresh = RNA_float_get(op->ptr, "threshold"); | |||||
| const int compare = RNA_enum_get(op->ptr, "compare"); | |||||
Done Inline ActionsUse ELEM instead: dfelinto: Use ELEM instead:
if (ELEM, type, SIMCURHAND_RADIUS, SIMCURHAND_WEIGHT, ...)) | |||||
| if (ELEM (op_type, SIMCURHAND_RADIUS, SIMCURHAND_WEIGHT, SIMCURHAND_DIRECTION)) | |||||
| { | |||||
| BKE_report(op->reports, RPT_ERROR, "type not supported at the moment."); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| int tot_nurbs_selected_all = 0; | |||||
| uint objects_len = 0; | |||||
| Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); | |||||
| bool changed_multi = false; | |||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | |||||
| Object *obedit = objects[ob_index]; | |||||
| Curve *cu = obedit->data; | |||||
| tot_nurbs_selected_all += ED_curve_select_count(v3d, cu->editnurb); | |||||
| } | |||||
| if (tot_nurbs_selected_all == 0) { | |||||
| BKE_report(op->reports, RPT_ERROR, "No control point selected"); | |||||
| MEM_freeN(objects); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| GSet *gset = NULL; | |||||
| short ref_type = 0; | |||||
| switch (op_type) { | |||||
| case SIMCURHAND_TYPE: | |||||
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. | |||||
| break; | |||||
| case SIMCURHAND_RADIUS: | |||||
| /* TODO */ | |||||
| break; | |||||
| case SIMCURHAND_WEIGHT: | |||||
| /* TODO */ | |||||
| break; | |||||
| case SIMCURHAND_DIRECTION: | |||||
| /* TODO: e.g. init KDTree*/ | |||||
| break; | |||||
| } | |||||
| /* get type of selected control points */ | |||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | |||||
| Object *obedit = objects[ob_index]; | |||||
| ListBase *editnurb = object_editcurve_get(obedit); | |||||
| Nurb *nu; | |||||
| for (nu = editnurb->first; nu; nu = nu->next) { | |||||
| if (ED_curve_nurb_select_check(v3d, nu)) { | |||||
| switch (op_type) { | |||||
| case SIMCURHAND_TYPE: | |||||
| { | |||||
| ref_type |= nu->type; | |||||
| break; | |||||
| } | |||||
| case SIMCURHAND_RADIUS: | |||||
| /* TODO */ | |||||
| break; | |||||
| case SIMCURHAND_WEIGHT: | |||||
| /* TODO */ | |||||
| break; | |||||
| case SIMCURHAND_DIRECTION: | |||||
| /* TODO */ | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| /* select control points with desired type */ | |||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | |||||
| Object *obedit = objects[ob_index]; | |||||
| ListBase *editnurb = object_editcurve_get(obedit); | |||||
| bool changed = false; | |||||
| Nurb *nu; | |||||
| BPoint *bp; | |||||
| BezTriple *bezt; | |||||
| for (nu = editnurb->first; nu; nu = nu->next) { | |||||
| switch (op_type) { | |||||
| case SIMCURHAND_TYPE: | |||||
| { | |||||
| if (nu->type & ref_type) { | |||||
| changed = true; | |||||
| ED_curve_nurb_select_all(nu); | |||||
| break; | |||||
| } | |||||
| } | |||||
| case SIMCURHAND_RADIUS: | |||||
| /* TODO */ | |||||
| break; | |||||
| case SIMCURHAND_WEIGHT: | |||||
| /* TODO */ | |||||
| break; | |||||
| case SIMCURHAND_DIRECTION: | |||||
| /* TODO */ | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (changed) { | |||||
| changed_multi = true; | |||||
| DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE); | |||||
| WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | |||||
| } | |||||
| } | |||||
| MEM_freeN(objects); | |||||
| if (gset != NULL) { | |||||
| BLI_gset_free(gset, NULL); | |||||
| } | |||||
| return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | |||||
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`. | |||||
| } | |||||
| void CURVE_OT_select_similar(wmOperatorType *ot) | void CURVE_OT_select_similar(wmOperatorType *ot) | ||||
| { | { | ||||
| /* 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 */ | ||||
| ot->invoke = WM_menu_invoke; | ot->invoke = WM_menu_invoke; | ||||
| ot->exec = curve_select_similar_exec; | ot->exec = curve_select_similar_exec_multi; | ||||
| 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 */ | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", curve_prop_similar_types, SIMCURHAND_WEIGHT, "Type", ""); | ot->prop = RNA_def_enum(ot->srna, "type", curve_prop_similar_types, SIMCURHAND_WEIGHT, "Type", ""); | ||||
| RNA_def_enum(ot->srna, "compare", curve_prop_similar_compare_types, SIM_CMP_EQ, "Compare", ""); | RNA_def_enum(ot->srna, "compare", curve_prop_similar_compare_types, SIM_CMP_EQ, "Compare", ""); | ||||
| ▲ Show 20 Lines • Show All 243 Lines • Show Last 20 Lines | |||||
Why is this not a static function? Are you planning to use this from a different file?