OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp |
| 29 * \ingroup freestyle |
| 30 */ |
| 31 |
| 32 #include "BPy_ViewEdge.h" |
| 33 |
| 34 #include "../BPy_Convert.h" |
| 35 #include "../BPy_Id.h" |
| 36 #include "../Interface0D/BPy_ViewVertex.h" |
| 37 #include "../Interface1D/BPy_FEdge.h" |
| 38 #include "../Interface1D/BPy_ViewEdge.h" |
| 39 #include "../BPy_Nature.h" |
| 40 #include "../BPy_ViewShape.h" |
| 41 |
| 42 #ifdef __cplusplus |
| 43 extern "C" { |
| 44 #endif |
| 45 |
| 46 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 47 |
| 48 /*----------------------ViewEdge methods ----------------------------*/ |
| 49 |
| 50 PyDoc_STRVAR(ViewEdge_doc, |
| 51 "Class hierarchy: :class:`Interface1D` > :class:`ViewEdge`\n" |
| 52 "\n" |
| 53 "Class defining a ViewEdge. A ViewEdge in an edge of the image graph.\n" |
| 54 "it connnects two :class:`ViewVertex` objects. It is made by connecting\n" |
| 55 "a set of FEdges.\n" |
| 56 "\n" |
| 57 ".. method:: __init__()\n" |
| 58 "\n" |
| 59 " Default constructor.\n" |
| 60 "\n" |
| 61 ".. method:: __init__(brother)\n" |
| 62 "\n" |
| 63 " Copy constructor.\n" |
| 64 "\n" |
| 65 " :arg brother: A ViewEdge object.\n" |
| 66 " :type brother: :class:`ViewEdge`"); |
| 67 |
| 68 static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds) |
| 69 { |
| 70 static const char *kwlist[] = {"brother", NULL}; |
| 71 PyObject *brother = 0; |
| 72 |
| 73 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &Vi
ewEdge_Type, &brother)) |
| 74 return -1; |
| 75 if (!brother) |
| 76 self->ve = new ViewEdge(); |
| 77 else |
| 78 self->ve = new ViewEdge(*(((BPy_ViewEdge *)brother)->ve)); |
| 79 self->py_if1D.if1D = self->ve; |
| 80 self->py_if1D.borrowed = 0; |
| 81 return 0; |
| 82 } |
| 83 |
| 84 PyDoc_STRVAR(ViewEdge_update_fedges_doc, |
| 85 ".. method:: update_fedges()\n" |
| 86 "\n" |
| 87 " Sets Viewedge to this for all embedded fedges.\n"); |
| 88 |
| 89 static PyObject * ViewEdge_update_fedges(BPy_ViewEdge *self) |
| 90 { |
| 91 self->ve->UpdateFEdges(); |
| 92 Py_RETURN_NONE; |
| 93 } |
| 94 |
| 95 static PyMethodDef BPy_ViewEdge_methods[] = { |
| 96 {"update_fedges", (PyCFunction)ViewEdge_update_fedges, METH_NOARGS, View
Edge_update_fedges_doc}, |
| 97 {NULL, NULL, 0, NULL} |
| 98 }; |
| 99 |
| 100 /*----------------------ViewEdge get/setters ----------------------------*/ |
| 101 |
| 102 PyDoc_STRVAR(ViewEdge_first_viewvertex_doc, |
| 103 "The first ViewVertex.\n" |
| 104 "\n" |
| 105 ":type: :class:`ViewVertex`"); |
| 106 |
| 107 static PyObject *ViewEdge_first_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(
closure)) |
| 108 { |
| 109 ViewVertex *v = self->ve->A(); |
| 110 if (v) |
| 111 return Any_BPy_ViewVertex_from_ViewVertex(*v); |
| 112 Py_RETURN_NONE; |
| 113 } |
| 114 |
| 115 static int ViewEdge_first_viewvertex_set(BPy_ViewEdge *self, PyObject *value, vo
id *UNUSED(closure)) |
| 116 { |
| 117 if(!BPy_ViewVertex_Check(value)) |
| 118 return -1; |
| 119 self->ve->setA(((BPy_ViewVertex *)value)->vv); |
| 120 return 0; |
| 121 } |
| 122 |
| 123 PyDoc_STRVAR(ViewEdge_last_viewvertex_doc, |
| 124 "The second ViewVertex.\n" |
| 125 "\n" |
| 126 ":type: :class:`ViewVertex`"); |
| 127 |
| 128 static PyObject *ViewEdge_last_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(c
losure)) |
| 129 { |
| 130 ViewVertex *v = self->ve->B(); |
| 131 if (v) |
| 132 return Any_BPy_ViewVertex_from_ViewVertex(*v); |
| 133 Py_RETURN_NONE; |
| 134 } |
| 135 |
| 136 static int ViewEdge_last_viewvertex_set(BPy_ViewEdge *self, PyObject *value, voi
d *UNUSED(closure)) |
| 137 { |
| 138 if(!BPy_ViewVertex_Check(value)) |
| 139 return -1; |
| 140 self->ve->setB(((BPy_ViewVertex *)value)->vv); |
| 141 return 0; |
| 142 } |
| 143 |
| 144 PyDoc_STRVAR(ViewEdge_first_fedge_doc, |
| 145 "The first FEdge that constitutes this ViewEdge.\n" |
| 146 "\n" |
| 147 ":type: :class:`FEdge`"); |
| 148 |
| 149 static PyObject *ViewEdge_first_fedge_get(BPy_ViewEdge *self, void *UNUSED(closu
re)) |
| 150 { |
| 151 FEdge *fe = self->ve->fedgeA(); |
| 152 if (fe) |
| 153 return Any_BPy_FEdge_from_FEdge(*fe); |
| 154 Py_RETURN_NONE; |
| 155 } |
| 156 |
| 157 static int ViewEdge_first_fedge_set(BPy_ViewEdge *self, PyObject *value, void *U
NUSED(closure)) |
| 158 { |
| 159 if(!BPy_FEdge_Check(value)) |
| 160 return -1; |
| 161 self->ve->setFEdgeA(((BPy_FEdge *)value)->fe); |
| 162 return 0; |
| 163 } |
| 164 |
| 165 PyDoc_STRVAR(ViewEdge_last_fedge_doc, |
| 166 "The last FEdge that constitutes this ViewEdge.\n" |
| 167 "\n" |
| 168 ":type: :class:`FEdge`"); |
| 169 |
| 170 static PyObject *ViewEdge_last_fedge_get(BPy_ViewEdge *self, void *UNUSED(closur
e)) |
| 171 { |
| 172 FEdge *fe = self->ve->fedgeB(); |
| 173 if (fe) |
| 174 return Any_BPy_FEdge_from_FEdge(*fe); |
| 175 Py_RETURN_NONE; |
| 176 } |
| 177 |
| 178 static int ViewEdge_last_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UN
USED(closure)) |
| 179 { |
| 180 if(!BPy_FEdge_Check(value)) |
| 181 return -1; |
| 182 self->ve->setFEdgeB(((BPy_FEdge *)value)->fe); |
| 183 return 0; |
| 184 } |
| 185 |
| 186 PyDoc_STRVAR(ViewEdge_viewshape_doc, |
| 187 "The ViewShape to which this ViewEdge belongs to.\n" |
| 188 "\n" |
| 189 ":type: :class:`ViewShape`"); |
| 190 |
| 191 static PyObject *ViewEdge_viewshape_get(BPy_ViewEdge *self, void *UNUSED(closure
)) |
| 192 {······· |
| 193 ViewShape *vs = self->ve->viewShape(); |
| 194 if (vs) |
| 195 return BPy_ViewShape_from_ViewShape(*vs); |
| 196 Py_RETURN_NONE; |
| 197 } |
| 198 |
| 199 static int ViewEdge_viewshape_set(BPy_ViewEdge *self, PyObject *value, void *UNU
SED(closure)) |
| 200 { |
| 201 if (!BPy_ViewShape_Check(value)) |
| 202 return -1; |
| 203 self->ve->setShape(((BPy_ViewShape *)value)->vs); |
| 204 return 0; |
| 205 } |
| 206 |
| 207 PyDoc_STRVAR(ViewEdge_occludee_doc, |
| 208 "The shape that is occluded by the ViewShape to which this ViewEdge\n" |
| 209 "belongs to. If no object is occluded, this property is set to None.\n" |
| 210 "\n" |
| 211 ":type: :class:`ViewShape`"); |
| 212 |
| 213 static PyObject *ViewEdge_occludee_get(BPy_ViewEdge *self, void *UNUSED(closure)
) |
| 214 { |
| 215 ViewShape *vs = self->ve->aShape(); |
| 216 if (vs) |
| 217 return BPy_ViewShape_from_ViewShape(*vs); |
| 218 Py_RETURN_NONE; |
| 219 } |
| 220 |
| 221 static int ViewEdge_occludee_set(BPy_ViewEdge *self, PyObject *value, void *UNUS
ED(closure)) |
| 222 { |
| 223 if(!BPy_ViewShape_Check(value)) |
| 224 return -1; |
| 225 self->ve->setaShape(((BPy_ViewShape *)value)->vs); |
| 226 return 0; |
| 227 } |
| 228 |
| 229 PyDoc_STRVAR(ViewEdge_is_closed_doc, |
| 230 "True if this ViewEdge forms a closed loop.\n" |
| 231 "\n" |
| 232 ":type: bool"); |
| 233 |
| 234 static PyObject *ViewEdge_is_closed_get(BPy_ViewEdge *self, void *UNUSED(closure
)) |
| 235 { |
| 236 return PyBool_from_bool(self->ve->isClosed()); |
| 237 } |
| 238 |
| 239 PyDoc_STRVAR(ViewEdge_id_doc, |
| 240 "The Id of this ViewEdge.\n" |
| 241 "\n" |
| 242 ":type: :class:`Id`"); |
| 243 |
| 244 static PyObject *ViewEdge_id_get(BPy_ViewEdge *self, void *UNUSED(closure)) |
| 245 { |
| 246 Id id(self->ve->getId()); |
| 247 return BPy_Id_from_Id(id); // return a copy |
| 248 } |
| 249 |
| 250 static int ViewEdge_id_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(clo
sure)) |
| 251 { |
| 252 if (!BPy_Id_Check(value)) { |
| 253 PyErr_SetString(PyExc_TypeError, "value must be an Id"); |
| 254 return -1; |
| 255 } |
| 256 self->ve->setId(*(((BPy_Id *)value)->id)); |
| 257 return 0; |
| 258 } |
| 259 |
| 260 PyDoc_STRVAR(ViewEdge_nature_doc, |
| 261 "The nature of this ViewEdge.\n" |
| 262 "\n" |
| 263 ":type: :class:`Nature`"); |
| 264 |
| 265 static PyObject *ViewEdge_nature_get(BPy_ViewEdge *self, void *UNUSED(closure)) |
| 266 { |
| 267 return BPy_Nature_from_Nature(self->ve->getNature()); |
| 268 } |
| 269 |
| 270 static int ViewEdge_nature_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED
(closure)) |
| 271 { |
| 272 if (!BPy_Nature_Check(value)) { |
| 273 PyErr_SetString(PyExc_TypeError, "value must be a Nature"); |
| 274 return -1; |
| 275 } |
| 276 self->ve->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)
); |
| 277 return 0; |
| 278 } |
| 279 |
| 280 PyDoc_STRVAR(ViewEdge_qi_doc, |
| 281 "The quantitative invisibility.\n" |
| 282 "\n" |
| 283 ":type: int"); |
| 284 |
| 285 static PyObject *ViewEdge_qi_get(BPy_ViewEdge *self, void *UNUSED(closure)) |
| 286 { |
| 287 return PyLong_FromLong(self->ve->qi()); |
| 288 } |
| 289 |
| 290 static int ViewEdge_qi_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(clo
sure)) |
| 291 { |
| 292 int qi; |
| 293 |
| 294 if((qi = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) |
| 295 return -1; |
| 296 self->ve->setQI(qi); |
| 297 return 0; |
| 298 } |
| 299 |
| 300 PyDoc_STRVAR(ViewEdge_chaining_time_stamp_doc, |
| 301 "The time stamp of this ViewEdge.\n" |
| 302 "\n" |
| 303 ":type: int"); |
| 304 |
| 305 static PyObject *ViewEdge_chaining_time_stamp_get(BPy_ViewEdge *self, void *UNUS
ED(closure)) |
| 306 { |
| 307 return PyLong_FromLong(self->ve->getChainingTimeStamp()); |
| 308 } |
| 309 |
| 310 static int ViewEdge_chaining_time_stamp_set(BPy_ViewEdge *self, PyObject *value,
void *UNUSED(closure)) |
| 311 { |
| 312 int timestamp; |
| 313 |
| 314 if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) |
| 315 return -1; |
| 316 self->ve->setChainingTimeStamp(timestamp); |
| 317 return 0; |
| 318 } |
| 319 |
| 320 static PyGetSetDef BPy_ViewEdge_getseters[] = { |
| 321 {(char *)"first_viewvertex", (getter)ViewEdge_first_viewvertex_get, (set
ter)ViewEdge_first_viewvertex_set, (char *)ViewEdge_first_viewvertex_doc, NULL}, |
| 322 {(char *)"last_viewvertex", (getter)ViewEdge_last_viewvertex_get, (sette
r)ViewEdge_last_viewvertex_set, (char *)ViewEdge_last_viewvertex_doc, NULL}, |
| 323 {(char *)"first_fedge", (getter)ViewEdge_first_fedge_get, (setter)ViewEd
ge_first_fedge_set, (char *)ViewEdge_first_fedge_doc, NULL}, |
| 324 {(char *)"last_fedge", (getter)ViewEdge_last_fedge_get, (setter)ViewEdge
_last_fedge_set, (char *)ViewEdge_last_fedge_doc, NULL}, |
| 325 {(char *)"viewshape", (getter)ViewEdge_viewshape_get, (setter)ViewEdge_v
iewshape_set, (char *)ViewEdge_viewshape_doc, NULL}, |
| 326 {(char *)"occludee", (getter)ViewEdge_occludee_get, (setter)ViewEdge_occ
ludee_set, (char *)ViewEdge_occludee_doc, NULL}, |
| 327 {(char *)"is_closed", (getter)ViewEdge_is_closed_get, (setter)NULL, (cha
r *)ViewEdge_is_closed_doc, NULL}, |
| 328 {(char *)"id", (getter)ViewEdge_id_get, (setter)ViewEdge_id_set, (char *
)ViewEdge_id_doc, NULL}, |
| 329 {(char *)"nature", (getter)ViewEdge_nature_get, (setter)ViewEdge_nature_
set, (char *)ViewEdge_nature_doc, NULL}, |
| 330 {(char *)"qi", (getter)ViewEdge_qi_get, (setter)ViewEdge_qi_set, (char *
)ViewEdge_qi_doc, NULL}, |
| 331 {(char *)"chaining_time_stamp", (getter)ViewEdge_chaining_time_stamp_get
, (setter)ViewEdge_chaining_time_stamp_set, (char *)ViewEdge_chaining_time_stamp
_doc, NULL}, |
| 332 {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ |
| 333 }; |
| 334 |
| 335 /*-----------------------BPy_ViewEdge type definition --------------------------
----*/ |
| 336 |
| 337 PyTypeObject ViewEdge_Type = { |
| 338 PyVarObject_HEAD_INIT(NULL, 0) |
| 339 "ViewEdge", /* tp_name */ |
| 340 sizeof(BPy_ViewEdge), /* tp_basicsize */ |
| 341 0, /* tp_itemsize */ |
| 342 0, /* tp_dealloc */ |
| 343 0, /* tp_print */ |
| 344 0, /* tp_getattr */ |
| 345 0, /* tp_setattr */ |
| 346 0, /* tp_reserved */ |
| 347 0, /* tp_repr */ |
| 348 0, /* tp_as_number */ |
| 349 0, /* tp_as_sequence */ |
| 350 0, /* tp_as_mapping */ |
| 351 0, /* tp_hash */ |
| 352 0, /* tp_call */ |
| 353 0, /* tp_str */ |
| 354 0, /* tp_getattro */ |
| 355 0, /* tp_setattro */ |
| 356 0, /* tp_as_buffer */ |
| 357 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 358 ViewEdge_doc, /* tp_doc */ |
| 359 0, /* tp_traverse */ |
| 360 0, /* tp_clear */ |
| 361 0, /* tp_richcompare */ |
| 362 0, /* tp_weaklistoffset */ |
| 363 0, /* tp_iter */ |
| 364 0, /* tp_iternext */ |
| 365 BPy_ViewEdge_methods, /* tp_methods */ |
| 366 0, /* tp_members */ |
| 367 BPy_ViewEdge_getseters, /* tp_getset */ |
| 368 &Interface1D_Type, /* tp_base */ |
| 369 0, /* tp_dict */ |
| 370 0, /* tp_descr_get */ |
| 371 0, /* tp_descr_set */ |
| 372 0, /* tp_dictoffset */ |
| 373 (initproc)ViewEdge_init, /* tp_init */ |
| 374 0, /* tp_alloc */ |
| 375 0, /* tp_new */ |
| 376 }; |
| 377 |
| 378 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 379 |
| 380 #ifdef __cplusplus |
| 381 } |
| 382 #endif |
OLD | NEW |