Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_curveprofile.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94a35bdede87d2254477967fc399d17ee0a073c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file
 * \ingroup RNA
 */

#include <stdio.h>
#include <stdlib.h>

#include "DNA_curve_types.h"
#include "DNA_curveprofile_types.h"
#include "DNA_texture_types.h"

#include "BLI_utildefines.h"

#include "RNA_define.h"
#include "rna_internal.h"

#include "WM_api.h"
#include "WM_types.h"

#ifdef RNA_RUNTIME

#  include "RNA_access.h"

#  include "DNA_image_types.h"
#  include "DNA_material_types.h"
#  include "DNA_movieclip_types.h"
#  include "DNA_node_types.h"
#  include "DNA_object_types.h"
#  include "DNA_particle_types.h"
#  include "DNA_sequence_types.h"

#  include "MEM_guardedalloc.h"

#  include "BKE_colorband.h"
#  include "BKE_curveprofile.h"
#  include "BKE_image.h"
#  include "BKE_linestyle.h"
#  include "BKE_movieclip.h"
#  include "BKE_node.h"
#  include "BKE_sequencer.h"

#  include "DEG_depsgraph.h"

#  include "ED_node.h"

#  include "IMB_colormanagement.h"
#  include "IMB_imbuf.h"

static void rna_CurveProfile_clip_set(PointerRNA *ptr, bool value)
{
  CurveProfile *profile = (CurveProfile *)ptr->data;

  if (value) {
    profile->flag |= PROF_USE_CLIP;
  }
  else {
    profile->flag &= ~PROF_USE_CLIP;
  }

  BKE_curveprofile_update(profile, false);
}

static void rna_CurveProfile_sample_straight_set(PointerRNA *ptr, bool value)
{
  CurveProfile *profile = (CurveProfile *)ptr->data;

  if (value) {
    profile->flag |= PROF_SAMPLE_STRAIGHT_EDGES;
  }
  else {
    profile->flag &= ~PROF_SAMPLE_STRAIGHT_EDGES;
  }

  BKE_curveprofile_update(profile, false);
}

static void rna_CurveProfile_sample_even_set(PointerRNA *ptr, bool value)
{
  CurveProfile *profile = (CurveProfile *)ptr->data;

  if (value) {
    profile->flag |= PROF_SAMPLE_EVEN_LENGTHS;
  }
  else {
    profile->flag &= ~PROF_SAMPLE_EVEN_LENGTHS;
  }

  BKE_curveprofile_update(profile, false);
}

static void rna_CurveProfile_remove_point(CurveProfile *profile,
                                          ReportList *reports,
                                          PointerRNA *point_ptr)
{
  CurveProfilePoint *point = point_ptr->data;
  if (BKE_curveprofile_remove_point(profile, point) == false) {
    BKE_report(reports, RPT_ERROR, "Unable to remove path point");
    return;
  }

  RNA_POINTER_INVALIDATE(point_ptr);
}

static void rna_CurveProfile_evaluate(struct CurveProfile *profile,
                                      ReportList *reports,
                                      float length_portion,
                                      float *location)
{
  if (!profile->table) {
    BKE_report(reports, RPT_ERROR, "CurveProfile table not initialized, call initialize()");
  }
  BKE_curveprofile_evaluate_length_portion(profile, length_portion, &location[0], &location[1]);
}

static void rna_CurveProfile_initialize(struct CurveProfile *profile, int segments_len)
{
  BKE_curveprofile_initialize(profile, (short)segments_len);
}

static void rna_CurveProfile_update(struct CurveProfile *profile)
{
  BKE_curveprofile_update(profile, false);
}

#else

static const EnumPropertyItem prop_handle_type_items[] = {
    {HD_AUTO, "AUTO", 0, "Auto Handle", ""},
    {HD_VECT, "VECTOR", 0, "Vector Handle", ""},
    {0, NULL, 0, NULL, NULL},
};

