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