Blender  V2.93
rna_fcurve_api.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  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <time.h>
28 
29 #include "BLI_utildefines.h"
30 
31 #include "RNA_define.h"
32 
33 #include "DNA_anim_types.h"
34 #include "DNA_scene_types.h"
35 
36 #include "rna_internal.h" /* own include */
37 
38 #ifdef RNA_RUNTIME
39 
40 # include <stddef.h>
41 
42 # include "BKE_fcurve.h"
43 
44 # include "BLI_math.h"
45 
46 static void rna_FCurve_convert_to_samples(FCurve *fcu, ReportList *reports, int start, int end)
47 {
48  /* XXX fcurve_store_samples uses end frame included,
49  * which is not consistent with usual behavior in Blender,
50  * nor python slices, etc. Let have public py API be consistent here at least. */
51  end--;
52  if (start > end) {
53  BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end + 1);
54  }
55  else if (fcu->fpt) {
56  BKE_report(reports, RPT_WARNING, "FCurve has already sample points");
57  }
58  else if (!fcu->bezt) {
59  BKE_report(reports, RPT_WARNING, "FCurve has no keyframes");
60  }
61  else {
64  }
65 }
66 
67 static void rna_FCurve_convert_to_keyframes(FCurve *fcu, ReportList *reports, int start, int end)
68 {
69  if (start >= end) {
70  BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end);
71  }
72  else if (fcu->bezt) {
73  BKE_report(reports, RPT_WARNING, "FCurve has already keyframes");
74  }
75  else if (!fcu->fpt) {
76  BKE_report(reports, RPT_WARNING, "FCurve has no sample points");
77  }
78  else {
79  fcurve_samples_to_keyframes(fcu, start, end);
81  }
82 }
83 
84 #else
85 
87 {
88  FunctionRNA *func;
89  PropertyRNA *parm;
90 
91  func = RNA_def_function(srna, "convert_to_samples", "rna_FCurve_convert_to_samples");
93  func, "Convert current FCurve from keyframes to sample points, if necessary");
95  parm = RNA_def_int(
96  func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
98  parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
100 
101  func = RNA_def_function(srna, "convert_to_keyframes", "rna_FCurve_convert_to_keyframes");
103  func,
104  "Convert current FCurve from sample points to keyframes (linear interpolation), "
105  "if necessary");
107  parm = RNA_def_int(
108  func, "start", 0, MINAFRAME, MAXFRAME, "Start Frame", "", MINAFRAME, MAXFRAME);
110  parm = RNA_def_int(func, "end", 0, MINAFRAME, MAXFRAME, "End Frame", "", MINAFRAME, MAXFRAME);
112 }
113 
115 {
116  /* FunctionRNA *func; */
117  /* PropertyRNA *parm; */
118 }
119 
120 #endif
void fcurve_store_samples(struct FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
Definition: fcurve.c:1108
void fcurve_samples_to_keyframes(struct FCurve *fcu, const int start, const int end)
Definition: fcurve.c:1156
float fcurve_samplingcb_evalcurve(struct FCurve *fcu, void *data, float evaltime)
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define UNUSED(x)
#define MINAFRAME
#define MAXFRAME
@ PARM_REQUIRED
Definition: RNA_types.h:337
@ FUNC_USE_REPORTS
Definition: RNA_types.h:578
#define NC_ANIMATION
Definition: WM_types.h:289
#define NA_EDITED
Definition: WM_types.h:462
#define ND_ANIMCHAN
Definition: WM_types.h:396
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
Definition: rna_define.c:4262
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
Definition: rna_define.c:4337
void RNA_def_function_flag(FunctionRNA *func, int flag)
Definition: rna_define.c:4332
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_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
Definition: rna_define.c:1547
void RNA_api_fcurves(StructRNA *srna)
void RNA_api_drivers(StructRNA *UNUSED(srna))
FPoint * fpt
BezTriple * bezt
void WM_main_add_notifier(unsigned int type, void *reference)