~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/IDProp.c

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
                        return PyInt_FromLong( (long)prop->data.val );
61
61
                case IDP_FLOAT:
62
62
                        return PyFloat_FromDouble( (double)(*(float*)(&prop->data.val)) );
 
63
                case IDP_DOUBLE:
 
64
                        return PyFloat_FromDouble( (*(double*)(&prop->data.val)) );
63
65
                case IDP_GROUP:
64
66
                        /*blegh*/
65
67
                        {
128
130
                        Py_XDECREF(value);
129
131
                        break;
130
132
                }
131
 
 
 
133
                case IDP_DOUBLE:
 
134
                {
 
135
                        double dvalue;
 
136
                        if (!PyNumber_Check(value))
 
137
                                return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!");
 
138
                        value = PyNumber_Float(value);
 
139
                        if (!value)
 
140
                                return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!");
 
141
                        dvalue = (float) PyFloat_AsDouble(value);
 
142
                        *(double*)&self->prop->data.val = dvalue;
 
143
                        Py_XDECREF(value);
 
144
                        break;
 
145
                }
132
146
                default:
133
147
                        return EXPP_ReturnIntError(PyExc_AttributeError, "attempt to set read-only attribute!");
134
148
        }
140
154
        return PyString_FromString(self->prop->name);
141
155
}
142
156
 
143
 
int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *bleh)
 
157
static int BPy_IDGroup_SetName(BPy_IDProperty *self, PyObject *value, void *bleh)
144
158
{
145
159
        char *st;
146
160
        if (!PyString_Check(value))
154
168
        return 0;
155
169
}
156
170
 
157
 
PyObject *BPy_IDGroup_GetType(BPy_IDProperty *self)
 
171
static PyObject *BPy_IDGroup_GetType(BPy_IDProperty *self)
158
172
{
159
173
        return PyInt_FromLong((long)self->prop->type);
160
174
}
167
181
         {NULL, NULL, NULL, NULL, NULL}
168
182
};
169
183
         
170
 
int BPy_IDGroup_Map_Len(BPy_IDProperty *self)
 
184
static int BPy_IDGroup_Map_Len(BPy_IDProperty *self)
171
185
{
172
186
        if (self->prop->type != IDP_GROUP)
173
187
                return EXPP_ReturnIntError( PyExc_TypeError,
176
190
        return self->prop->len;
177
191
}
178
192
 
179
 
PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
 
193
static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
180
194
{
181
195
        IDProperty *loop;
182
196
        char *st;
198
212
}
199
213
 
200
214
/*returns NULL on success, error string on failure*/
201
 
char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob)
 
215
static char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObject *ob)
202
216
{
203
217
        IDProperty *prop = NULL;
204
218
        IDPropertyTemplate val = {0};
205
219
        
206
220
        if (PyFloat_Check(ob)) {
207
 
                val.f = (float) PyFloat_AsDouble(ob);
208
 
                prop = IDP_New(IDP_FLOAT, val, name);
 
221
                val.d = PyFloat_AsDouble(ob);
 
222
                prop = IDP_New(IDP_DOUBLE, val, name);
209
223
        } else if (PyInt_Check(ob)) {
210
224
                val.i = (int) PyInt_AsLong(ob);
211
225
                prop = IDP_New(IDP_INT, val, name);
223
237
                val.array.len = PySequence_Length(ob);
224
238
                for (i=0; i<val.array.len; i++) {
225
239
                        item = PySequence_GetItem(ob, i);
226
 
                        if (PyFloat_Check(item)) val.array.type = IDP_FLOAT;
 
240
                        if (PyFloat_Check(item)) val.array.type = IDP_DOUBLE;
227
241
                        else if (!PyInt_Check(item)) return "only floats and ints are allowed in ID property arrays";
228
242
                        Py_XDECREF(item);
229
243
                }
236
250
                                ((int*)prop->data.pointer)[i] = (int)PyInt_AsLong(item);
237
251
                        } else {
238
252
                                item = PyNumber_Float(item);
239
 
                                ((float*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item);
 
253
                                ((double*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item);
240
254
                        }
241
255
                        Py_XDECREF(item);
242
256
                }
283
297
        return NULL;
284
298
}
285
299
 
286
 
int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
 
300
static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
287
301
{
288
302
        char *err;
289
303
        
311
325
        return 0;
312
326
}
313
327
 
314
 
PyObject *BPy_IDGroup_SpawnIterator(BPy_IDProperty *self)
 
328
static PyObject *BPy_IDGroup_SpawnIterator(BPy_IDProperty *self)
315
329
{
316
330
        BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &IDGroup_Iter_Type);
317
331
        
325
339
        return (PyObject*) iter;
326
340
}
327
341
 
