| 196 | } |
| 197 | |
| 198 | static PyObject* PySetItem( PyObject* self, PyObject* args ) |
| 199 | { |
| 200 | Tr2RuntimeInstanceData* pThis = BluePythonCast<Tr2RuntimeInstanceData*>( self ); |
| 201 | |
| 202 | unsigned index; |
| 203 | PyObject* item; |
| 204 | if( !PyArg_ParseTuple( args, "IO!", &index, &PyTuple_Type, &item ) ) |
| 205 | { |
| 206 | return nullptr; |
| 207 | } |
| 208 | |
| 209 | if( pThis->GetCount() <= index ) |
| 210 | { |
| 211 | PyErr_SetString( PyExc_IndexError, "Index out of range" ); |
| 212 | return nullptr; |
| 213 | } |
| 214 | |
| 215 | const Tr2VertexDefinition& def = pThis->GetLayout(); |
| 216 | if( def.m_items.empty() ) |
| 217 | { |
| 218 | PyErr_SetString( PyExc_RuntimeError, "Need to set valid element layout with SetElementLayout before calling SetData" ); |
| 219 | return nullptr; |
| 220 | } |
| 221 | |
| 222 | if( PyTuple_GET_SIZE( item ) != def.m_items.size() ) |
| 223 | { |
| 224 | pThis->DestroyData(); |
| 225 | PyErr_SetString( PyExc_TypeError, "Argument 2 needs to be a tuple and it needs to match element layout" ); |
| 226 | return nullptr; |
| 227 | } |
| 228 | |
| 229 | uint8_t* dataRaw = static_cast<uint8_t*>( pThis->GetData( pThis->GetCount() ) ); |
| 230 | if( !dataRaw ) |
| 231 | { |
| 232 | PyErr_SetString( PyExc_RuntimeError, "Could not lock data" ); |
| 233 | return nullptr; |
| 234 | } |
| 235 | float* data = static_cast<float*>( static_cast<void*>( dataRaw + pThis->GetStride() * index ) ); |
| 236 | |
| 237 | |
| 238 | for( size_t j = 0; j < def.m_items.size(); ++j ) |
| 239 | { |
| 240 | PyObject* element = PyTuple_GET_ITEM( item, j ); |
| 241 | unsigned size = def.GetDataTypeSizeInMembers( def.m_items[j].m_dataType ); |
| 242 | if( size == 1 ) |
| 243 | { |
| 244 | if( !PyFloat_Check( element ) ) |
| 245 | { |
| 246 | pThis->DestroyData(); |
| 247 | PyErr_SetString( PyExc_TypeError, "Argument 2 needs to be a tuple and it needs to match element layout" ); |
| 248 | return nullptr; |
| 249 | } |
| 250 | *data++ = float( PyFloat_AsDouble( element ) ); |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | if( !PyTuple_Check( element ) ) |
| 255 | { |
nothing calls this directly
no test coverage detected