Blender  V2.93
bpy_app_alembic.c
Go to the documentation of this file.
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) 2016 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BLI_utildefines.h"
25 #include <Python.h>
26 
27 #include "bpy_app_alembic.h"
28 
29 #include "../generic/py_capi_utils.h"
30 
31 #ifdef WITH_ALEMBIC
32 # include "ABC_alembic.h"
33 #endif
34 
35 static PyTypeObject BlenderAppABCType;
36 
37 static PyStructSequence_Field app_alembic_info_fields[] = {
38  {"supported", "Boolean, True when Blender is built with Alembic support"},
39  {"version", "The Alembic version as a tuple of 3 numbers"},
40  {"version_string", "The Alembic version formatted as a string"},
41  {NULL},
42 };
43 
44 static PyStructSequence_Desc app_alembic_info_desc = {
45  "bpy.app.alembic", /* name */
46  "This module contains information about Alembic blender is linked against", /* doc */
47  app_alembic_info_fields, /* fields */
49 };
50 
51 static PyObject *make_alembic_info(void)
52 {
53  PyObject *alembic_info = PyStructSequence_New(&BlenderAppABCType);
54 
55  if (alembic_info == NULL) {
56  return NULL;
57  }
58 
59  int pos = 0;
60 
61 #ifndef WITH_ALEMBIC
62 # define SetStrItem(str) PyStructSequence_SET_ITEM(alembic_info, pos++, PyUnicode_FromString(str))
63 #endif
64 
65 #define SetObjItem(obj) PyStructSequence_SET_ITEM(alembic_info, pos++, obj)
66 
67 #ifdef WITH_ALEMBIC
68  const int curversion = ABC_get_version();
69  const int major = curversion / 10000;
70  const int minor = (curversion / 100) - (major * 100);
71  const int patch = curversion - ((curversion / 100) * 100);
72 
73  SetObjItem(PyBool_FromLong(1));
74  SetObjItem(PyC_Tuple_Pack_I32(major, minor, patch));
75  SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", major, minor, patch));
76 #else
77  SetObjItem(PyBool_FromLong(0));
79  SetStrItem("Unknown");
80 #endif
81 
82  if (UNLIKELY(PyErr_Occurred())) {
83  Py_DECREF(alembic_info);
84  return NULL;
85  }
86 
87 #undef SetStrItem
88 #undef SetObjItem
89 
90  return alembic_info;
91 }
92 
93 PyObject *BPY_app_alembic_struct(void)
94 {
95  PyStructSequence_InitType(&BlenderAppABCType, &app_alembic_info_desc);
96 
97  PyObject *ret = make_alembic_info();
98 
99  /* prevent user from creating new instances */
100  BlenderAppABCType.tp_init = NULL;
101  BlenderAppABCType.tp_new = NULL;
102  BlenderAppABCType.tp_hash = (hashfunc)
103  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
104 
105  return ret;
106 }
int ABC_get_version(void)
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyTypeObject BlenderAppABCType
PyObject * BPY_app_alembic_struct(void)
static PyStructSequence_Field app_alembic_info_fields[]
#define SetStrItem(str)
static PyObject * make_alembic_info(void)
static PyStructSequence_Desc app_alembic_info_desc
#define SetObjItem(obj)
uint pos
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:67
return ret