~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
 
2
 * $Id: MTex.c,v 1.5 2004/10/07 19:25:39 stiv Exp $
2
3
 *
3
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
5
 *
41
42
#include "Texture.h"
42
43
#include "constant.h"
43
44
#include "gen_utils.h"
44
 
#include "modules.h"
45
45
 
46
46
 
47
47
/*****************************************************************************/
48
48
/* Python BPy_MTex methods declarations:                                     */
49
49
/*****************************************************************************/
50
 
static PyObject *MTex_setTex(BPy_MTex *self, PyObject *args);
 
50
static PyObject *MTex_setTex( BPy_MTex * self, PyObject * args );
51
51
 
52
52
/*****************************************************************************/
53
53
/* Python method structure definition for Blender.Texture.MTex module:       */
54
54
/*****************************************************************************/
55
55
struct PyMethodDef M_MTex_methods[] = {
56
 
    {NULL, NULL, 0, NULL}
 
56
        {NULL, NULL, 0, NULL}
57
57
};
58
58
 
59
59
/*****************************************************************************/
60
60
/* Python BPy_MTex methods table:                                            */
61
61
/*****************************************************************************/
62
62
static PyMethodDef BPy_MTex_methods[] = {
63
 
 /* name, method, flags, doc */
64
 
  {"setTex", (PyCFunction)MTex_setTex, METH_VARARGS,
65
 
                            "(i) - Set MTex Texture"},
66
 
  {0}
 
63
        /* name, method, flags, doc */
 
64
        {"setTex", ( PyCFunction ) MTex_setTex, METH_VARARGS,
 
65
         "(i) - Set MTex Texture"},
 
66
        {NULL, NULL, 0, NULL}
67
67
};
68
68
 
69
69
/*****************************************************************************/
70
70
/* Python MTex_Type callback function prototypes:                            */
71
71
/*****************************************************************************/
72
 
static void MTex_dealloc (BPy_MTex *self);
73
 
static int MTex_setAttr (BPy_MTex *self, char *name, PyObject *v);
74
 
static int MTex_compare (BPy_MTex *a, BPy_MTex *b);
75
 
static PyObject *MTex_getAttr (BPy_MTex *self, char *name);
76
 
static PyObject *MTex_repr (BPy_MTex *self);
 
72
static void MTex_dealloc( BPy_MTex * self );
 
73
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * v );
 
74
static int MTex_compare( BPy_MTex * a, BPy_MTex * b );
 
75
static PyObject *MTex_getAttr( BPy_MTex * self, char *name );
 
76
static PyObject *MTex_repr( BPy_MTex * self );
77
77
 
78
78
 
79
79
/*****************************************************************************/
80
80
/* Python MTex_Type structure definition:                                    */
81
81
/*****************************************************************************/
82
 
PyTypeObject MTex_Type =
83
 
