Blender  V3.3
rna_curveprofile.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stdio.h>
8 #include <stdlib.h>
9 
10 #include "DNA_curve_types.h"
11 #include "DNA_curveprofile_types.h"
12 
13 #include "RNA_define.h"
14 #include "rna_internal.h"
15 
16 #include "WM_api.h"
17 #include "WM_types.h"
18 
19 #ifdef RNA_RUNTIME
20 
21 # include "RNA_access.h"
22 
23 # include "BKE_curveprofile.h"
24 
29 static void rna_CurveProfilePoint_handle_type_set(PointerRNA *ptr, int value)
30 {
32  CurveProfile *profile = point->profile;
33 
34  if (profile) {
35  BKE_curveprofile_selected_handle_set(profile, value, value);
38  }
39 }
40 
41 static void rna_CurveProfile_clip_set(PointerRNA *ptr, bool value)
42 {
43  CurveProfile *profile = (CurveProfile *)ptr->data;
44 
45  if (value) {
46  profile->flag |= PROF_USE_CLIP;
47  }
48  else {
49  profile->flag &= ~PROF_USE_CLIP;
50  }
51 
53 }
54 
55 static void rna_CurveProfile_sample_straight_set(PointerRNA *ptr, bool value)
56 {
57  CurveProfile *profile = (CurveProfile *)ptr->data;
58 
59  if (value) {
60  profile->flag |= PROF_SAMPLE_STRAIGHT_EDGES;
61  }
62  else {
63  profile->flag &= ~PROF_SAMPLE_STRAIGHT_EDGES;
64  }
65 
67 }
68 
69 static void rna_CurveProfile_sample_even_set(PointerRNA *ptr, bool value)
70 {
71  CurveProfile *profile = (CurveProfile *)ptr->data;
72 
73  if (value) {
74  profile->flag |= PROF_SAMPLE_EVEN_LENGTHS;
75  }
76  else {
77  profile->flag &= ~PROF_SAMPLE_EVEN_LENGTHS;
78  }
79 
81 }
82 
83 static void rna_CurveProfile_remove_point(CurveProfile *profile,
84  ReportList *reports,
85  PointerRNA *point_ptr)
86 {
87  CurveProfilePoint *point = point_ptr->data;
88  if (BKE_curveprofile_remove_point(profile, point) == false) {
89  BKE_report(reports, RPT_ERROR, "Unable to remove path point");
90  return;
91  }
92 
93  RNA_POINTER_INVALIDATE(point_ptr);
94 }
95 
96 static void rna_CurveProfile_evaluate(struct CurveProfile *profile,
97  ReportList *reports,
98  float length_portion,
99  float location[2])
100 {
101  if (!profile->table) {
102  BKE_report(reports, RPT_ERROR, "CurveProfile table not initialized, call initialize()");
103  }
104  BKE_curveprofile_evaluate_length_portion(profile, length_portion, &location[0], &location[1]);
105 }
106 
107 static void rna_CurveProfile_initialize(struct CurveProfile *profile, int segments_len)
108 {
109  BKE_curveprofile_init(profile, (short)segments_len);
110 }
111 
112 static void rna_CurveProfile_update(struct CurveProfile *profile)
113 {
115 }
116 
117 #else
118 
120  {HD_AUTO, "AUTO", ICON_HANDLE_AUTO, "Auto Handle", ""},
121  {HD_VECT, "VECTOR", ICON_HANDLE_VECTOR, "Vector Handle", ""},
122  {HD_FREE, "FREE", ICON_HANDLE_FREE, "Free Handle", ""},
123  {HD_ALIGN, "ALIGN", ICON_HANDLE_ALIGNED, "Aligned Free Handles", ""},
124  {0, NULL, 0, NULL, NULL},
125 };
126 
128 {
129  StructRNA *srna;
130  PropertyRNA *prop;
131 
132  srna = RNA_def_struct(brna, "CurveProfilePoint", NULL);
133  RNA_def_struct_ui_text(srna, "CurveProfilePoint", "Point of a path used to define a profile");
134 
135  prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
136  RNA_def_property_float_sdna(prop, NULL, "x");
137  RNA_def_property_array(prop, 2);
138  RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the path point");
139 
140  prop = RNA_def_property(srna, "handle_type_1", PROP_ENUM, PROP_NONE);
141  RNA_def_property_enum_sdna(prop, NULL, "h1");
143  RNA_def_property_enum_funcs(prop, NULL, "rna_CurveProfilePoint_handle_type_set", NULL);
144  RNA_def_property_ui_text(prop, "First Handle Type", "Path interpolation at this point");
145 
146  prop = RNA_def_property(srna, "handle_type_2", PROP_ENUM, PROP_NONE);
147  RNA_def_property_enum_sdna(prop, NULL, "h2");
149  RNA_def_property_enum_funcs(prop, NULL, "rna_CurveProfilePoint_handle_type_set", NULL);
150  RNA_def_property_ui_text(prop, "Second Handle Type", "Path interpolation at this point");
151 
152  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
154  RNA_def_property_ui_text(prop, "Select", "Selection state of the path point");
155 }
156 
158 {
159  StructRNA *srna;
160  PropertyRNA *parm;
161  FunctionRNA *func;
162 
163  RNA_def_property_srna(cprop, "CurveProfilePoints");
164  srna = RNA_def_struct(brna, "CurveProfilePoints", NULL);
165  RNA_def_struct_sdna(srna, "CurveProfile");
166  RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points");
167 
168  func = RNA_def_function(srna, "add", "BKE_curveprofile_insert");
169  RNA_def_function_ui_description(func, "Add point to the profile");
170  parm = RNA_def_float(func,
171  "x",
172  0.0f,
173  -FLT_MAX,
174  FLT_MAX,
175  "X Position",
176  "X Position for new point",
177  -FLT_MAX,
178  FLT_MAX);
180  parm = RNA_def_float(func,
181  "y",
182  0.0f,
183  -FLT_MAX,
184  FLT_MAX,
185  "Y Position",
186  "Y Position for new point",
187  -FLT_MAX,
188  FLT_MAX);
190  parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "New point");
191  RNA_def_function_return(func, parm);
192 
193  func = RNA_def_function(srna, "remove", "rna_CurveProfile_remove_point");
195  RNA_def_function_ui_description(func, "Delete point from the profile");
196  parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "Point to remove");
199 }
200 
202 {
203  StructRNA *srna;
204  PropertyRNA *prop;
205  PropertyRNA *parm;
206  FunctionRNA *func;
207 
208  static const EnumPropertyItem rna_enum_curveprofile_preset_items[] = {
209  {PROF_PRESET_LINE, "LINE", 0, "Line", "Default"},
210  {PROF_PRESET_SUPPORTS, "SUPPORTS", 0, "Support Loops", "Loops on each side of the profile"},
211  {PROF_PRESET_CORNICE, "CORNICE", 0, "Cornice Molding", ""},
212  {PROF_PRESET_CROWN, "CROWN", 0, "Crown Molding", ""},
213  {PROF_PRESET_STEPS, "STEPS", 0, "Steps", "A number of steps defined by the segments"},
214  {0, NULL, 0, NULL, NULL},
215  };
216 
217  srna = RNA_def_struct(brna, "CurveProfile", NULL);
218  RNA_def_struct_ui_text(srna, "CurveProfile", "Profile Path editor used to build a profile path");
219 
220  prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE);
221  RNA_def_property_enum_sdna(prop, NULL, "preset");
222  RNA_def_property_enum_items(prop, rna_enum_curveprofile_preset_items);
223  RNA_def_property_ui_text(prop, "Preset", "");
224 
225  prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
227  RNA_def_property_ui_text(prop, "Clip", "Force the path view to fit a defined boundary");
228  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_clip_set");
229 
230  prop = RNA_def_property(srna, "use_sample_straight_edges", PROP_BOOLEAN, PROP_NONE);
232  RNA_def_property_ui_text(prop, "Sample Straight Edges", "Sample edges with vector handles");
233  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_sample_straight_set");
234 
235  prop = RNA_def_property(srna, "use_sample_even_lengths", PROP_BOOLEAN, PROP_NONE);
237  RNA_def_property_ui_text(prop, "Sample Even Lengths", "Sample edges with even lengths");
238  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_sample_even_set");
239 
240  func = RNA_def_function(srna, "update", "rna_CurveProfile_update");
241  RNA_def_function_ui_description(func, "Refresh internal data, remove doubles and clip points");
242 
243  func = RNA_def_function(srna, "reset_view", "BKE_curveprofile_reset_view");
244  RNA_def_function_ui_description(func, "Reset the curve profile grid to its clipping size");
245 
246  func = RNA_def_function(srna, "initialize", "rna_CurveProfile_initialize");
247  parm = RNA_def_int(func,
248  "totsegments",
249  1,
250  1,
251  1000,
252  "",
253  "The number of segment values to"
254  " initialize the segments table with",
255  1,
256  100);
258  RNA_def_function_ui_description(func, "Set the number of display segments and fill tables");
259 
260  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
261  RNA_def_property_collection_sdna(prop, NULL, "path", "path_len");
262  RNA_def_property_struct_type(prop, "CurveProfilePoint");
263  RNA_def_property_ui_text(prop, "Points", "Profile control points");
265 
266  prop = RNA_def_property(srna, "segments", PROP_COLLECTION, PROP_NONE);
267  RNA_def_property_collection_sdna(prop, NULL, "segments", "segments_len");
268  RNA_def_property_struct_type(prop, "CurveProfilePoint");
269  RNA_def_property_ui_text(prop, "Segments", "Segments sampled from control points");
270 
271  func = RNA_def_function(srna, "evaluate", "rna_CurveProfile_evaluate");
273  RNA_def_function_ui_description(func, "Evaluate the at the given portion of the path length");
274  parm = RNA_def_float(func,
275  "length_portion",
276  0.0f,
277  0.0f,
278  1.0f,
279  "Length Portion",
280  "Portion of the path length to travel before evaluation",
281  0.0f,
282  1.0f);
284  parm = RNA_def_float_vector(func,
285  "location",
286  2,
287  NULL,
288  -100.0f,
289  100.0f,
290  "Location",
291  "The location at the given portion of the profile",
292  -100.0f,
293  100.0f);
294  RNA_def_function_output(func, parm);
295 }
296 
298 {
300  rna_def_curveprofile(brna);
301 }
302 
303 #endif
@ PROF_UPDATE_CLIP
@ PROF_UPDATE_REMOVE_DOUBLES
@ PROF_UPDATE_NONE
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)
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.c:83
@ HD_VECT
@ HD_FREE
@ HD_AUTO
@ HD_ALIGN
@ PROF_PRESET_CROWN
@ PROF_PRESET_LINE
@ PROF_PRESET_CORNICE
@ PROF_PRESET_SUPPORTS
@ PROF_PRESET_STEPS
@ PROF_USE_CLIP
@ PROF_SAMPLE_EVEN_LENGTHS
@ PROF_SAMPLE_STRAIGHT_EDGES
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:744
@ PARM_RNAPTR
Definition: RNA_types.h:354
@ PARM_REQUIRED
Definition: RNA_types.h:352
@ FUNC_USE_REPORTS
Definition: RNA_types.h:663
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_ENUM
Definition: RNA_types.h:63
@ PROP_COLLECTION
Definition: RNA_types.h:65
@ PROP_THICK_WRAP
Definition: RNA_types.h:285
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_XYZ
Definition: RNA_types.h:162
@ PROP_NONE
Definition: RNA_types.h:126
#define NC_GEOM
Definition: WM_types.h:343
#define ND_DATA
Definition: WM_types.h:456
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)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3836
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4170
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2236
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1526
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4312
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4273
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3474
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4337
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
Definition: rna_define.c:2944
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3862
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1872
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1048
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2769
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4347
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
Definition: rna_define.c:3224
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4342
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2601
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3597
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2493
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1518
CurveProfilePoint * table
void * data
Definition: RNA_types.h:38
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3480