Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curve.cc
| Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
| using blender::float3; | using blender::float3; | ||||
| using blender::IndexRange; | using blender::IndexRange; | ||||
| /* globals */ | /* globals */ | ||||
| /* local */ | /* local */ | ||||
| // static CLG_LogRef LOG = {"bke.curve"}; | // static CLG_LogRef LOG = {"bke.curve"}; | ||||
| enum class NURBSValidationStatus { | |||||
| Valid, | |||||
| AtLeastTwoCpsRequired, | |||||
| MoreCpsThanOrderRequired, | |||||
| MoreRowsForBezierRequired, | |||||
| MorePointsForBezierRequired | |||||
| }; | |||||
| static void curve_init_data(ID *id) | static void curve_init_data(ID *id) | ||||
| { | { | ||||
| Curve *curve = (Curve *)id; | Curve *curve = (Curve *)id; | ||||
| BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(curve, id)); | BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(curve, id)); | ||||
| MEMCPY_STRUCT_AFTER(curve, DNA_struct_default_get(Curve), id); | MEMCPY_STRUCT_AFTER(curve, DNA_struct_default_get(Curve), id); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 4,622 Lines • ▼ Show 20 Lines | else { | ||||
| bp->tilt = key[3]; | bp->tilt = key[3]; | ||||
| bp->radius = key[4]; | bp->radius = key[4]; | ||||
| key += KEYELEM_FLOAT_LEN_BPOINT; | key += KEYELEM_FLOAT_LEN_BPOINT; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| bool BKE_nurb_valid_message(const int pnts, | static NURBSValidationStatus nurb_check_valid(const int pnts, | ||||
| const short order, | const short order, | ||||
| const short flag, | const short flag, | ||||
| const short type, | const short type, | ||||
| const bool is_surf, | const bool is_surf, | ||||
| const char *dir, | int *r_points_needed) | ||||
campbellbarton: Return args should use `r_` prefix. | |||||
| char *message_dst, | |||||
| const size_t maxncpy) | |||||
| { | { | ||||
| const char *msg_template = ""; | |||||
| uint16_t points_needed = 0; | |||||
| if (pnts <= 1) { | if (pnts <= 1) { | ||||
| msg_template = TIP_("At least two points required."); | return NURBSValidationStatus::AtLeastTwoCpsRequired; | ||||
| } | } | ||||
| else if (type == CU_NURBS) { | else if (type == CU_NURBS) { | ||||
| if (pnts < order) { | if (pnts < order) { | ||||
| msg_template = TIP_("Must have more control points than Order"); | return NURBSValidationStatus::MoreCpsThanOrderRequired; | ||||
| } | } | ||||
| else if (flag & CU_NURB_BEZIER) { | else if (flag & CU_NURB_BEZIER) { | ||||
| int points_needed = 0; | |||||
| if (flag & CU_NURB_CYCLIC) { | if (flag & CU_NURB_CYCLIC) { | ||||
| const uint16_t remainder = pnts % (order - 1); | const int remainder = pnts % (order - 1); | ||||
| points_needed = remainder > 0 ? order - 1 - remainder : 0; | points_needed = remainder > 0 ? order - 1 - remainder : 0; | ||||
| } | } | ||||
| else if (((flag & CU_NURB_ENDPOINT) == 0) && pnts <= order) { | else if (((flag & CU_NURB_ENDPOINT) == 0) && pnts <= order) { | ||||
| points_needed = order + 1 - pnts; | points_needed = order + 1 - pnts; | ||||
| } | } | ||||
| if (points_needed) { | if (points_needed) { | ||||
| msg_template = is_surf ? TIP_("%d more %s row(s) needed for Bezier") : | *r_points_needed = points_needed; | ||||
| TIP_("%d more point(s) needed for Bezier"); | return is_surf ? NURBSValidationStatus::MoreRowsForBezierRequired : | ||||
| NURBSValidationStatus::MorePointsForBezierRequired; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| return NURBSValidationStatus::Valid; | |||||
| } | } | ||||
| if (message_dst) { | bool BKE_nurb_valid_message(const int pnts, | ||||
| BLI_snprintf(message_dst, maxncpy, msg_template, points_needed, dir); | const short order, | ||||
| const short flag, | |||||
| const short type, | |||||
| const bool is_surf, | |||||
| const int dir, | |||||
| char *message_dst, | |||||
| const size_t maxncpy) | |||||
| { | |||||
| int points_needed; | |||||
| NURBSValidationStatus status = nurb_check_valid( | |||||
| pnts, order, flag, type, is_surf, &points_needed); | |||||
| const char *msg_template = nullptr; | |||||
| switch (status) { | |||||
| case NURBSValidationStatus::Valid: | |||||
| message_dst[0] = 0; | |||||
| return false; | |||||
| case NURBSValidationStatus::AtLeastTwoCpsRequired: | |||||
| if (dir == 1) { | |||||
| /* Exception made for curves as their pntsv == 1. */ | |||||
| message_dst[0] = 0; | |||||
| return false; | |||||
| } | |||||
| msg_template = TIP_("At least two points required."); | |||||
| break; | |||||
| case NURBSValidationStatus::MoreCpsThanOrderRequired: | |||||
| msg_template = TIP_("Must have more control points than Order"); | |||||
| break; | |||||
| case NURBSValidationStatus::MoreRowsForBezierRequired: | |||||
| msg_template = TIP_("%d more %s row(s) needed for Bezier"); | |||||
| break; | |||||
| case NURBSValidationStatus::MorePointsForBezierRequired: | |||||
| msg_template = TIP_("%d more point(s) needed for Bezier"); | |||||
| break; | |||||
Not Done Inline ActionsThis can be NULL. campbellbarton: This can be `NULL`. | |||||
| } | } | ||||
| return msg_template[0]; | |||||
| BLI_snprintf(message_dst, maxncpy, msg_template, points_needed, dir == 0 ? "U" : "V"); | |||||
| return true; | |||||
| } | } | ||||
| bool BKE_nurb_check_valid_u(const Nurb *nu) | bool BKE_nurb_check_valid_u(const Nurb *nu) | ||||
| { | { | ||||
| return !BKE_nurb_valid_message( | int points_needed; | ||||
| nu->pntsu, nu->orderu, nu->flagu, nu->type, nu->pntsv > 1, "U", nullptr, 0); | return NURBSValidationStatus::Valid == | ||||
| nurb_check_valid( | |||||
| nu->pntsu, nu->orderu, nu->flagu, nu->type, nu->pntsv > 1, &points_needed); | |||||
Not Done Inline ActionsUnless there's a specific reason to use a 16 bit unsigned integer, the style guide prefers sticking with int. HooglyBoogly: Unless there's a specific reason to use a 16 bit unsigned integer, the [[ https://wiki.blender. | |||||
| } | } | ||||
| bool BKE_nurb_check_valid_v(const Nurb *nu) | bool BKE_nurb_check_valid_v(const Nurb *nu) | ||||
| { | { | ||||
| return !BKE_nurb_valid_message( | int points_needed; | ||||
| nu->pntsv, nu->orderv, nu->flagv, nu->type, nu->pntsv > 1, "V", nullptr, 0); | return NURBSValidationStatus::Valid == | ||||
| nurb_check_valid( | |||||
| nu->pntsv, nu->orderv, nu->flagv, nu->type, nu->pntsv > 1, &points_needed); | |||||
| } | } | ||||
| bool BKE_nurb_check_valid_uv(const Nurb *nu) | bool BKE_nurb_check_valid_uv(const Nurb *nu) | ||||
| { | { | ||||
| if (!BKE_nurb_check_valid_u(nu)) { | if (!BKE_nurb_check_valid_u(nu)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if ((nu->pntsv > 1) && !BKE_nurb_check_valid_v(nu)) { | if ((nu->pntsv > 1) && !BKE_nurb_check_valid_v(nu)) { | ||||
| ▲ Show 20 Lines • Show All 729 Lines • Show Last 20 Lines | |||||
Return args should use r_ prefix.