Blender V4.3
rna_curveprofile.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdio>
10#include <cstdlib>
11
12#include "DNA_curve_types.h"
14
15#include "RNA_define.hh"
16#include "rna_internal.hh"
17
18#include "BLT_translation.hh"
19
20#include "WM_api.hh"
21#include "WM_types.hh"
22
23#ifdef RNA_RUNTIME
24
25# include "RNA_access.hh"
26
27# include "BKE_curveprofile.h"
28
33static void rna_CurveProfilePoint_handle_type_set(PointerRNA *ptr, int value)
34{
35 CurveProfilePoint *point = static_cast<CurveProfilePoint *>(ptr->data);
36 CurveProfile *profile = point->profile;
37
38 if (profile) {
39 BKE_curveprofile_selected_handle_set(profile, value, value);
42 }
43}
44
45static void rna_CurveProfile_clip_set(PointerRNA *ptr, bool value)
46{
47 CurveProfile *profile = (CurveProfile *)ptr->data;
48
49 if (value) {
50 profile->flag |= PROF_USE_CLIP;
51 }
52 else {
53 profile->flag &= ~PROF_USE_CLIP;
54 }
55
57}
58
59static void rna_CurveProfile_sample_straight_set(PointerRNA *ptr, bool value)
60{
61 CurveProfile *profile = (CurveProfile *)ptr->data;
62
63 if (value) {
64 profile->flag |= PROF_SAMPLE_STRAIGHT_EDGES;
65 }
66 else {
67 profile->flag &= ~PROF_SAMPLE_STRAIGHT_EDGES;
68 }
69
71}
72
73static void rna_CurveProfile_sample_even_set(PointerRNA *ptr, bool value)
74{
75 CurveProfile *profile = (CurveProfile *)ptr->data;
76
77 if (value) {
78 profile->flag |= PROF_SAMPLE_EVEN_LENGTHS;
79 }
80 else {
81 profile->flag &= ~PROF_SAMPLE_EVEN_LENGTHS;
82 }
83
85}
86
87static void rna_CurveProfile_remove_point(CurveProfile *profile,
88 ReportList *reports,
89 PointerRNA *point_ptr)
90{
91 CurveProfilePoint *point = static_cast<CurveProfilePoint *>(point_ptr->data);
92 if (BKE_curveprofile_remove_point(profile, point) == false) {
93 BKE_report(reports, RPT_ERROR, "Unable to remove path point");
94 return;
95 }
96
97 RNA_POINTER_INVALIDATE(point_ptr);
98}
99
100static void rna_CurveProfile_evaluate(CurveProfile *profile,
101 ReportList *reports,
102 float length_portion,
103 float location[2])
104{
105 if (!profile->table) {
106 BKE_report(reports, RPT_ERROR, "CurveProfile table not initialized, call initialize()");
107 }
108 BKE_curveprofile_evaluate_length_portion(profile, length_portion, &location[0], &location[1]);
109}
110
111static void rna_CurveProfile_initialize(CurveProfile *profile, int segments_len)
112{
113 BKE_curveprofile_init(profile, short(segments_len));
114}
115
116static void rna_CurveProfile_update(CurveProfile *profile)
117{
119}
120
121#else
122
124 {HD_AUTO, "AUTO", ICON_HANDLE_AUTO, "Auto Handle", ""},
125 {HD_VECT, "VECTOR", ICON_HANDLE_VECTOR, "Vector Handle", ""},
126 {HD_FREE, "FREE", ICON_HANDLE_FREE, "Free Handle", ""},
127 {HD_ALIGN, "ALIGN", ICON_HANDLE_ALIGNED, "Aligned Free Handles", ""},
128 {0, nullptr, 0, nullptr, nullptr},
129};
130
132{
133 StructRNA *srna;
134 PropertyRNA *prop;
135
136 srna = RNA_def_struct(brna, "CurveProfilePoint", nullptr);
137 RNA_def_struct_ui_text(srna, "CurveProfilePoint", "Point of a path used to define a profile");
138
139 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
140 RNA_def_property_float_sdna(prop, nullptr, "x");
141 RNA_def_property_array(prop, 2);
142 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the path point");
143
144 prop = RNA_def_property(srna, "handle_type_1", PROP_ENUM, PROP_NONE);
145 RNA_def_property_enum_sdna(prop, nullptr, "h1");
147 RNA_def_property_enum_funcs(prop, nullptr, "rna_CurveProfilePoint_handle_type_set", nullptr);
148 RNA_def_property_ui_text(prop, "First Handle Type", "Path interpolation at this point");
149
150 prop = RNA_def_property(srna, "handle_type_2", PROP_ENUM, PROP_NONE);
151 RNA_def_property_enum_sdna(prop, nullptr, "h2");
153 RNA_def_property_enum_funcs(prop, nullptr, "rna_CurveProfilePoint_handle_type_set", nullptr);
154 RNA_def_property_ui_text(prop, "Second Handle Type", "Path interpolation at this point");
155
156 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
157 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PROF_SELECT);
158 RNA_def_property_ui_text(prop, "Select", "Selection state of the path point");
159}
160
162{
163 StructRNA *srna;
164 PropertyRNA *parm;
165 FunctionRNA *func;
166
167 RNA_def_property_srna(cprop, "CurveProfilePoints");
168 srna = RNA_def_struct(brna, "CurveProfilePoints", nullptr);
169 RNA_def_struct_sdna(srna, "CurveProfile");
170 RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points");
171
172 func = RNA_def_function(srna, "add", "BKE_curveprofile_insert");
173 RNA_def_function_ui_description(func, "Add point to the profile");
174 parm = RNA_def_float(func,
175 "x",
176 0.0f,
177 -FLT_MAX,
178 FLT_MAX,
179 "X Position",
180 "X Position for new point",
181 -FLT_MAX,
182 FLT_MAX);
184 parm = RNA_def_float(func,
185 "y",
186 0.0f,
187 -FLT_MAX,
188 FLT_MAX,
189 "Y Position",
190 "Y Position for new point",
191 -FLT_MAX,
192 FLT_MAX);
194 parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "New point");
195 RNA_def_function_return(func, parm);
196
197 func = RNA_def_function(srna, "remove", "rna_CurveProfile_remove_point");
199 RNA_def_function_ui_description(func, "Delete point from the profile");
200 parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "Point to remove");
203}
204
206{
207 StructRNA *srna;
208 PropertyRNA *prop;
209 PropertyRNA *parm;
210 FunctionRNA *func;
211
212 static const EnumPropertyItem rna_enum_curveprofile_preset_items[] = {
213 {PROF_PRESET_LINE, "LINE", 0, "Line", "Default"},
214 {PROF_PRESET_SUPPORTS, "SUPPORTS", 0, "Support Loops", "Loops on each side of the profile"},
215 {PROF_PRESET_CORNICE, "CORNICE", 0, "Cornice Molding", ""},
216 {PROF_PRESET_CROWN, "CROWN", 0, "Crown Molding", ""},
217 {PROF_PRESET_STEPS, "STEPS", 0, "Steps", "A number of steps defined by the segments"},
218 {0, nullptr, 0, nullptr, nullptr},
219 };
220
221 srna = RNA_def_struct(brna, "CurveProfile", nullptr);
222 RNA_def_struct_ui_text(srna, "CurveProfile", "Profile Path editor used to build a profile path");
223
224 prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE);
225 RNA_def_property_enum_sdna(prop, nullptr, "preset");
226 RNA_def_property_enum_items(prop, rna_enum_curveprofile_preset_items);
228 RNA_def_property_ui_text(prop, "Preset", "");
229
230 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
231 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PROF_USE_CLIP);
232 RNA_def_property_ui_text(prop, "Clip", "Force the path view to fit a defined boundary");
233 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_clip_set");
234
235 prop = RNA_def_property(srna, "use_sample_straight_edges", PROP_BOOLEAN, PROP_NONE);
237 RNA_def_property_ui_text(prop, "Sample Straight Edges", "Sample edges with vector handles");
238 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_sample_straight_set");
239
240 prop = RNA_def_property(srna, "use_sample_even_lengths", PROP_BOOLEAN, PROP_NONE);
242 RNA_def_property_ui_text(prop, "Sample Even Lengths", "Sample edges with even lengths");
243 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_sample_even_set");
244
245 func = RNA_def_function(srna, "update", "rna_CurveProfile_update");
246 RNA_def_function_ui_description(func, "Refresh internal data, remove doubles and clip points");
247
248 func = RNA_def_function(srna, "reset_view", "BKE_curveprofile_reset_view");
249 RNA_def_function_ui_description(func, "Reset the curve profile grid to its clipping size");
250
251 func = RNA_def_function(srna, "initialize", "rna_CurveProfile_initialize");
252 parm = RNA_def_int(func,
253 "totsegments",
254 1,
255 1,
256 1000,
257 "",
258 "The number of segment values to"
259 " initialize the segments table with",
260 1,
261 100);
263 RNA_def_function_ui_description(func, "Set the number of display segments and fill tables");
264
265 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
266 RNA_def_property_collection_sdna(prop, nullptr, "path", "path_len");
267 RNA_def_property_struct_type(prop, "CurveProfilePoint");
268 RNA_def_property_ui_text(prop, "Points", "Profile control points");
270
271 prop = RNA_def_property(srna, "segments", PROP_COLLECTION, PROP_NONE);
272 RNA_def_property_collection_sdna(prop, nullptr, "segments", "segments_len");
273 RNA_def_property_struct_type(prop, "CurveProfilePoint");
274 RNA_def_property_ui_text(prop, "Segments", "Segments sampled from control points");
275
276 func = RNA_def_function(srna, "evaluate", "rna_CurveProfile_evaluate");
278 RNA_def_function_ui_description(func, "Evaluate the at the given portion of the path length");
279 parm = RNA_def_float(func,
280 "length_portion",
281 0.0f,
282 0.0f,
283 1.0f,
284 "Length Portion",
285 "Portion of the path length to travel before evaluation",
286 0.0f,
287 1.0f);
289 parm = RNA_def_float_vector(func,
290 "location",
291 2,
292 nullptr,
293 -100.0f,
294 100.0f,
295 "Location",
296 "The location at the given portion of the profile",
297 -100.0f,
298 100.0f);
299 RNA_def_function_output(func, parm);
300}
301
307
308#endif
void BKE_curveprofile_selected_handle_set(struct CurveProfile *profile, int type_1, int type_2)
bool BKE_curveprofile_remove_point(struct CurveProfile *profile, struct CurveProfilePoint *point)
void BKE_curveprofile_update(struct CurveProfile *profile, int update_flags)
@ PROF_UPDATE_CLIP
@ PROF_UPDATE_REMOVE_DOUBLES
@ PROF_UPDATE_NONE
void BKE_curveprofile_evaluate_length_portion(const struct CurveProfile *profile, float length_portion, float *x_out, float *y_out)
void BKE_curveprofile_init(struct CurveProfile *profile, short segments_len)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
#define BLT_I18NCONTEXT_ID_MESH
@ HD_VECT
@ HD_FREE
@ HD_AUTO
@ HD_ALIGN
@ PROF_SAMPLE_EVEN_LENGTHS
@ PROF_SAMPLE_STRAIGHT_EDGES
@ PROF_PRESET_CROWN
@ PROF_PRESET_LINE
@ PROF_PRESET_CORNICE
@ PROF_PRESET_SUPPORTS
@ PROF_PRESET_STEPS
#define RNA_POINTER_INVALIDATE(ptr)
ParameterFlag
Definition RNA_types.hh:396
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_COLLECTION
Definition RNA_types.hh:71
PropertyFlag
Definition RNA_types.hh:201
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_XYZ
Definition RNA_types.hh:172
@ PROP_NONE
Definition RNA_types.hh:136
#define NC_GEOM
Definition WM_types.hh:360
#define ND_DATA
Definition WM_types.hh:475
static void rna_def_curveprofile(BlenderRNA *brna)
static const EnumPropertyItem prop_handle_type_items[]
static void rna_def_curveprofilepoint(BlenderRNA *brna)
static void rna_def_curveprofile_points_api(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_profile(BlenderRNA *brna)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
PropertyRNA * RNA_def_float(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)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_array(PropertyRNA *prop, int length)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
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
void * data
Definition RNA_types.hh:42
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4126