static void rna_def_curveprofilepoint(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;

  srna = RNA_def_struct(brna, "CurveProfilePoint", NULL);
  RNA_def_struct_ui_text(srna, "CurveProfilePoint", "Point of a path used to define a profile");

  prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
  RNA_def_property_float_sdna(prop, NULL, "x");
  RNA_def_property_array(prop, 2);
  RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the path point");

  prop = RNA_def_property(srna, "handle_type_1", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_sdna(prop, NULL, "h1");
  RNA_def_property_enum_items(prop, prop_handle_type_items);
  RNA_def_property_ui_text(
      prop, "First Handle Type", "Path interpolation at this point: Bezier or vector");

  prop = RNA_def_property(srna, "handle_type_2", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_sdna(prop, NULL, "h2");
  RNA_def_property_enum_items(prop, prop_handle_type_items);
  RNA_def_property_ui_text(
      prop, "Second Handle Type", "Path interpolation at this point: Bezier or vector");

  prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", PROF_SELECT);
  RNA_def_property_ui_text(prop, "Select", "Selection state of the path point");
}

static void rna_def_curveprofile_points_api(BlenderRNA *brna, PropertyRNA *cprop)
{
  StructRNA *srna;
  PropertyRNA *parm;
  FunctionRNA *func;

  RNA_def_property_srna(cprop, "CurveProfilePoints");
  srna = RNA_def_struct(brna, "CurveProfilePoints", NULL);
  RNA_def_struct_sdna(srna, "CurveProfile");
  RNA_def_struct_ui_text(srna, "Profile Point", "Collection of Profile Points");

  func = RNA_def_function(srna, "add", "BKE_curveprofile_insert");
  RNA_def_function_ui_description(func, "Add point to the profile");
  parm = RNA_def_float(func,
                       "x",
                       0.0f,
                       -FLT_MAX,
                       FLT_MAX,
                       "X Position",
                       "X Position for new point",
                       -FLT_MAX,
                       FLT_MAX);
  RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
  parm = RNA_def_float(func,
                       "y",
                       0.0f,
                       -FLT_MAX,
                       FLT_MAX,
                       "Y Position",
                       "Y Position for new point",
                       -FLT_MAX,
                       FLT_MAX);
  RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
  parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "New point");
  RNA_def_function_return(func, parm);

  func = RNA_def_function(srna, "remove", "rna_CurveProfile_remove_point");
  RNA_def_function_flag(func, FUNC_USE_REPORTS);
  RNA_def_function_ui_description(func, "Delete point from the profile");
  parm = RNA_def_pointer(func, "point", "CurveProfilePoint", "", "Point to remove");
  RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
  RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
}

static void rna_def_curveprofile(BlenderRNA *brna)
{
  StructRNA *srna;
  PropertyRNA *prop;
  PropertyRNA *parm;
  FunctionRNA *func;

  static const EnumPropertyItem rna_enum_curveprofile_preset_items[] = {
      {PROF_PRESET_LINE, "LINE", 0, "Line", "Default"},
      {PROF_PRESET_SUPPORTS, "SUPPORTS", 0, "Support Loops", "Loops on each side of the profile"},
      {PROF_PRESET_CORNICE, "CORNICE", 0, "Cornice Molding", ""},
      {PROF_PRESET_CROWN, "CROWN", 0, "Crown Molding", ""},
      {PROF_PRESET_STEPS, "STEPS", 0, "Steps", "A number of steps defined by the segments"},
      {0, NULL, 0, NULL, NULL},
  };

  srna = RNA_def_struct(brna, "CurveProfile", NULL);
  RNA_def_struct_ui_text(srna, "CurveProfile", "Profile Path editor used to build a profile path");

  prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE);
  RNA_def_property_enum_sdna(prop, NULL, "preset");
  RNA_def_property_enum_items(prop, rna_enum_curveprofile_preset_items);
  RNA_def_property_ui_text(prop, "Preset", "");

  prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", PROF_USE_CLIP);
  RNA_def_property_ui_text(prop, "Clip", "Force the path view to fit a defined boundary");
  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_clip_set");

  prop = RNA_def_property(srna, "use_sample_straight_edges", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", PROF_SAMPLE_STRAIGHT_EDGES);
  RNA_def_property_ui_text(prop, "Sample Straight Edges", "Sample edges with vector handles");
  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_sample_straight_set");

  prop = RNA_def_property(srna, "use_sample_even_lengths", PROP_BOOLEAN, PROP_NONE);
  RNA_def_property_boolean_sdna(prop, NULL, "flag", PROF_SAMPLE_EVEN_LENGTHS);
  RNA_def_property_ui_text(prop, "Sample Even Lengths", "Sample edges with even lengths");
  RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveProfile_sample_even_set");

  func = RNA_def_function(srna, "update", "rna_CurveProfile_update");
  RNA_def_function_ui_description(func, "Update the profile");

  func = RNA_def_function(srna, "initialize", "rna_CurveProfile_initialize");
  parm = RNA_def_int(func,
                     "totsegments",
                     1,
                     1,
                     1000,
                     "",
                     "The number of segment values to"
                     " initialize the segments table with",
                     1,
                     100);
  RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
  RNA_def_function_ui_description(func, "Set the number of display segments and fill tables");

  prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
  RNA_def_property_collection_sdna(prop, NULL, "path", "path_len");
  RNA_def_property_struct_type(prop, "CurveProfilePoint");
  RNA_def_property_ui_text(prop, "Points", "Profile control points");
  rna_def_curveprofile_points_api(brna, prop);

  prop = RNA_def_property(srna, "segments", PROP_COLLECTION, PROP_NONE);
  RNA_def_property_collection_sdna(prop, NULL, "segments", "segments_len");
  RNA_def_property_struct_type(prop, "CurveProfilePoint");
  RNA_def_property_ui_text(prop, "Segments", "Segments sampled from control points");

  func = RNA_def_function(srna, "evaluate", "rna_CurveProfile_evaluate");
  RNA_def_function_flag(func, FUNC_USE_REPORTS);
  RNA_def_function_ui_description(func, "Evaluate the at the given portion of the path length");
  parm = RNA_def_float(func,
                       "length_portion",
                       0.0f,
                       0.0f,
                       1.0f,
                       "Length Portion",
                       "Portion of the path length to travel before evaluation",
                       0.0f,
                       1.0f);
  RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
  parm = RNA_def_float_vector(func,
                              "location",
                              2,
                              NULL,
                              -100.0f,
                              100.0f,
                              "Location",
                              "The location at the given portion of the profile",
                              -100.0f,
                              100.0f);
  RNA_def_function_output(func, parm);
}

void RNA_def_profile(BlenderRNA *brna)
{
  rna_def_curveprofilepoint(brna);
  rna_def_curveprofile(brna);
}

#endif