Blender  V3.3
BPy_ViewMap.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_ViewMap.h"
8 
9 #include "BPy_BBox.h"
10 #include "BPy_Convert.h"
11 #include "Interface1D/BPy_FEdge.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 using namespace Freestyle;
19 
21 
22 //-------------------MODULE INITIALIZATION--------------------------------
23 int ViewMap_Init(PyObject *module)
24 {
25  if (module == nullptr) {
26  return -1;
27  }
28 
29  if (PyType_Ready(&ViewMap_Type) < 0) {
30  return -1;
31  }
32  Py_INCREF(&ViewMap_Type);
33  PyModule_AddObject(module, "ViewMap", (PyObject *)&ViewMap_Type);
34 
35  return 0;
36 }
37 
38 /*----------------------ViewMap methods----------------------------*/
39 
40 PyDoc_STRVAR(ViewMap_doc,
41  "Class defining the ViewMap.\n"
42  "\n"
43  ".. method:: __init__()\n"
44  "\n"
45  " Default constructor.");
46 
47 static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
48 {
49  static const char *kwlist[] = {nullptr};
50 
51  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
52  return -1;
53  }
54  self->vm = new ViewMap();
55  return 0;
56 }
57 
58 static void ViewMap_dealloc(BPy_ViewMap *self)
59 {
60  delete self->vm;
61  Py_TYPE(self)->tp_free((PyObject *)self);
62 }
63 
64 static PyObject *ViewMap_repr(BPy_ViewMap *self)
65 {
66  return PyUnicode_FromFormat("ViewMap - address: %p", self->vm);
67 }
68 
69 PyDoc_STRVAR(ViewMap_get_closest_viewedge_doc,
70  ".. method:: get_closest_viewedge(x, y)\n"
71  "\n"
72  " Gets the ViewEdge nearest to the 2D point specified as arguments.\n"
73  "\n"
74  " :arg x: X coordinate of a 2D point.\n"
75  " :type x: float\n"
76  " :arg y: Y coordinate of a 2D point.\n"
77  " :type y: float\n"
78  " :return: The ViewEdge nearest to the specified 2D point.\n"
79  " :rtype: :class:`ViewEdge`");
80 
81 static PyObject *ViewMap_get_closest_viewedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
82 {
83  static const char *kwlist[] = {"x", "y", nullptr};
84  double x, y;
85 
86  if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) {
87  return nullptr;
88  }
89  ViewEdge *ve = const_cast<ViewEdge *>(self->vm->getClosestViewEdge(x, y));
90  if (ve) {
91  return BPy_ViewEdge_from_ViewEdge(*ve);
92  }
93  Py_RETURN_NONE;
94 }
95 
96 PyDoc_STRVAR(ViewMap_get_closest_fedge_doc,
97  ".. method:: get_closest_fedge(x, y)\n"
98  "\n"
99  " Gets the FEdge nearest to the 2D point specified as arguments.\n"
100  "\n"
101  " :arg x: X coordinate of a 2D point.\n"
102  " :type x: float\n"
103  " :arg y: Y coordinate of a 2D point.\n"
104  " :type y: float\n"
105  " :return: The FEdge nearest to the specified 2D point.\n"
106  " :rtype: :class:`FEdge`");
107 
108 static PyObject *ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
109 {
110  static const char *kwlist[] = {"x", "y", nullptr};
111  double x, y;
112 
113  if (!PyArg_ParseTupleAndKeywords(args, kwds, "dd", (char **)kwlist, &x, &y)) {
114  return nullptr;
115  }
116  FEdge *fe = const_cast<FEdge *>(self->vm->getClosestFEdge(x, y));
117  if (fe) {
118  return Any_BPy_FEdge_from_FEdge(*fe);
119  }
120  Py_RETURN_NONE;
121 }
122 
123 // static ViewMap *getInstance ();
124 
125 static PyMethodDef BPy_ViewMap_methods[] = {
126  {"get_closest_viewedge",
127  (PyCFunction)ViewMap_get_closest_viewedge,
128  METH_VARARGS | METH_KEYWORDS,
129  ViewMap_get_closest_viewedge_doc},
130  {"get_closest_fedge",
131  (PyCFunction)ViewMap_get_closest_fedge,
132  METH_VARARGS | METH_KEYWORDS,
133  ViewMap_get_closest_fedge_doc},
134  {nullptr, nullptr, 0, nullptr},
135 };
136 
137 /*----------------------ViewMap get/setters ----------------------------*/
138 
139 PyDoc_STRVAR(ViewMap_scene_bbox_doc,
140  "The 3D bounding box of the scene.\n"
141  "\n"
142  ":type: :class:`BBox`");
143 
144 static PyObject *ViewMap_scene_bbox_get(BPy_ViewMap *self, void *UNUSED(closure))
145 {
146  return BPy_BBox_from_BBox(self->vm->getScene3dBBox());
147 }
148 
149 static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void *UNUSED(closure))
150 {
151  if (!BPy_BBox_Check(value)) {
152  PyErr_SetString(PyExc_TypeError, "value must be a BBox");
153  return -1;
154  }
155  self->vm->setScene3dBBox(*(((BPy_BBox *)value)->bb));
156  return 0;
157 }
158 
159 static PyGetSetDef BPy_ViewMap_getseters[] = {
160  {"scene_bbox",
161  (getter)ViewMap_scene_bbox_get,
162  (setter)ViewMap_scene_bbox_set,
163  ViewMap_scene_bbox_doc,
164  nullptr},
165  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
166 };
167 
168 /*-----------------------BPy_ViewMap type definition ------------------------------*/
169 
170 PyTypeObject ViewMap_Type = {
171  PyVarObject_HEAD_INIT(nullptr, 0) "ViewMap", /* tp_name */
172  sizeof(BPy_ViewMap), /* tp_basicsize */
173  0, /* tp_itemsize */
174  (destructor)ViewMap_dealloc, /* tp_dealloc */
175  0, /* tp_vectorcall_offset */
176  nullptr, /* tp_getattr */
177  nullptr, /* tp_setattr */
178  nullptr, /* tp_reserved */
179  (reprfunc)ViewMap_repr, /* tp_repr */
180  nullptr, /* tp_as_number */
181  nullptr, /* tp_as_sequence */
182  nullptr, /* tp_as_mapping */
183  nullptr, /* tp_hash */
184  nullptr, /* tp_call */
185  nullptr, /* tp_str */
186  nullptr, /* tp_getattro */
187  nullptr, /* tp_setattro */
188  nullptr, /* tp_as_buffer */
189  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
190  ViewMap_doc, /* tp_doc */
191  nullptr, /* tp_traverse */
192  nullptr, /* tp_clear */
193  nullptr, /* tp_richcompare */
194  0, /* tp_weaklistoffset */
195  nullptr, /* tp_iter */
196  nullptr, /* tp_iternext */
197  BPy_ViewMap_methods, /* tp_methods */
198  nullptr, /* tp_members */
199  BPy_ViewMap_getseters, /* tp_getset */
200  nullptr, /* tp_base */
201  nullptr, /* tp_dict */
202  nullptr, /* tp_descr_get */
203  nullptr, /* tp_descr_set */
204  0, /* tp_dictoffset */
205  (initproc)ViewMap_init, /* tp_init */
206  nullptr, /* tp_alloc */
207  PyType_GenericNew, /* tp_new */
208 };
209 
211 
212 #ifdef __cplusplus
213 }
214 #endif
#define UNUSED(x)
#define BPy_BBox_Check(v)
Definition: BPy_BBox.h:24
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
PyObject * BPy_BBox_from_BBox(const BBox< Vec3r > &bb)
int ViewMap_Init(PyObject *module)
Definition: BPy_ViewMap.cpp:23
static int ViewMap_scene_bbox_set(BPy_ViewMap *self, PyObject *value, void *UNUSED(closure))
PyDoc_STRVAR(ViewMap_doc, "Class defining the ViewMap.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.")
static PyObject * ViewMap_get_closest_fedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
static PyMethodDef BPy_ViewMap_methods[]
static int ViewMap_init(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
Definition: BPy_ViewMap.cpp:47
static void ViewMap_dealloc(BPy_ViewMap *self)
Definition: BPy_ViewMap.cpp:58
static PyGetSetDef BPy_ViewMap_getseters[]
static PyObject * ViewMap_scene_bbox_get(BPy_ViewMap *self, void *UNUSED(closure))
static PyObject * ViewMap_get_closest_viewedge(BPy_ViewMap *self, PyObject *args, PyObject *kwds)
Definition: BPy_ViewMap.cpp:81
PyTypeObject ViewMap_Type
static PyObject * ViewMap_repr(BPy_ViewMap *self)
Definition: BPy_ViewMap.cpp:64
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
static struct PyModuleDef module
Definition: python.cpp:972