328
 
PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
 
342
static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
329
343
{
330
344
        switch (prop->type) {
331
345
                case IDP_STRING:
334
348
                case IDP_FLOAT:
335
349
                        return PyFloat_FromDouble(*((float*)&prop->data.val));
336
350
                        break;
 
351
                case IDP_DOUBLE:
 
352
                        return PyFloat_FromDouble(*((double*)&prop->data.val));
 
353
                        break;
337
354
                case IDP_INT:
338
355
                        return PyInt_FromLong( (long)prop->data.val );
339
356
                        break;
347
364
                                           "PyList_New() failed" );
348
365
                        
349
366
                        for (i=0; i<prop->len; i++) {
350
 
                                if (prop->subtype == IDP_FLOAT)
 
367
                                if (prop->subtype == IDP_FLOAT) {
351
368
                                                PyList_SetItem(seq, i,
352
369
                                                PyFloat_FromDouble(((float*)prop->data.pointer)[i]));
353
 
                                
354
 
                                else    PyList_SetItem(seq, i,
355
 
                                                PyInt_FromLong(((int*)prop->data.pointer)[i]));
 
370
                                } else if (prop->subtype == IDP_DOUBLE) {
 
371
                                                PyList_SetItem(seq, i,
 
372
                                                PyFloat_FromDouble(((double*)prop->data.pointer)[i]));                          
 
373
                                } else  { PyList_SetItem(seq, i,
 
374
                                                  PyInt_FromLong(((int*)prop->data.pointer)[i]));
 
375
                                }
356
376
                        }
357
377
                        return seq;
358
378
                }
381
401
                                           "eek!! a property exists with a bad type code!!!" );
382
402
}
383
403
 
384
 
PyObject *BPy_IDGroup_Pop(BPy_IDProperty *self, PyObject *value)
 
404
static PyObject *BPy_IDGroup_Pop(BPy_IDProperty *self, PyObject *value)
385
405
{
386
406
        IDProperty *loop;
387
407
        PyObject *pyform;
411
431
                   "item not in group" );
412
432
}
413
433
 
414
 
PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self)
 
434
static PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self)
415
435
{
416
436
        BPy_IDGroup_Iter *iter = PyObject_New(BPy_IDGroup_Iter, &IDGroup_Iter_Type);
417
437
        
426
446
        return (PyObject*) iter;
427
447
}
428
448
 
429
 
PyObject *BPy_IDGroup_GetKeys(BPy_IDProperty *self)
 
449
static PyObject *BPy_IDGroup_GetKeys(BPy_IDProperty *self)
430
450
{
431
451
        PyObject *seq = PyList_New(self->prop->len);
432
452
        IDProperty *loop;
451
471
                /*set correct group length*/
452
472
                self->prop->len = i;
453
473
                
454
 
                /*free the old list*/
 
474
                /*free the list*/
455
475
                Py_DECREF(seq);
456
476
                
457
477
                /*call self again*/
461
481
        return seq;
462
482
}
463
483
 
464
 
PyObject *BPy_IDGroup_GetValues(BPy_IDProperty *self)
 
484
static PyObject *BPy_IDGroup_GetValues(BPy_IDProperty *self)
465
485
{
466
486
        PyObject *seq = PyList_New(self->prop->len);
467
487
        IDProperty *loop;
497
517
        return seq;
498
518
}
499
519
 
500
 
PyObject *BPy_IDGroup_HasKey(BPy_IDProperty *self, PyObject *value)
 
520
static PyObject *BPy_IDGroup_HasKey(BPy_IDProperty *self, PyObject *value)
501
521
{
502
522
        IDProperty *loop;
503
523
        char *name = PyString_AsString(value);
513
533
        Py_RETURN_FALSE;
514
534
}
515
535
 
516
 
PyObject *BPy_IDGroup_Update(BPy_IDProperty *self, PyObject *vars)
 
