Blender V5.3
rna_curve_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "RNA_define.hh"
12
13#include "rna_internal.hh" /* own include */
14
15#ifdef RNA_RUNTIME
16# include "DNA_curve_types.h"
17
18# include "BLI_string.hh"
19
20# include "BKE_curve.hh"
21
22# include "DEG_depsgraph.hh"
23
24namespace blender {
25
26static void rna_Curve_transform(Curve *cu, const float mat[16], bool shape_keys)
27{
28 BKE_curve_transform(cu, reinterpret_cast<const float (*)[4]>(mat), shape_keys, true);
29
30 DEG_id_tag_update(&cu->id, 0);
31}
32
33static void rna_Curve_update_gpu_tag(Curve *cu)
34{
36}
37
38static float rna_Nurb_calc_length(Nurb *nu, int resolution_u)
39{
40 return BKE_nurb_calc_length(nu, resolution_u);
41}
42
43static void rna_Nurb_valid_message(Nurb *nu, int direction, const char **r_result, int *result_len)
44{
45 const bool is_surf = nu->pntsv > 1;
46 const short type = nu->type;
47
48 int pnts;
49 short order, flag;
50 if (direction == 0) {
51 pnts = nu->pntsu;
52 order = nu->orderu;
53 flag = nu->flagu;
54 }
55 else {
56 pnts = nu->pntsv;
57 order = nu->orderv;
58 flag = nu->flagv;
59 }
60
61 char buf[64];
62 if (BKE_nurb_valid_message(pnts, order, flag, type, is_surf, direction, buf, sizeof(buf))) {
63 const int buf_len = strlen(buf);
64 *r_result = BLI_strdupn(buf, buf_len);
65 *result_len = buf_len;
66 }
67 else {
68 *r_result = nullptr;
69 *result_len = 0;
70 }
71}
72
73} // namespace blender
74
75#else
76
77namespace blender {
78
80{
81 FunctionRNA *func;
82 PropertyRNA *parm;
83
84 func = RNA_def_function(srna, "transform", "rna_Curve_transform");
85 RNA_def_function_ui_description(func, "Transform curve by a matrix");
86 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
88 RNA_def_boolean(func, "shape_keys", false, "", "Transform Shape Keys");
89
90 func = RNA_def_function(srna, "validate_material_indices", "BKE_curve_material_index_validate");
92 func,
93 "Validate material indices of splines or letters, return True when the curve "
94 "has had invalid indices corrected (to default 0)");
95 parm = RNA_def_boolean(func, "result", false, "Result", "");
96 RNA_def_function_return(func, parm);
97
98 RNA_def_function(srna, "update_gpu_tag", "rna_Curve_update_gpu_tag");
99}
100
102{
103 FunctionRNA *func;
104 PropertyRNA *parm;
105
106 func = RNA_def_function(srna, "calc_length", "rna_Nurb_calc_length");
107 RNA_def_function_ui_description(func, "Calculate spline length");
108 RNA_def_int(func,
109 "resolution",
110 0,
111 0,
112 1024,
113 "Resolution",
114 "Spline resolution to be used, 0 defaults to the resolution_u",
115 0,
116 64);
117 parm = RNA_def_float_distance(func,
118 "length",
119 0.0f,
120 0.0f,
121 FLT_MAX,
122 "Length",
123 "Length of the polygonally approximated spline",
124 0.0f,
125 FLT_MAX);
126 RNA_def_function_return(func, parm);
127
128 func = RNA_def_function(srna, "valid_message", "rna_Nurb_valid_message");
129 RNA_def_function_ui_description(func, "Return the message");
130 parm = RNA_def_int(
131 func, "direction", 0, 0, 1, "Direction", "The direction where 0-1 maps to U-V", 0, 1);
133 /* return value */
134 parm = RNA_def_string(func,
135 "result",
136 "nothing",
137 64,
138 "Return value",
139 "The message or an empty string when there is no error");
140
143}
144
145} // namespace blender
146
147#endif
#define FLT_MAX
BMesh Iterators.
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
@ BKE_CURVE_BATCH_DIRTY_ALL
Definition BKE_curve.hh:387
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void BKE_curve_batch_cache_dirty_tag(Curve *cu, int mode)
Definition curve.cc:5536
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_curve_transform(Curve *cu, const float mat[4][4], bool do_keys, bool do_props)
Definition curve.cc:5260
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void DEG_id_tag_update(ID *id, unsigned int flags)
void RNA_api_curve(StructRNA *srna)
bool BKE_nurb_valid_message(int pnts, short order, short flag, short type, bool is_surf, int dir, char *message_dst, size_t maxncpy)
Definition curve.cc:4756
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
PropertyRNA * RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, const int rows, const int columns, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_OUTPUT
Definition RNA_types.hh:632
void RNA_api_curve_nurb(StructRNA *srna)
float BKE_nurb_calc_length(const Nurb *nu, int resolution)
Definition curve.cc:785