Blender  V2.93
rna_curveprofile.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #include "DNA_curve_types.h"
25 #include "DNA_curveprofile_types.h"
26 #include "DNA_texture_types.h"
27 
28 #include "BLI_utildefines.h"
29 
30 #include "RNA_define.h"
31 #include "rna_internal.h"
32 
33 #include "WM_api.h"
34 #include "WM_types.h"
35 
36 #ifdef RNA_RUNTIME
37 
38 # include "RNA_access.h"
39 
40 # include "DNA_image_types.h"
41 # include "DNA_material_types.h"
42 # include "DNA_movieclip_types.h"
43 # include "DNA_node_types.h"
44 # include "DNA_object_types.h"
45 # include "DNA_particle_types.h"
46 # include "DNA_sequence_types.h"
47 
48 # include "MEM_guardedalloc.h"
49 
50 # include "BKE_colorband.h"
51 # include "BKE_curveprofile.h"
52 # include "BKE_image.h"
53 # include "BKE_linestyle.h"
54 # include "BKE_movieclip.h"
55 # include "BKE_node.h"
56 
57 # include "DEG_depsgraph.h"
58 
59 # include "ED_node.h"
60 
61 # include "IMB_colormanagement.h"
62 # include "IMB_imbuf.h"
63 
64 # include "SEQ_sequencer.h"
65 
70 static void rna_CurveProfilePoint_handle_type_set(PointerRNA *ptr, int value)
71 {
72  CurveProfilePoint *point = ptr->data;
73  CurveProfile *profile = point->profile;
74 
75  if (profile) {
76  BKE_curveprofile_selected_handle_set(profile, value, value);
79  }
80 }
81 
82 static void rna_CurveProfile_clip_set(PointerRNA *ptr, bool value)
83 {
84  CurveProfile *profile = (CurveProfile *)ptr->data;
85 
86  if (value) {
87  profile->flag |= PROF_USE_CLIP;
88  }
89  else {
90  profile->flag &= ~PROF_USE_CLIP;
91  }
92 
94 }
95 
96 static void rna_CurveProfile_sample_straight_set(PointerRNA *ptr, bool value)
97 {
98  CurveProfile *profile = (CurveProfile *)ptr->data;
99 
100  if (value) {
101  profile->flag |= PROF_SAMPLE_STRAIGHT_EDGES;
102  }
103  else {
104  profile->flag &= ~PROF_SAMPLE_STRAIGHT_EDGES;
105  }
106 
108 }
109 
110 static void rna_CurveProfile_sample_even_set(PointerRNA *ptr, bool value)
111 {
112  CurveProfile *profile = (CurveProfile *)ptr->data;
113 
114  if (value) {
115  profile->flag |= PROF_SAMPLE_EVEN_LENGTHS;
116  }
117  else {
118  profile->flag &= ~PROF_SAMPLE_EVEN_LENGTHS;
119  }
120 
122 }
123 
124 static void rna_CurveProfile_remove_point(CurveProfile *profile,
125  ReportList *reports,
126  PointerRNA *point_ptr)
127 {
128  CurveProfilePoint *point = point_ptr->data;
129  if (BKE_curveprofile_remove_point(profile, point) == false) {
130  BKE_report(reports, RPT_ERROR, "Unable to remove path point");
131  return;
132  }
133 
134  RNA_POINTER_INVALIDATE(point_ptr);
135 }
136 
137 static void rna_CurveProfile_evaluate(struct CurveProfile *profile,
138  ReportList *reports,
139  float length_portion,
140  float *location)
141 {
142  if (!profile->table) {
143  BKE_report(reports, RPT_ERROR, "CurveProfile table not initialized, call initialize()");
144  }
145  BKE_curveprofile_evaluate_length_portion(profile, length_portion, &location[0], &location[1]);
146 }
147 
148 static void rna_CurveProfile_initialize(struct CurveProfile *profile, int segments_len)
149 {
150  BKE_curveprofile_init(profile, (short)segments_len);
151 }
152 
153 static void rna_CurveProfile_update(struct CurveProfile *profile)
154 {
156 }
157 
158 #else
159 
161  {HD_AUTO, "AUTO", ICON_HANDLE_AUTO, "Auto Handle", ""},
162  {HD_VECT, "VECTOR", ICON_HANDLE_VECTOR, "Vector Handle", ""},
163  {HD_FREE, "FREE", ICON_HANDLE_FREE, "Free Handle", ""},
164  {HD_ALIGN, "ALIGN", ICON_HANDLE_ALIGNED, "Aligned Free Handles", ""},
165  {0, NULL, 0, NULL, NULL},
166 };
167 
169 {
170  StructRNA *srna;
171  PropertyRNA *prop;
172 
173  srna = RNA_def_struct(brna, "CurveProfilePoint", NULL);
174  RNA_def_struct_ui_text(srna, "CurveProfilePoint", "Point of a path used to define a profile");
175 
176  prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
177  RNA_def_property_float_sdna(prop, NULL, "x");
178  RNA_def_property_array(prop, 2);
179  RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the path point");
180 
181  prop = RNA_def_property(srna, "handle_type_1", PROP_ENUM, PROP_NONE);
182  RNA_def_property_enum_sdna(prop, NULL, "h1");
184  RNA_def_property_enum_funcs(prop, NULL, "rna_CurveProfilePoint_handle_type_set", NULL);
185  RNA_def_property_ui_text(prop, "First Handle Type", "Path interpolation at this point");
186 
187  prop = RNA_def_property(srna, "handle_type_2", PROP_ENUM, PROP_NONE);
188  RNA_def_property_enum_sdna(prop, NULL, "h2");
190  RNA_def_property_enum_funcs(prop, NULL, "rna_CurveProfilePoint_handle_type_set", NULL);
191  RNA_def_property_ui_text(prop, "Second Handle Type", "Path interpolation at this point");
192 
193  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
195  RNA_def_property_ui_text(prop, "Select", "Selection state of the path point");
196 }
197 
199 {
200  StructRNA *srna;
201  PropertyRNA *parm;
202  FunctionRNA *func;
203 
204  RNA_def_property_srna(cprop, "CurveProfilePoints");
205  srna = RNA_def_struct(brna, "CurveProfilePoints", NULL);
206  RNA_def_struct_sdna(srna, "CurveProfile");
207  RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points");
208 
209  func = RNA_def_function(srna, "add", "BKE_curveprofile_insert");
210  RNA_def_function_ui_description(func, "Add point to the profile");
211  parm = RNA_def_float(func,
212  "x",
213  0.0f,
214  -FLT_MAX,
215  FLT_MAX,
216  "X Position",
217  "X Position for new point",
218  -FLT_MAX,
219  FLT_MAX);
221  parm = RNA_def_float(func,
222  "y",
223  0.0f,
224  -FLT_MAX,
225  FLT_MAX,
226  "Y Position",
227  "Y Position for new point",
228  -FLT_MAX,
229  FLT_MAX);
231  parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "New point");
232  RNA_def_function_return(func, parm);
233 
234  func = RNA_def_function(srna, "remove", "rna_CurveProfile_remove_point");
236  RNA_def_function_ui_description(func, "Delete point from the profile");
237  parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "Point to remove");
240 }
241 
243 {
244  StructRNA *srna;
245  PropertyRNA *prop;
246  PropertyRNA *parm;
247  FunctionRNA *func;
248 
250  {PROF_PRESET_LINE, "LINE", 0, "Line", "Default"},
251  {PROF_PRESET_SUPPORTS, "SUPPORTS", 0, "Support Loops", "Loops on each side of the profile"},
252  {PROF_PRESET_CORNICE, "CORNICE", 0, "Cornice Molding", ""},
253  {PROF_PRESET_CROWN, "CROWN", 0, "Crown Molding", ""},
254  {PROF_PRESET_STEPS, "STEPS", 0, "Steps", "A number of steps defined by the segments"},
255  {0, NULL, 0, NULL, NULL},
256  };
257 
258  srna = RNA_def_struct(brna, "CurveProfile", NULL);
259  RNA_def_struct_ui_text(srna, "CurveProfile", "Profile Path editor used to build a profile path");
260 
261  prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE);
262  RNA_def_property_enum_sdna(prop, NULL, "preset");
264  RNA_def_property_ui_text(prop, "Preset", "");
265 
266  prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
268  RNA_def_property_ui_text(prop, "Clip", "Force the path view to fit a defined boundary");
269  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_clip_set");
270 
271  prop = RNA_def_property(srna, "use_sample_straight_edges", PROP_BOOLEAN, PROP_NONE);
273  RNA_def_property_ui_text(prop, "Sample Straight Edges", "Sample edges with vector handles");
274  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_sample_straight_set");
275 
276  prop = RNA_def_property(srna, "use_sample_even_lengths", PROP_BOOLEAN, PROP_NONE);
278  RNA_def_property_ui_text(prop, "Sample Even Lengths", "Sample edges with even lengths");
279  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_sample_even_set");
280 
281  func = RNA_def_function(srna, "update", "rna_CurveProfile_update");
282  RNA_def_function_ui_description(func, "Refresh internal data, remove doubles and clip points");
283 
284  func = RNA_def_function(srna, "reset_view", "BKE_curveprofile_reset_view");
285  RNA_def_function_ui_description(func, "Reset the curve profile grid to its clipping size");
286 
287  func = RNA_def_function(srna, "initialize", "rna_CurveProfile_initialize");
288  parm = RNA_def_int(func,
289  "totsegments",
290  1,
291  1,
292  1000,
293  "",
294  "The number of segment values to"
295  " initialize the segments table with",
296  1,
297  100);
299  RNA_def_function_ui_description(func, "Set the number of display segments and fill tables");
300 
301  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
302  RNA_def_property_collection_sdna(prop, NULL, "path", "path_len");
303  RNA_def_property_struct_type(prop, "CurveProfilePoint");
304  RNA_def_property_ui_text(prop, "Points", "Profile control points");
306 
307  prop = RNA_def_property(srna, "segments", PROP_COLLECTION, PROP_NONE);
308  RNA_def_property_collection_sdna(prop, NULL, "segments", "segments_len");
309  RNA_def_property_struct_type(prop, "CurveProfilePoint");
310  RNA_def_property_ui_text(prop, "Segments", "Segments sampled from control points");
311 
312  func = RNA_def_function(srna, "evaluate", "rna_CurveProfile_evaluate");
314  RNA_def_function_ui_description(func, "Evaluate the at the given portion of the path length");
315  parm = RNA_def_float(func,
316  "length_portion",
317  0.0f,
318  0.0f,
319  1.0f,
320  "Length Portion",
321  "Portion of the path length to travel before evaluation",
322  0.0f,
323  1.0f);
325  parm = RNA_def_float_vector(func,
326  "location",
327  2,
328  NULL,
329  -100.0f,
330  100.0f,
331  "Location",
332  "The location at the given portion of the profile",
333  -100.0f,
334  100.0f);
335  RNA_def_function_output(func, parm);
336 }
337 
339 {
341  rna_def_curveprofile(brna);
342 }
343 
344 #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)
Definition: curveprofile.c:335
bool BKE_curveprofile_remove_point(struct CurveProfile *profile, struct CurveProfilePoint *point)
Definition: curveprofile.c:192
void BKE_curveprofile_update(struct CurveProfile *profile, const int update_flags)
Definition: curveprofile.c:905
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)
Definition: curveprofile.c:966
Blender kernel freestyle line style functionality.
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
@ 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
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define RNA_POINTER_INVALIDATE(ptr)
Definition: RNA_access.h:1425
const EnumPropertyItem rna_enum_curveprofile_preset_items[]
@ PARM_RNAPTR
Definition: RNA_types.h:339
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_COLLECTION
Definition: RNA_types.h:79
@ PROP_THICK_WRAP
Definition: RNA_types.h:270
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_XYZ
Definition: RNA_types.h:148
@ PROP_NONE
Definition: RNA_types.h:113
#define NC_GEOM
Definition: WM_types.h:294
#define ND_DATA
Definition: WM_types.h:408
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:3825
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
Definition: rna_define.c:4159
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1555
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
Definition: rna_define.c:4302
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
Definition: rna_define.c:3462
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
Definition: rna_define.c:4327
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
Definition: rna_define.c:2971
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:3851
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
Definition: rna_define.c:2791
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
Definition: rna_define.c:3251
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2623
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:3585
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2515
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
struct CurveProfile * profile
CurveProfilePoint * table
void * data
Definition: RNA_types.h:52
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157