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