{
84
 
    PyObject_HEAD_INIT(NULL)
85
 
    0,                              /* ob_size */
86
 
    "Blender MTex",                 /* tp_name */
87
 
    sizeof (BPy_MTex),              /* tp_basicsize */
88
 
    0,                              /* tp_itemsize */
89
 
    /* methods */
90
 
    (destructor)MTex_dealloc,       /* tp_dealloc */
91
 
    0,                              /* tp_print */
92
 
    (getattrfunc)MTex_getAttr,      /* tp_getattr */
93
 
    (setattrfunc)MTex_setAttr,      /* tp_setattr */
94
 
    (cmpfunc)MTex_compare,          /* tp_compare */
95
 
    (reprfunc)MTex_repr,            /* tp_repr */
96
 
    0,                              /* tp_as_number */
97
 
    0,                              /* tp_as_sequence */
98
 
    0,                              /* tp_as_mapping */
99
 
    0,                              /* tp_as_hash */
100
 
    0,0,0,0,0,0,
101
 
    0,                              /* tp_doc */ 
102
 
    0,0,0,0,0,0,
103
 
    0,                              /* tp_methods */
104
 
    0,                              /* tp_members */
 
82
PyTypeObject MTex_Type = {
 
83
        PyObject_HEAD_INIT( NULL ) 
 
84
        0,      /* ob_size */
 
85
        "Blender MTex",         /* tp_name */
 
86
        sizeof( BPy_MTex ),     /* tp_basicsize */
 
87
        0,                      /* tp_itemsize */
 
88
        /* methods */
 
89
        ( destructor ) MTex_dealloc,    /* tp_dealloc */
 
90
        0,                      /* tp_print */
 
91
        ( getattrfunc ) MTex_getAttr,   /* tp_getattr */
 
92
        ( setattrfunc ) MTex_setAttr,   /* tp_setattr */
 
93
        ( cmpfunc ) MTex_compare,       /* tp_compare */
 
94
        ( reprfunc ) MTex_repr, /* tp_repr */
 
95
        0,                      /* tp_as_number */
 
96
        0,                      /* tp_as_sequence */
 
97
        0,                      /* tp_as_mapping */
 
98
        0,                      /* tp_as_hash */
 
99
        0, 0, 0, 0, 0, 0,
 
100
        0,                      /* tp_doc */
 
101
        0, 0, 0, 0, 0, 0,
 
102
        0,                      /* tp_methods */
 
103
        0,                      /* tp_members */
105
104
};
106
105
 
107
106
 
108
 
PyObject *MTex_Init (void)
109
 
{
110
 
    PyObject *submodule;
111
 
    
112
 
    MTex_Type.ob_type = &PyType_Type;
113
 
 
114
 
    submodule = Py_InitModule("Blender.Texture.MTex", M_MTex_methods);
115
 
    
116
 
    return submodule;
117
 
}
118
 
 
119
 
PyObject *MTex_CreatePyObject (MTex *mtex)
120
 
{
121
 
    BPy_MTex *pymtex;
122
 
 
123
 
    pymtex = (BPy_MTex *) PyObject_NEW (BPy_MTex, &MTex_Type);
124
 
    if (!pymtex)
125
 
        return EXPP_ReturnPyObjError (PyExc_MemoryError,
126
 
                                  "couldn't create BPy_MTex PyObject");
127
 
 
128
 
    pymtex->mtex = mtex;
129
 
    return (PyObject *) pymtex;
130
 
}
131
 
 
132
 
MTex *MTex_FromPyObject (PyObject *pyobj)
133
 
{
134
 
    return ((BPy_MTex *)pyobj)->mtex;
135
 
}
136
 
 
137
 
 
138
 
int MTex_CheckPyObject (PyObject *pyobj)
139
 
{
140
 
    return (pyobj->ob_type == &MTex_Type);
 
107
PyObject *MTex_Init( void )
 
108
{
 
109
        PyObject *submodule;
 
110
 
 
111
        MTex_Type.ob_type = &PyType_Type;
 
112
 
 
113
        submodule = Py_InitModule( "Blender.Texture.MTex", M_MTex_methods );
 
114
 
 
115
        return submodule;
 
116
}
 
117
 
 
118
PyObject *MTex_CreatePyObject( MTex * mtex )
 
119
{
 
120
        BPy_MTex *pymtex;
 
121
 
 
122
        pymtex = ( BPy_MTex * ) PyObject_NEW( BPy_MTex, &MTex_Type );
 
123
        if( !pymtex )
 
124
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
125
                                              "couldn't create BPy_MTex PyObject" );
 
126
 
 
127
        pymtex->mtex = mtex;
 
128
        return ( PyObject * ) pymtex;
 
129
}
 
130
 
 
131
MTex *MTex_FromPyObject( PyObject * pyobj )
 
132
{
 
133
        return ( ( BPy_MTex * ) pyobj )->mtex;
 
134
}
 
135
 
 
136
 
 
137
int MTex_CheckPyObject( PyObject * pyobj )
 
138
{
 
139
        return ( pyobj->ob_type == &MTex_Type );
141
140
}
142
141
 
143
142
 
145
144
/* Python BPy_MTex methods:                                                  */
146
145
/*****************************************************************************/
147
146
 
148
 
static PyObject *MTex_setTex(BPy_MTex *self, PyObject *args)
149
 
{
150
 
    BPy_Texture *pytex = NULL;
151
 
    if (!PyArg_ParseTuple(args, "O!", &Texture_Type, &pytex))
152
 
        return EXPP_ReturnPyObjError (PyExc_TypeError,
153
 
                                           "expected Texture argument");
154
 
 
155
 
    if (self->mtex->tex)
156
 
        self->mtex->tex->id.us--;
157
 
    
158
 
    self->mtex->tex = Texture_FromPyObject((PyObject*)pytex);
159
 
 
160
 
    Py_INCREF(Py_None);
161
 
    return Py_None;
162
 
}
163
 
 
164
 
static void MTex_dealloc (BPy_MTex *self)
165
 
{
166
 
    PyObject_DEL (self);
167
 
}
168
 
 
169
 
static PyObject *MTex_getAttr (BPy_MTex *self, char *name)
170
 
{
171
 
    if (STREQ(name, "tex"))
172
 
    {
173
 
        if (self->mtex->tex)
174
 
            return Texture_CreatePyObject (self->mtex->tex);
175
 
        else
176
 
        {
177
 
            Py_INCREF (Py_None);
178
 
            return Py_None;
179
 
        }        
180
 
    }
181
 
    else if (STREQ(name, "texco"))
182
 
        return PyInt_FromLong(self->mtex->texco);
183
 
    else if (STREQ(name, "mapto"))
184
 
        return PyInt_FromLong(self->mtex->mapto);
185
 
    
186
 
    else if (STREQ(name, "__members__"))
187
 
        return Py_BuildValue("[s,s,s]", "tex", "texco", "mapto");
188
 
 
189
 
    /* not an attribute, search the methods table */
190
 
    return Py_FindMethod(BPy_MTex_methods, (PyObject *)self, name);
191
 
}
192
 
 
193
 
static int MTex_setAttr (BPy_MTex *self, char *name, PyObject *value)
194
 
{
195
 
    PyObject *valtuple; 
196
 
    PyObject *error = NULL;
197
 
 
198
 
    /* Put "value" in a tuple, because we want to pass it to functions  *
199
 
     * that only accept PyTuples.                                       */
200
 
    valtuple = Py_BuildValue("(O)", value);
201
 
    if (!valtuple)
202
 
        return EXPP_ReturnIntError(PyExc_MemoryError,
203
 
                                "MTex_setAttr: couldn't create PyTuple");
204
 
 
205
 
    if (STREQ(name, "tex"))
206
 
        error = MTex_setTex(self, valtuple);
207
 
    else if (STREQ(name, "texco"))
208
 
    {
209
 
        if (PyInt_Check(value))
210
 
        {
211
 
            int texco = PyInt_AsLong(value);
212
 
            /* TODO: sanity-check this input! */
213
 
            self->mtex->texco = texco;
214
 
            Py_INCREF (Py_None); /* because we decref it below */
215
 
            error = Py_None;
216
 
        }            
217
 
    }
218
 
    else if (STREQ(name, "mapto"))
219
 
    {
220
 
        if (PyInt_Check(value))
221
 
        {
222
 
            int mapto = PyInt_AsLong(value);
223
 
            /* TODO: sanity-check this input! */
224
 
            self->mtex->mapto = mapto;
225
 
            Py_INCREF (Py_None); /* because we decref it below */
226
 
            error = Py_None;
227
 
        }            
228
 
    }
229
 
    
230
 
    else { 
231
 
        /* Error */
232
 
        Py_DECREF(valtuple);
233
 
        return EXPP_ReturnIntError (PyExc_KeyError, "attribute not found");
234
 
    }
235
 
 
236
 
    Py_DECREF (valtuple);
237
 
 
238
 
    if (error != Py_None) return -1;
239
 
 
240
 
    /* Py_None was INCREF'd by the set*() function, so we need to DECREF it */
241
 
    Py_DECREF (Py_None);
242
 
    
243
 
    return 0;
244
 
}
245
 
 
246
 
static int MTex_compare (BPy_MTex *a, BPy_MTex *b)
247
 
{
248
 
    return (a->mtex == b->mtex) ? 0 : -1;
249
 
}
250
 
 
251
 
static PyObject *MTex_repr (BPy_MTex *self)
252
 
{
253
 
    return PyString_FromFormat("[MTex]");
254
 
}
255
 
 
 
147
static PyObject *MTex_setTex( BPy_MTex * self, PyObject * args )
 
148
{
 
149
        BPy_Texture *pytex = NULL;
 
150
        if( !PyArg_ParseTuple( args, "O!", &Texture_Type, &pytex ) )
 
151
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
152
                                              "expected Texture argument" );
 
153
 
 
154
        if( self->mtex->tex )
 
155
                self->mtex->tex->id.us--;
 
156
 
 
157
        self->mtex->tex = Texture_FromPyObject( ( PyObject * ) pytex );
 
158
 
 
159
        Py_INCREF( Py_None );
 
160
        return Py_None;
 
161
}
 
