| 90 | } |
| 91 | |
| 92 | void PropertyVector::setPyObject(PyObject* value) |
| 93 | { |
| 94 | if (PyObject_TypeCheck(value, &(Base::VectorPy::Type))) { |
| 95 | Base::VectorPy* pcObject = static_cast<Base::VectorPy*>(value); |
| 96 | Base::Vector3d* val = pcObject->getVectorPtr(); |
| 97 | setValue(*val); |
| 98 | } |
| 99 | else if (PyTuple_Check(value) && PyTuple_Size(value) == 3) { |
| 100 | PyObject* item {}; |
| 101 | Base::Vector3d cVec; |
| 102 | // x |
| 103 | item = PyTuple_GetItem(value, 0); |
| 104 | if (PyFloat_Check(item)) { |
| 105 | cVec.x = PyFloat_AsDouble(item); |
| 106 | } |
| 107 | else if (PyLong_Check(item)) { |
| 108 | cVec.x = (double)PyLong_AsLong(item); |
| 109 | } |
| 110 | else { |
| 111 | throw Base::TypeError("Not allowed type used in tuple (float expected)..."); |
| 112 | } |
| 113 | // y |
| 114 | item = PyTuple_GetItem(value, 1); |
| 115 | if (PyFloat_Check(item)) { |
| 116 | cVec.y = PyFloat_AsDouble(item); |
| 117 | } |
| 118 | else if (PyLong_Check(item)) { |
| 119 | cVec.y = (double)PyLong_AsLong(item); |
| 120 | } |
| 121 | else { |
| 122 | throw Base::TypeError("Not allowed type used in tuple (float expected)..."); |
| 123 | } |
| 124 | // z |
| 125 | item = PyTuple_GetItem(value, 2); |
| 126 | if (PyFloat_Check(item)) { |
| 127 | cVec.z = PyFloat_AsDouble(item); |
| 128 | } |
| 129 | else if (PyLong_Check(item)) { |
| 130 | cVec.z = (double)PyLong_AsLong(item); |
| 131 | } |
| 132 | else { |
| 133 | throw Base::TypeError("Not allowed type used in tuple (float expected)..."); |
| 134 | } |
| 135 | setValue(cVec); |
| 136 | } |
| 137 | else { |
| 138 | std::string error = std::string("type must be 'Vector' or tuple of three floats, not "); |
| 139 | error += value->ob_type->tp_name; |
| 140 | throw Base::TypeError(error); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void PropertyVector::Save(Base::Writer& writer) const |
| 145 | { |
no test coverage detected