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