536
static PyObject *BPy_IDGroup_Update(BPy_IDProperty *self, PyObject *vars)
517
537
{
518
538
        PyObject *pyob, *pkey, *pval;
519
539
        Py_ssize_t i=0;
535
555
        Py_RETURN_NONE;
536
556
}
537
557
 
538
 
PyObject *BPy_IDGroup_ConvertToPy(BPy_IDProperty *self)
 
558
static PyObject *BPy_IDGroup_ConvertToPy(BPy_IDProperty *self)
539
559
{
540
560
        return BPy_IDGroup_MapDataToPy(self->prop);
541
561
}
645
665
 
646
666
/********Array Wrapper********/
647
667
 
648
 
PyObject *IDArray_repr(BPy_IDArray *self)
 
668
static PyObject *IDArray_repr(BPy_IDArray *self)
649
669
{
650
670
        return PyString_FromString("(ID Array)");
651
671
}
652
672
 
653
673
 
654
 
PyObject *BPy_IDArray_GetType(BPy_IDArray *self)
 
674
static PyObject *BPy_IDArray_GetType(BPy_IDArray *self)
655
675
{
656
676
        return PyInt_FromLong( (long)self->prop->subtype );
657
677
}
658
678
 
659
 
PyObject *BPy_IDArray_GetLen(BPy_IDArray *self)
 
679
static PyObject *BPy_IDArray_GetLen(BPy_IDArray *self)
660
680
{
661
681
        return PyInt_FromLong( (long)self->prop->len );
662
682
}
673
693
        {NULL, NULL, NULL, NULL, NULL},
674
694
};
675
695
 
676
 
int BPy_IDArray_Len(BPy_IDArray *self)
 
696
static int BPy_IDArray_Len(BPy_IDArray *self)
677
697
{
678
698
        return self->prop->len;
679
699
}
680
700
 
681
 
PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index)
 
701
static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index)
682
702
{
683
703
        if (index < 0 || index >= self->prop->len)
684
704
                return EXPP_ReturnPyObjError( PyExc_IndexError,
688
708
                case IDP_FLOAT:
689
709
                        return PyFloat_FromDouble( (double)(((float*)self->prop->data.pointer)[index]));
690
710
                        break;
 
711
                case IDP_DOUBLE:
 
712
                        return PyFloat_FromDouble( (((double*)self->prop->data.pointer)[index]));
 
713
                        break;          
691
714
                case IDP_INT:
692
715
                        return PyInt_FromLong( (long)((int*)self->prop->data.pointer)[index] );
693
716
                        break;
696
719
                                "invalid/corrupt array type!");
697
720
}
698
721
 
699
 
int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val)
 
722
static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val)
700
723
{
701
724
        int i;
702
725
        float f;
703
 
 
 
726
        double d;
 
727
        
704
728
        if (index < 0 || index >= self->prop->len)
705
729
                return EXPP_ReturnIntError( PyExc_RuntimeError,
706
730
                                "index out of range!");
717
741
                        ((float*)self->prop->data.pointer)[index] = f;
718
742
                        Py_XDECREF(val);
719
743
                        break;
 
744
                case IDP_DOUBLE:
 
745
                        if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError,
 
746
                                "expected a float");
 
747
                        val = PyNumber_Float(val);
 
748
                        if (!val) return EXPP_ReturnIntError( PyExc_TypeError,
 
749
                                "expected a float");
 
750
 
 
751
                        d = (double) PyFloat_AsDouble(val);
 
752
                        ((double*)self->prop->data.pointer)[index] = d;
 
753
                        Py_XDECREF(val);
 
754
                        break;
720
755
                case IDP_INT:
721
756
                        if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError,
722
757
                                "expected an int");
830
865
 
831
866
/*********** ID Property Group iterator ********/
832
867
 
833
 
PyObject *IDGroup_Iter_iterself(PyObject *self)
 
868
static PyObject *IDGroup_Iter_iterself(PyObject *self)
834
869
{
835
870
        Py_XINCREF(self);
836
871
        return self;
837
872
}
838
873
 
839
 
PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self)
 
874
static PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self)
840
875
{
841
876
        return PyString_FromString("(ID Property Group)");
842
877
}
843
878
 
844
 
PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
 
879
static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
845
880
{
846
881
        IDProperty *cur=NULL;
847
882
        PyObject *tmpval;