Library of Assembled Shared Sources
export_traits_prim.cpp
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43#include "python_common.h"
44#include "export_traits_prim.h"
46
47namespace lass
48{
49namespace python
50{
51namespace impl
52{
53
54/** @ingroup Python
55 * @internal
56 */
57PyObject* buildIndexVertex(size_t iVertex, size_t iNormal, size_t iUv)
58{
59 python::PyObjectPtr<PyObject>::Type tuple;
60
61 LASS_ASSERT(iVertex != prim::IndexTriangle::null());
62 if (iNormal == prim::IndexTriangle::null())
63 {
64 if (iUv == prim::IndexTriangle::null())
65 {
66 tuple = python::makeTuple(iVertex);
67 }
68 else
69 {
70 tuple = python::makeTuple(iVertex, python::fromNakedToSharedPtrCast<PyObject>(Py_None), iUv);
71 }
72 }
73 else
74 {
75 if (iUv == prim::IndexTriangle::null())
76 {
77 tuple = python::makeTuple(iVertex, iNormal);
78 }
79 else
80 {
81 tuple = python::makeTuple(iVertex, iNormal, iUv);
82 }
83 }
85}
86
87/** @ingroup Python
88 * @internal
89 */
90int getIndexVertex(PyObject* iIndices, size_t& oVertex, size_t& oNormal, size_t& oUv)
91{
92 size_t vertex = prim::IndexTriangle::null();
93 size_t normal = prim::IndexTriangle::null();
94 size_t uv = prim::IndexTriangle::null();
95
96 TPyObjPtr tuple(PySequence_Fast(iIndices, "expected a sequence (tuple, list, ...)"));
97 if (!tuple)
98 {
99 return 1;
100 }
101 const Py_ssize_t size = PySequence_Fast_GET_SIZE(tuple.get());
102 if (size == -1)
103 {
104 return 1;
105 }
106 if (size == 0 || size > 3)
107 {
108 PyErr_SetString(PyExc_TypeError, "is not (v [, vn [, vt]])");
109 return 1;
110 }
111 PyObject** objects = PySequence_Fast_ITEMS(tuple.get());
112 if (pyGetSimpleObject(objects[0], vertex) != 0)
113 {
115 return 1;
116 }
117 if (size > 1 && objects[1] != Py_None)
118 {
119 if (pyGetSimpleObject(objects[1], normal) != 0)
120 {
122 return 1;
123 }
124 }
125 if (size > 2 && objects[2] != Py_None)
126 {
127 if (pyGetSimpleObject(objects[2], uv) != 0)
128 {
130 return 1;
131 }
132 }
133 oVertex = vertex;
134 oNormal = normal;
135 oUv = uv;
136 return 0;
137}
138
139
140}
141}
142}
143
144// EOF
void addMessageHeader(const char *header)
Prepend a message to the current Python exception value.
PyObjectPtr< PyObject >::Type TPyObjPtr
PyObjectPtr to a PyObject.
PyObject * fromSharedPtrToNakedCast(const util::SharedPtr< T, PyObjectStorage, PyObjectCounter > &object)
fromSharedPtrToNakedCast.
lass::util::SharedPtr< T, PyObjectStorage, PyObjectCounter > fromNakedToSharedPtrCast(PyObject *object)
fromNakedToSharedPtrCast.
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.
Definition config.h:53