Blender V5.0
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
8
9#include <cstdlib>
10
11#include "DNA_curve_types.h"
13
14#include "RNA_define.hh"
15#include "rna_internal.hh"
16
17#include "BLT_translation.hh"
18
19#include "WM_api.hh"
20#include "WM_types.hh"
21
22#ifdef RNA_RUNTIME
23
24# include "RNA_access.hh"
25
26# include "BKE_curveprofile.h"
27
32static void rna_CurveProfilePoint_handle_type_set(PointerRNA *ptr, int value)
33{
34 CurveProfilePoint *point = static_cast<CurveProfilePoint *>(ptr->data);
35 CurveProfile *profile = point->profile;
36
37 if (profile) {
38 BKE_curveprofile_selected_handle_set(profile, value, value);
41 }
42}
43
44static void rna_CurveProfile_clip_set(PointerRNA *ptr, bool value)
45{
46 CurveProfile *profile = (CurveProfile *)ptr->data;
47
48 if (value) {
49 profile->flag |= PROF_USE_CLIP;
50 }
51 else {
52 profile->flag &= ~PROF_USE_CLIP;
53 }
54
56}
57
58static void rna_CurveProfile_sample_straight_set(PointerRNA *ptr, bool value)
59{
60 CurveProfile *profile = (CurveProfile *)ptr->data;
61
62 if (value) {
64 }
65 else {
67 }
68
70}
71
72static void rna_CurveProfile_sample_even_set(PointerRNA *ptr, bool value)
73{
74 CurveProfile *profile = (CurveProfile *)ptr->data;
75
76 if (value) {
78 }
79 else {
81 }
82
84}
85
86static void rna_CurveProfile_remove_point(CurveProfile *profile,
87 ReportList *reports,
88 PointerRNA *point_ptr)
89{
90 CurveProfilePoint *point = static_cast<CurveProfilePoint *>(point_ptr->data);
91 if (BKE_curveprofile_remove_point(profile, point) == false) {
92 BKE_report(reports, RPT_ERROR, "Unable to remove path point");
93 return;
94 }
95
96 point_ptr->invalidate();
97}
98
99static void rna_CurveProfile_evaluate(CurveProfile *profile,
100 ReportList *reports,
101 float length_portion,
102 float location[2])
103{
104 if (!profile->table) {
105 BKE_report(reports, RPT_ERROR, "CurveProfile table not initialized, call initialize()");
106 }
107 BKE_curveprofile_evaluate_length_portion(profile, length_portion, &location[0], &location[1]);
108}
109
110static void rna_CurveProfile_initialize(CurveProfile *profile, int segments_len)
111{
112 BKE_curveprofile_init(profile, short(segments_len));
113}
114
115static void rna_CurveProfile_update(CurveProfile *profile)
116{
118}
119
120#else
121
123 {HD_AUTO, "AUTO", ICON_HANDLE_AUTO, "Auto Handle", ""},
124 {HD_VECT, "VECTOR", ICON_HANDLE_VECTOR, "Vector Handle", ""},
125 {HD_FREE, "FREE", ICON_HANDLE_FREE, "Free Handle", ""},
126 {HD_ALIGN, "ALIGN", ICON_HANDLE_ALIGNED, "Aligned Free Handles", ""},
127 {0, nullptr, 0, nullptr, nullptr},
128};
129
131{
132 StructRNA *srna;
133 PropertyRNA *prop;
134
135 srna = RNA_def_struct(brna, "CurveProfilePoint", nullptr);
136 RNA_def_struct_ui_text(srna, "CurveProfilePoint", "Point of a path used to define a profile");
137
138 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
139 RNA_def_property_float_sdna(prop, nullptr, "x");
140 RNA_def_property_array(prop, 2);
141 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the path point");
142
143 prop = RNA_def_property(srna, "handle_type_1", PROP_ENUM, PROP_NONE);
144 RNA_def_property_enum_sdna(prop, nullptr, "h1");
146 RNA_def_property_enum_funcs(prop, nullptr, "rna_CurveProfilePoint_handle_type_set", nullptr);
147 RNA_def_property_ui_text(prop, "First Handle Type", "Path interpolation at this point");
148
149 prop = RNA_def_property(srna, "handle_type_2", PROP_ENUM, PROP_NONE);
150 RNA_def_property_enum_sdna(prop, nullptr, "h2");
152 RNA_def_property_enum_funcs(prop, nullptr, "rna_CurveProfilePoint_handle_type_set", nullptr);
153 RNA_def_property_ui_text(prop, "Second Handle Type", "Path interpolation at this point");
154
155 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
156 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PROF_SELECT);
157 RNA_def_property_ui_text(prop, "Select", "Selection state of the path point");
158}
159
161{
162 StructRNA *srna;
163 PropertyRNA *parm;
164 FunctionRNA *func;
165
166 RNA_def_property_srna(cprop, "CurveProfilePoints");
167 srna = RNA_def_struct(brna, "CurveProfilePoints", nullptr);
168 RNA_def_struct_sdna(srna, "CurveProfile");
169 RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points");
170
171 func = RNA_def_function(srna, "add", "BKE_curveprofile_insert");
172 RNA_def_function_ui_description(func, "Add point to the profile");
173 parm = RNA_def_float(func,
174 "x",
175 0.0f,
176 -FLT_MAX,
177 FLT_MAX,
178 "X Position",
179 "X Position for new point",
180 -FLT_MAX,
181 FLT_MAX);
183 parm = RNA_def_float(func,
184 "y",
185 0.0f,
186 -FLT_MAX,
187 FLT_MAX,
188 "Y Position",
189 "Y Position for new point",
190 -FLT_MAX,
191 FLT_MAX);
193 parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "New point");
194 RNA_def_function_return(func, parm);
195
196 func = RNA_def_function(srna, "remove", "rna_CurveProfile_remove_point");
198 RNA_def_function_ui_description(func, "Delete point from the profile");
199 parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "Point to remove");
202}
203
205{
206 StructRNA *srna;
207 PropertyRNA *prop;
208 PropertyRNA *parm;
209 FunctionRNA *func;
210
211 static const EnumPropertyItem rna_enum_curveprofile_preset_items[] = {
212 {PROF_PRESET_LINE, "LINE", 0, "Line", "Default"},
213 {PROF_PRESET_SUPPORTS, "SUPPORTS", 0, "Support Loops", "Loops on each side of the profile"},
214 {PROF_PRESET_CORNICE, "CORNICE", 0, "Cornice Molding", ""},
215 {PROF_PRESET_CROWN, "CROWN", 0, "Crown Molding", ""},
216 {PROF_PRESET_STEPS, "STEPS", 0, "Steps", "A number of steps defined by the segments"},
217 {0, nullptr, 0, nullptr, nullptr},
218 };
219
220 srna = RNA_def_struct(brna, "CurveProfile", nullptr);
221 RNA_def_struct_ui_text(srna, "CurveProfile", "Profile Path editor used to build a profile path");
222
223 prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE);
224 RNA_def_property_enum_sdna(prop, nullptr, "preset");
225 RNA_def_property_enum_items(prop, rna_enum_curveprofile_preset_items);
227 RNA_def_property_ui_text(prop, "Preset", "");
228
229 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
230 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PROF_USE_CLIP);
231 RNA_def_property_ui_text(prop, "Clip", "Force the path view to fit a defined boundary");
232 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_clip_set");
233
234 prop = RNA_def_property(srna, "use_sample_straight_edges", PROP_BOOLEAN, PROP_NONE);
236 RNA_def_property_ui_text(prop, "Sample Straight Edges", "Sample edges with vector handles");
237 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_sample_straight_set");
238
239 prop = RNA_def_property(srna, "use_sample_even_lengths", PROP_BOOLEAN, PROP_NONE);
241 RNA_def_property_ui_text(prop, "Sample Even Lengths", "Sample edges with even lengths");
242 RNA_def_property_boolean_funcs(prop, nullptr, "rna_CurveProfile_sample_even_set");
243
244 func = RNA_def_function(srna, "update", "rna_CurveProfile_update");
245 RNA_def_function_ui_description(func, "Refresh internal data, remove doubles and clip points");
246
247 func = RNA_def_function(srna, "reset_view", "BKE_curveprofile_reset_view");
248 RNA_def_function_ui_description(func, "Reset the curve profile grid to its clipping size");
249
250 func = RNA_def_function(srna, "initialize", "rna_CurveProfile_initialize");
251 parm = RNA_def_int(func,
252 "totsegments",
253 1,
254 1,
255 1000,
256 "",
257 "The number of segment values to"
258 " initialize the segments table with",
259 1,
260 100);
262 RNA_def_function_ui_description(func, "Set the number of display segments and fill tables");
263
264 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
265 RNA_def_property_collection_sdna(prop, nullptr, "path", "path_len");
266 RNA_def_property_struct_type(prop, "CurveProfilePoint");
267 RNA_def_property_ui_text(prop, "Points", "Profile control points");
269
270 prop = RNA_def_property(srna, "segments", PROP_COLLECTION, PROP_NONE);
271 RNA_def_property_collection_sdna(prop, nullptr, "segments", "segments_len");
272 RNA_def_property_struct_type(prop, "CurveProfilePoint");
273 RNA_def_property_ui_text(prop, "Segments", "Segments sampled from control points");
274
275 func = RNA_def_function(srna, "evaluate", "rna_CurveProfile_evaluate");
277 RNA_def_function_ui_description(func, "Evaluate the at the given portion of the path length");
278 parm = RNA_def_float(func,
279 "length_portion",
280 0.0f,
281 0.0f,
282 1.0f,
283 "Length Portion",
284 "Portion of the path length to travel before evaluation",
285 0.0f,
286 1.0f);
288 parm = RNA_def_float_vector(func,
289 "location",
290 2,
291 nullptr,
292 -100.0f,
293 100.0f,
294 "Location",
295 "The location at the given portion of the profile",
296 -100.0f,
297 100.0f);
298 RNA_def_function_output(func, parm);
299}
300
306
307#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)
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define BLT_I18NCONTEXT_ID_MESH
@ HD_VECT
@ HD_FREE
@ HD_AUTO
@ HD_ALIGN
@ PROF_PRESET_CROWN
@ PROF_PRESET_LINE
@ PROF_PRESET_CORNICE
@ PROF_PRESET_SUPPORTS
@ PROF_PRESET_STEPS
@ PROF_SAMPLE_EVEN_LENGTHS
@ PROF_SAMPLE_STRAIGHT_EDGES
ParameterFlag
Definition RNA_types.hh:544
@ PARM_RNAPTR
Definition RNA_types.hh:547
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ FUNC_USE_REPORTS
Definition RNA_types.hh:914
@ PROP_FLOAT
Definition RNA_types.hh:164
@ PROP_BOOLEAN
Definition RNA_types.hh:162
@ PROP_ENUM
Definition RNA_types.hh:166
@ PROP_COLLECTION
Definition RNA_types.hh:168
PropertyFlag
Definition RNA_types.hh:300
@ PROP_THICK_WRAP
Definition RNA_types.hh:423
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
@ PROP_XYZ
Definition RNA_types.hh:269
@ PROP_NONE
Definition RNA_types.hh:233
#define NC_GEOM
Definition WM_types.hh:393
#define ND_DATA
Definition WM_types.hh:509
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 booleanbit)
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
struct CurveProfile * profile
CurveProfilePoint * table
void invalidate()
Definition RNA_types.hh:110
void * data
Definition RNA_types.hh:53
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4238