Blender V5.0
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.h"
19
20# include "BKE_curve.hh"
21
22# include "DEG_depsgraph.hh"
23
24static void rna_Curve_transform(Curve *cu, const float mat[16], bool shape_keys)
25{
26 BKE_curve_transform(cu, (const float (*)[4])mat, shape_keys, true);
27
28 DEG_id_tag_update(&cu->id, 0);
29}
30
31static void rna_Curve_update_gpu_tag(Curve *cu)
32{
34}
35
36static float rna_Nurb_calc_length(Nurb *nu, int resolution_u)
37{
38 return BKE_nurb_calc_length(nu, resolution_u);
39}
40
41static void rna_Nurb_valid_message(Nurb *nu, int direction, const char **r_result, int *result_len)
42{
43 const bool is_surf = nu->pntsv > 1;
44 const short type = nu->type;
45
46 int pnts;
47 short order, flag;
48 if (direction == 0) {
49 pnts = nu->pntsu;
50 order = nu->orderu;
51 flag = nu->flagu;
52 }
53 else {
54 pnts = nu->pntsv;
55 order = nu->orderv;
56 flag = nu->flagv;
57 }
58
59 char buf[64];
60 if (BKE_nurb_valid_message(pnts, order, flag, type, is_surf, direction, buf, sizeof(buf))) {
61 const int buf_len = strlen(buf);
62 *r_result = BLI_strdupn(buf, buf_len);
63 *result_len = buf_len;
64 }
65 else {
66 *r_result = nullptr;
67 *result_len = 0;
68 }
69}
70
71#else
72
74{
75 FunctionRNA *func;
76 PropertyRNA *parm;
77
78 func = RNA_def_function(srna, "transform", "rna_Curve_transform");
79 RNA_def_function_ui_description(func, "Transform curve by a matrix");
80 parm = RNA_def_float_matrix(func, "matrix", 4, 4, nullptr, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
82 RNA_def_boolean(func, "shape_keys", false, "", "Transform Shape Keys");
83
84 func = RNA_def_function(srna, "validate_material_indices", "BKE_curve_material_index_validate");
86 func,
87 "Validate material indices of splines or letters, return True when the curve "
88 "has had invalid indices corrected (to default 0)");
89 parm = RNA_def_boolean(func, "result", false, "Result", "");
90 RNA_def_function_return(func, parm);
91
92 RNA_def_function(srna, "update_gpu_tag", "rna_Curve_update_gpu_tag");
93}
94
96{
97 FunctionRNA *func;
98 PropertyRNA *parm;
99
100 func = RNA_def_function(srna, "calc_length", "rna_Nurb_calc_length");
101 RNA_def_function_ui_description(func, "Calculate spline length");
102 RNA_def_int(func,
103 "resolution",
104 0,
105 0,
106 1024,
107 "Resolution",
108 "Spline resolution to be used, 0 defaults to the resolution_u",
109 0,
110 64);
111 parm = RNA_def_float_distance(func,
112 "length",
113 0.0f,
114 0.0f,
115 FLT_MAX,
116 "Length",
117 "Length of the polygonaly approximated spline",
118 0.0f,
119 FLT_MAX);
120 RNA_def_function_return(func, parm);
121
122 func = RNA_def_function(srna, "valid_message", "rna_Nurb_valid_message");
123 RNA_def_function_ui_description(func, "Return the message");
124 parm = RNA_def_int(
125 func, "direction", 0, 0, 1, "Direction", "The direction where 0-1 maps to U-V", 0, 1);
127 /* return value */
128 parm = RNA_def_string(func,
129 "result",
130 "nothing",
131 64,
132 "Return value",
133 "The message or an empty string when there is no error");
134
137}
138
139#endif
void BKE_curve_batch_cache_dirty_tag(Curve *cu, int mode)
Definition curve.cc:5502
float BKE_nurb_calc_length(const Nurb *nu, int resolution)
Definition curve.cc:762
@ BKE_CURVE_BATCH_DIRTY_ALL
Definition BKE_curve.hh:379
void BKE_curve_transform(Curve *cu, const float mat[4][4], bool do_keys, bool do_props)
Definition curve.cc:5226
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:4722
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.cc:30
void DEG_id_tag_update(ID *id, unsigned int flags)
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ PARM_OUTPUT
Definition RNA_types.hh:546
PropertyFlag
Definition RNA_types.hh:300
@ PROP_DYNAMIC
Definition RNA_types.hh:428
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
void RNA_api_curve_nurb(StructRNA *srna)
void RNA_api_curve(StructRNA *srna)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
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_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)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
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)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
#define FLT_MAX
Definition stdcycles.h:14
short flagu
short orderu
short orderv
short type
short flagv
uint8_t flag
Definition wm_window.cc:145