1
/* $Id: sceneTimeLine.c 14444 2008-04-16 22:40:48Z hos $
3
* ***** BEGIN GPL LICENSE BLOCK *****
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software Foundation,
17
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20
* All rights reserved.
22
* This is a new part of Blender.
24
* Contributor(s): Joilnen Leite
26
* ***** END GPL LICENSE BLOCK *****
29
#include <BLI_blenlib.h>
33
#include <MEM_guardedalloc.h> /* for MEM_callocN */
35
#include "gen_utils.h"
36
#include "sceneTimeLine.h"
38
// static PyObject *TimeLine_New (PyObject *self);
39
static PyObject *M_TimeLine_Get (PyObject *self, PyObject *args);
41
static char M_TimeLine_Get_doc[]= "Return the Scene.TimeLine.";
43
//----------------------Scene.TimeMarker subsubmodule method def----------------------------
44
struct PyMethodDef M_TimeLine_methods[]= {
45
// {"New", (PyCFunction) M_TimeMarker_New, METH_NOVAR,
46
// M_TimeLine_New_doc},
47
{"Get", (PyCFunction) M_TimeLine_Get, METH_VARARGS,
52
static PyObject *TimeLine_addMarker (BPy_TimeLine *self, PyObject *args);
53
static PyObject *TimeLine_delMarker (BPy_TimeLine *self, PyObject *args);
54
static PyObject *TimeLine_setNameMarker (BPy_TimeLine *self, PyObject *args);
55
static PyObject *TimeLine_getNameMarker (BPy_TimeLine *self, PyObject *args);
56
static PyObject *TimeLine_getFramesMarked (BPy_TimeLine *self, PyObject *args);
58
static PyObject *TimeLine_repr (BPy_TimeLine *self) {
60
return PyString_FromFormat ("[TimeLine]");
63
static PyMethodDef BPy_TimeLine_methods[] = {
64
{"add", (PyCFunction) TimeLine_addMarker,
66
"() - Add timemarker"},
67
{"delete", (PyCFunction) TimeLine_delMarker,
69
"() - delete timemarker"},
70
{"setName", (PyCFunction) TimeLine_setNameMarker,
72
"() - Get timemarker name"},
73
{"getName", (PyCFunction) TimeLine_getNameMarker,
75
"() - Set timemarker name"},
76
{"getMarked", (PyCFunction) TimeLine_getFramesMarked,
78
"() - Get frames timemarked"},
82
/*-----------------------dealloc----------------------------------------*/
83
static void TimeLine_dealloc( BPy_TimeLine * self )
88
/*-----------------------getattr----------------------------------------*/
89
static PyObject *TimeLine_getattr (BPy_TimeLine *self, char *name) {
90
return Py_FindMethod( BPy_TimeLine_methods, ( PyObject * ) self, name );
93
/*-----------------------setattr----------------------------------------*/
94
static int TimeLine_setattr (BPy_TimeLine *self, char *name, PyObject *value) {
96
PyObject *error= NULL;
98
valtuple= Py_BuildValue ("(O)", value);
101
return EXPP_ReturnIntError( PyExc_MemoryError,
102
"TimeLineSetAttr: couldn't create tuple" );
103
if( strcmp( name, "name" ) == 0 )
104
error = TimeLine_setNameMarker (self, valtuple);
105
Py_DECREF (valtuple);
106
if (error != Py_None)
113
//-----------------------BPy_Scene method def------------------------------
114
PyTypeObject TimeLine_Type = {
115
PyObject_HEAD_INIT (NULL) 0, /* ob_size */
116
"TimeLine", /* tp_name */
117
sizeof (BPy_TimeLine), /* tp_basicsize */
120
( destructor ) TimeLine_dealloc, /* tp_dealloc */
121
(printfunc) 0, /* tp_print */
122
(getattrfunc) TimeLine_getattr, /* tp_getattr */
123
(setattrfunc) TimeLine_setattr, /* tp_setattr */
125
(reprfunc) TimeLine_repr, /* tp_repr */
126
0, /* tp_as_number */
127
0, /* tp_as_sequence */
128
0, /* tp_as_mapping */
130
0, /* tp_as_number */
131
0, /* tp_as_sequence */
132
0, /* tp_as_mapping */
135
BPy_TimeLine_methods,
137
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
140
PyObject *TimeLine_Init (void)
144
if (PyType_Ready (&TimeLine_Type) < 0)
146
submodule= Py_InitModule3 ("Blender.Scene.TimeLine", M_TimeLine_methods,
147
"The Blender TimeLine subsubmodule");
152
PyObject *TimeLine_CreatePyObject (BPy_TimeLine *tl) {
155
bl_tl= (BPy_TimeLine *) PyObject_NEW (BPy_TimeLine, &TimeLine_Type);
157
return (( PyObject * ) bl_tl);
161
PyObject *M_TimeLine_Get (PyObject *self, PyObject *args) {
163
return EXPP_incr_ret (Py_None);
166
static PyObject *TimeLine_getFramesMarked (BPy_TimeLine *self, PyObject *args) {
168
PyObject *marker_dict= NULL;
169
TimeMarker *marker_it= NULL;
170
PyObject *tmarker= NULL, *pyo= NULL, *tmpstr;
172
if (!PyArg_ParseTuple (args, "|O", &tmarker))
173
return EXPP_ReturnPyObjError (PyExc_AttributeError,
174
"expected nothing, string or int as arguments.");
179
if (PyString_Check (tmarker) && (BLI_strncpy(s, PyString_AsString (tmarker), 64)) ) {
180
for (marker_it= self->marker_list->first; marker_it; marker_it= marker_it->next)
181
if (!strcmp (marker_it->name, s)) {
182
frm= (int)marker_it->frame;
186
else if (PyInt_Check (tmarker))
187
frm= (int)PyInt_AS_LONG (tmarker);
189
return EXPP_ReturnPyObjError (PyExc_AttributeError,
190
"expected nothing, string or int as arguments.");
192
marker_dict= PyDict_New ();
193
for (marker_it= self->marker_list->first; marker_it; marker_it= marker_it->next){
194
if (marker_it->frame==frm) {
195
pyo= PyDict_GetItem ((PyObject*)marker_dict, PyInt_FromLong ((long int)marker_it->frame));
196
tmpstr = PyString_FromString(marker_it->name);
198
PyList_Append (pyo, tmpstr);
202
PyList_Append (pyo, tmpstr);
206
PyDict_SetItem (marker_dict, PyInt_FromLong ((long int)marker_it->frame), pyo);
216
marker_dict= PyDict_New ();
217
for (marker_it= self->marker_list->first; marker_it; marker_it= marker_it->next) {
218
pyo=PyDict_GetItem ((PyObject*)marker_dict, PyInt_FromLong ((long int)marker_it->frame));
219
tmpstr = PyString_FromString(marker_it->name);
221
PyList_Append (pyo, tmpstr);
225
PyList_Append (pyo, tmpstr);
229
PyDict_SetItem (marker_dict, PyInt_FromLong ((long int)marker_it->frame), pyo);
240
static PyObject *TimeLine_addMarker (BPy_TimeLine *self, PyObject *args) {
242
TimeMarker *marker= NULL, *marker_it= NULL;
244
if (!PyArg_ParseTuple( args, "i", &frame ))
245
return EXPP_ReturnPyObjError (PyExc_TypeError,
246
"expected int as argument.");
247
/* two markers can't be at the same place */
248
for (marker_it= self->marker_list->first; marker_it; marker_it= marker_it->next) {
249
if (marker_it->frame==frame)
250
return EXPP_incr_ret (Py_None);
252
if (frame<self->sfra || frame>self->efra)
253
return EXPP_ReturnPyObjError (PyExc_TypeError, "frame out of range.");
254
marker= MEM_callocN (sizeof(TimeMarker), "TimeMarker");
255
if (!marker) return EXPP_incr_ret (Py_None);
256
marker->frame= frame;
257
BLI_addtail (self->marker_list, marker);
258
return EXPP_incr_ret (Py_None);
261
static PyObject *TimeLine_delMarker (BPy_TimeLine *self, PyObject *args) {
263
TimeMarker *marker= NULL;
265
if (!PyArg_ParseTuple (args, "|i", &frame))
266
return EXPP_ReturnPyObjError (PyExc_TypeError,
267
"expected int as argument.");
269
for (marker= self->marker_list->first; marker; marker= marker->next) {
271
BLI_freelinkN (self->marker_list, marker);
272
else if (marker->frame == frame) {
273
BLI_freelinkN (self->marker_list, marker);
274
return EXPP_incr_ret (Py_None);
278
return EXPP_incr_ret (Py_None);
281
static PyObject *TimeLine_setNameMarker (BPy_TimeLine *self, PyObject *args) {
285
TimeMarker *marker= NULL;
287
if (!PyArg_ParseTuple( args, "is", &frame, &buf))
288
return EXPP_ReturnPyObjError (PyExc_TypeError,
289
"expected int as argument.");
290
PyOS_snprintf (name, sizeof (name), "%s", buf);
291
for (marker= self->marker_list->first; marker; marker= marker->next) {
292
if (marker->frame == frame) {
293
BLI_strncpy(marker->name, name, sizeof(marker->name));
294
return EXPP_incr_ret (Py_None);
298
return EXPP_ReturnPyObjError (PyExc_TypeError, "frame not marked.");
301
static PyObject *TimeLine_getNameMarker (BPy_TimeLine *self, PyObject *args) {
305
if (!PyArg_ParseTuple (args, "i", &frame))
306
return EXPP_ReturnPyObjError (PyExc_TypeError, "expected int as argument.");
308
for (marker= self->marker_list->first; marker; marker= marker->next) {
309
if (marker->frame == frame)
310
return PyString_FromString (marker->name);
313
return EXPP_ReturnPyObjError (PyExc_TypeError, "frame not marked.");