OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFuncti
on0DVectorViewShape.cpp |
| 29 * \ingroup freestyle |
| 30 */ |
| 31 |
| 32 #include "BPy_UnaryFunction0DVectorViewShape.h" |
| 33 |
| 34 #include "../BPy_Convert.h" |
| 35 #include "../Iterator/BPy_Interface0DIterator.h" |
| 36 |
| 37 #include "UnaryFunction0D_vector_ViewShape/BPy_GetOccludersF0D.h" |
| 38 |
| 39 #ifdef __cplusplus |
| 40 extern "C" { |
| 41 #endif |
| 42 |
| 43 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 44 |
| 45 //-------------------MODULE INITIALIZATION-------------------------------- |
| 46 |
| 47 int UnaryFunction0DVectorViewShape_Init(PyObject *module) |
| 48 { |
| 49 if (module == NULL) |
| 50 return -1; |
| 51 |
| 52 if (PyType_Ready(&UnaryFunction0DVectorViewShape_Type) < 0) |
| 53 return -1; |
| 54 Py_INCREF(&UnaryFunction0DVectorViewShape_Type); |
| 55 PyModule_AddObject(module, "UnaryFunction0DVectorViewShape", (PyObject *
)&UnaryFunction0DVectorViewShape_Type); |
| 56 |
| 57 if (PyType_Ready(&GetOccludersF0D_Type) < 0) |
| 58 return -1; |
| 59 Py_INCREF(&GetOccludersF0D_Type); |
| 60 PyModule_AddObject(module, "GetOccludersF0D", (PyObject *)&GetOccludersF
0D_Type); |
| 61 |
| 62 return 0; |
| 63 } |
| 64 |
| 65 //------------------------INSTANCE METHODS ---------------------------------- |
| 66 |
| 67 static char UnaryFunction0DVectorViewShape___doc__[] = |
| 68 "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVectorViewSh
ape`\n" |
| 69 "\n" |
| 70 "Base class for unary functions (functors) that work on\n" |
| 71 ":class:`Interface0DIterator` and return a list of :class:`ViewShape`\n" |
| 72 "objects.\n" |
| 73 "\n" |
| 74 ".. method:: __init__()\n" |
| 75 "\n" |
| 76 " Default constructor.\n"; |
| 77 |
| 78 static int UnaryFunction0DVectorViewShape___init__(BPy_UnaryFunction0DVectorView
Shape* self, PyObject *args, PyObject *kwds) |
| 79 { |
| 80 static const char *kwlist[] = {NULL}; |
| 81 |
| 82 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) |
| 83 return -1; |
| 84 self->uf0D_vectorviewshape = new UnaryFunction0D< std::vector<ViewShape*
> >(); |
| 85 self->uf0D_vectorviewshape->py_uf0D = (PyObject *)self; |
| 86 return 0; |
| 87 } |
| 88 |
| 89 static void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVector
ViewShape* self) |
| 90 { |
| 91 if (self->uf0D_vectorviewshape) |
| 92 delete self->uf0D_vectorviewshape; |
| 93 UnaryFunction0D_Type.tp_dealloc((PyObject*)self); |
| 94 } |
| 95 |
| 96 static PyObject * UnaryFunction0DVectorViewShape___repr__(BPy_UnaryFunction0DVec
torViewShape* self) |
| 97 { |
| 98 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_
name, self->uf0D_vectorviewshape); |
| 99 } |
| 100 |
| 101 static PyObject * UnaryFunction0DVectorViewShape___call__(BPy_UnaryFunction0DVec
torViewShape *self, PyObject *args, PyObject *kwds) |
| 102 { |
| 103 static const char *kwlist[] = {"it", NULL}; |
| 104 PyObject *obj; |
| 105 |
| 106 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Int
erface0DIterator_Type, &obj)) |
| 107 return NULL; |
| 108 |
| 109 if (typeid(*(self->uf0D_vectorviewshape)) == typeid(UnaryFunction0D< std
::vector<ViewShape*> >)) { |
| 110 PyErr_SetString(PyExc_TypeError, "__call__ method not properly o
verridden"); |
| 111 return NULL; |
| 112 } |
| 113 if (self->uf0D_vectorviewshape->operator()(*(((BPy_Interface0DIterator *
)obj)->if0D_it)) < 0) { |
| 114 if (!PyErr_Occurred()) { |
| 115 string class_name(Py_TYPE(self)->tp_name); |
| 116 PyErr_SetString(PyExc_RuntimeError, (class_name + " __ca
ll__ method failed").c_str()); |
| 117 } |
| 118 return NULL; |
| 119 } |
| 120 PyObject *list = PyList_New(0); |
| 121 PyObject *item; |
| 122 for(unsigned int i = 0; i < self->uf0D_vectorviewshape->result.size(); i
++) { |
| 123 ViewShape *v = self->uf0D_vectorviewshape->result[i]; |
| 124 if (v) { |
| 125 item = BPy_ViewShape_from_ViewShape(*v); |
| 126 } else { |
| 127 item = Py_None; |
| 128 Py_INCREF(item); |
| 129 } |
| 130 PyList_Append(list, item); |
| 131 } |
| 132 ········ |
| 133 return list; |
| 134 } |
| 135 |
| 136 /*-----------------------BPy_UnaryFunction0DVectorViewShape type definition ----
--------------------------*/ |
| 137 |
| 138 PyTypeObject UnaryFunction0DVectorViewShape_Type = { |
| 139 PyVarObject_HEAD_INIT(NULL, 0) |
| 140 "UnaryFunction0DVectorViewShape", /* tp_name */ |
| 141 sizeof(BPy_UnaryFunction0DVectorViewShape), /* tp_basicsize */ |
| 142 0, /* tp_itemsize */ |
| 143 (destructor)UnaryFunction0DVectorViewShape___dealloc__, /* tp_dealloc */ |
| 144 0, /* tp_print */ |
| 145 0, /* tp_getattr */ |
| 146 0, /* tp_setattr */ |
| 147 0, /* tp_reserved */ |
| 148 (reprfunc)UnaryFunction0DVectorViewShape___repr__, /* tp_repr */ |
| 149 0, /* tp_as_number */ |
| 150 0, /* tp_as_sequence */ |
| 151 0, /* tp_as_mapping */ |
| 152 0, /* tp_hash */ |
| 153 (ternaryfunc)UnaryFunction0DVectorViewShape___call__, /* tp_call */ |
| 154 0, /* tp_str */ |
| 155 0, /* tp_getattro */ |
| 156 0, /* tp_setattro */ |
| 157 0, /* tp_as_buffer */ |
| 158 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 159 UnaryFunction0DVectorViewShape___doc__, /* tp_doc */ |
| 160 0, /* tp_traverse */ |
| 161 0, /* tp_clear */ |
| 162 0, /* tp_richcompare */ |
| 163 0, /* tp_weaklistoffset */ |
| 164 0, /* tp_iter */ |
| 165 0, /* tp_iternext */ |
| 166 0, /* tp_methods */ |
| 167 0, /* tp_members */ |
| 168 0, /* tp_getset */ |
| 169 &UnaryFunction0D_Type, /* tp_base */ |
| 170 0, /* tp_dict */ |
| 171 0, /* tp_descr_get */ |
| 172 0, /* tp_descr_set */ |
| 173 0, /* tp_dictoffset */ |
| 174 (initproc)UnaryFunction0DVectorViewShape___init__, /* tp_init */ |
| 175 0, /* tp_alloc */ |
| 176 0, /* tp_new */ |
| 177 }; |
| 178 |
| 179 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 180 |
| 181 #ifdef __cplusplus |
| 182 } |
| 183 #endif |
OLD | NEW |