162
 
 
163
static void MTex_dealloc( BPy_MTex * self )
 
164
{
 
165
        PyObject_DEL( self );
 
166
}
 
167
 
 
168
static PyObject *MTex_getAttr( BPy_MTex * self, char *name )
 
169
{
 
170
        if( STREQ( name, "tex" ) ) {
 
171
                if( self->mtex->tex )
 
172
                        return Texture_CreatePyObject( self->mtex->tex );
 
173
                else {
 
174
                        Py_INCREF( Py_None );
 
175
                        return Py_None;
 
176
                }
 
177
        } else if( STREQ( name, "texco" ) )
 
178
                return PyInt_FromLong( self->mtex->texco );
 
179
        else if( STREQ( name, "mapto" ) )
 
180
                return PyInt_FromLong( self->mtex->mapto );
 
181
 
 
182
        else if( STREQ( name, "__members__" ) )
 
183
                return Py_BuildValue( "[s,s,s]", "tex", "texco", "mapto" );
 
184
 
 
185
        /* not an attribute, search the methods table */
 
186
        return Py_FindMethod( BPy_MTex_methods, ( PyObject * ) self, name );
 
187
}
 
188
 
 
189
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * value )
 
190
{
 
191
        PyObject *valtuple;
 
192
        PyObject *error = NULL;
 
193
 
 
194
        /* Put "value" in a tuple, because we want to pass it to functions  *
 
195
         * that only accept PyTuples.                                       */
 
196
        valtuple = Py_BuildValue( "(O)", value );
 
197
        if( !valtuple )
 
198
                return EXPP_ReturnIntError( PyExc_MemoryError,
 
199
                                            "MTex_setAttr: couldn't create PyTuple" );
 
200
 
 
201
        if( STREQ( name, "tex" ) )
 
202
                error = MTex_setTex( self, valtuple );
 
203
        else if( STREQ( name, "texco" ) ) {
 
204
                if( PyInt_Check( value ) ) {
 
205
                        int texco = PyInt_AsLong( value );
 
206
                        /* TODO: sanity-check this input! */
 
207
                        self->mtex->texco = texco;
 
208
                        Py_INCREF( Py_None );   /* because we decref it below */
 
209
                        error = Py_None;
 
210
                }
 
211
        } else if( STREQ( name, "mapto" ) ) {
 
212
                if( PyInt_Check( value ) ) {
 
213
                        int mapto = PyInt_AsLong( value );
 
214
                        /* TODO: sanity-check this input! */
 
215
                        self->mtex->mapto = mapto;
 
216
                        Py_INCREF( Py_None );   /* because we decref it below */
 
217
                        error = Py_None;
 
218
                }
 
219
        }
 
220
 
 
221
        else {
 
222
                /* Error */
 
223
                Py_DECREF( valtuple );
 
224
                return EXPP_ReturnIntError( PyExc_KeyError,
 
225
                                            "attribute not found" );
 
226
        }
 
227
 
 
228
        Py_DECREF( valtuple );
 
229
 
 
230
        if( error != Py_None )
 
231
                return -1;
 
232
 
 
233
        /* Py_None was INCREF'd by the set*() function, so we need to DECREF it */
 
234
        Py_DECREF( Py_None );
 
235
 
 
236
        return 0;
 
237
}
 
238
 
 
239
static int MTex_compare( BPy_MTex * a, BPy_MTex * b )
 
240
{
 
241
        return ( a->mtex == b->mtex ) ? 0 : -1;
 
242
}
 
243
 
 
244
static PyObject *MTex_repr( BPy_MTex * self )
 
245
{
 
246
        return PyString_FromFormat( "[MTex]" );
 
247
}