1 %{
2 static void
convert_SbVec4f_array(PyObject * input,float temp[4])3 convert_SbVec4f_array(PyObject * input, float temp[4])
4 {
5   if (PySequence_Check(input) && (PySequence_Size(input) == 4) &&
6       PyNumber_Check(PySequence_GetItem(input, 0)) &&
7       PyNumber_Check(PySequence_GetItem(input, 1)) &&
8       PyNumber_Check(PySequence_GetItem(input, 2)) &&
9       PyNumber_Check(PySequence_GetItem(input, 3))) {
10     temp[0] = PyFloat_AsDouble(PySequence_GetItem(input, 0));
11     temp[1] = PyFloat_AsDouble(PySequence_GetItem(input, 1));
12     temp[2] = PyFloat_AsDouble(PySequence_GetItem(input, 2));
13     temp[3] = PyFloat_AsDouble(PySequence_GetItem(input, 3));
14   } else {
15     PyErr_SetString(PyExc_TypeError, "expected a sequence with 4 floats");
16     PyErr_Print();
17   }
18 }
19 %}
20 
21 %typemap(in) float v[4] (float temp[4]) {
22   convert_SbVec4f_array($input, temp);
23   $1 = temp;
24 }
25 
26 %typemap(typecheck) float v[4] {
27   $1 = PySequence_Check($input) ? 1 : 0;
28 }
29 
30 %ignore SbVec2d::__imul__;
31 
32 /* for some strange reason the %apply directive below doesn't work
33  * for this class on getValue(f,f,f,f)...
34  * created this typemap for getValue(void) instead as a workaround.
35  */
36 %typemap(out) float * {
37   $result = Py_BuildValue("(ffff)",
38                           (double)(*($1)),
39                           (double)(*($1+1)),
40                           (double)(*($1+2)),
41                           (double)(*($1+3)));
42 }
43 
44 /* add operator overloading methods instead of the global functions */
45 %extend SbVec4f {
__add__(const SbVec4f & u)46   SbVec4f __add__(const SbVec4f &u) { return *self + u; }
__sub__(const SbVec4f & u)47   SbVec4f __sub__(const SbVec4f &u) { return *self - u; }
__mul__(const float d)48   SbVec4f __mul__(const float d) { return *self * d; }
__mul__(const SbMatrix & m)49   SbVec4f __mul__(const SbMatrix &m) { SbVec4f res; m.multVecMatrix(*self,res); return res; }
__rmul__(const float d)50   SbVec4f __rmul__(const float d) { return *self * d; }
__div__(const float d)51   SbVec4f __div__(const float d) { return *self / d; }
__truediv__(const float d)52   SbVec4f __truediv__(const float d) { return *self / d; }
__eq__(const SbVec4f & u)53   int __eq__(const SbVec4f &u) { return *self == u; }
__nq__(const SbVec4f & u)54   int __nq__(const SbVec4f &u) { return *self != u; }
55   // swig - add a method for wrapping c++ operator[] access
__getitem__(int i)56   float __getitem__(int i) { return (self->getValue())[i]; }
__setitem__(int i,float value)57   void  __setitem__(int i, float value) { (*self)[i] = value; }
58 
59 %pythoncode %{
60    def __iter__(self):
61       for i in range(4):
62          yield self[i]
63 
64    def __len__(self):
65          return 4
66 %}
67 }
68 
69 %apply float *OUTPUT { float& x, float& y, float& z, float& w };
70 
71 %ignore SbVec4f::getValue(float& x, float& y, float& z, float& w) const;
72