Bevel mod: cleanup flags and extra data.
[blender.git] / source / blender / python / intern / bpy_app_opensubdiv.c
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
17 /** \file
18  * \ingroup pythonintern
19  */
20
21 #include <Python.h>
22 #include "BLI_utildefines.h"
23
24 #include "bpy_app_opensubdiv.h"
25
26 #include "../generic/py_capi_utils.h"
27
28 #ifdef WITH_OPENSUBDIV
29 #  include "opensubdiv_capi.h"
30 #endif
31
32 static PyTypeObject BlenderAppOpenSubdivType;
33
34 static PyStructSequence_Field app_opensubdiv_info_fields[] = {
35         {(char *)"supported", (char *)("Boolean, True when Blender is built with OpenSubdiv support")},
36         {(char *)("version"), (char *)("The OpenSubdiv version as a tuple of 3 numbers")},
37         {(char *)("version_string"), (char *)("The OpenSubdiv version formatted as a string")},
38         {NULL},
39 };
40
41 static PyStructSequence_Desc app_opensubdiv_info_desc = {
42         (char *)"bpy.app.opensubdiv",     /* name */
43         (char *)"This module contains information about OpenSubdiv blender is linked against",    /* doc */
44         app_opensubdiv_info_fields,    /* fields */
45         ARRAY_SIZE(app_opensubdiv_info_fields) - 1,
46 };
47
48 static PyObject *make_opensubdiv_info(void)
49 {
50         PyObject *opensubdiv_info;
51         int pos = 0;
52
53         opensubdiv_info = PyStructSequence_New(&BlenderAppOpenSubdivType);
54         if (opensubdiv_info == NULL) {
55                 return NULL;
56         }
57
58 #ifndef WITH_OPENSUBDIV
59 #define SetStrItem(str) \
60         PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
61 #endif
62
63 #define SetObjItem(obj) \
64         PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
65
66 #ifdef WITH_OPENSUBDIV
67         int curversion = openSubdiv_getVersionHex();
68         SetObjItem(PyBool_FromLong(1));
69         SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
70         SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d",
71                                         curversion / 10000, (curversion / 100) % 100, curversion % 100));
72 #else
73         SetObjItem(PyBool_FromLong(0));
74         SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
75         SetStrItem("Unknown");
76 #endif
77
78         if (PyErr_Occurred()) {
79                 Py_CLEAR(opensubdiv_info);
80                 return NULL;
81         }
82
83 #undef SetStrItem
84 #undef SetObjItem
85
86         return opensubdiv_info;
87 }
88
89 PyObject *BPY_app_opensubdiv_struct(void)
90 {
91         PyObject *ret;
92
93         PyStructSequence_InitType(&BlenderAppOpenSubdivType, &app_opensubdiv_info_desc);
94
95         ret = make_opensubdiv_info();
96
97         /* prevent user from creating new instances */
98         BlenderAppOpenSubdivType.tp_init = NULL;
99         BlenderAppOpenSubdivType.tp_new = NULL;
100         /* without this we can't do set(sys.modules) [#29635] */
101         BlenderAppOpenSubdivType.tp_hash = (hashfunc)_Py_HashPointer;
102
103         return ret;
104 }