| 240 | } |
| 241 | |
| 242 | PyObject* MaterialManagerPy::save(PyObject* args, PyObject* kwds) |
| 243 | { |
| 244 | char* libraryName {}; |
| 245 | PyObject* obj {}; |
| 246 | char* path {}; |
| 247 | PyObject* overwrite = Py_False; |
| 248 | PyObject* saveAsCopy = Py_False; |
| 249 | PyObject* saveInherited = Py_False; |
| 250 | static const std::array<const char *, 7> kwlist { "library", "material", "path", "overwrite", "saveAsCopy", "saveInherited", nullptr }; |
| 251 | if (!Base::Wrapped_ParseTupleAndKeywords(args, |
| 252 | kwds, |
| 253 | "etOet|O!O!O!", |
| 254 | kwlist, |
| 255 | "utf-8", &libraryName, |
| 256 | &obj, |
| 257 | "utf-8", &path, |
| 258 | &PyBool_Type, &overwrite, |
| 259 | &PyBool_Type, &saveAsCopy, |
| 260 | &PyBool_Type, &saveInherited)) { |
| 261 | return nullptr; |
| 262 | } |
| 263 | |
| 264 | Base::Console().log("library name %s\n", libraryName); |
| 265 | Base::Console().log("path %s\n", path); |
| 266 | |
| 267 | MaterialPy* material; |
| 268 | if (QLatin1String(obj->ob_type->tp_name) == QLatin1String("Materials.Material")) { |
| 269 | material = static_cast<MaterialPy*>(obj); |
| 270 | } |
| 271 | else { |
| 272 | PyErr_Format(PyExc_TypeError, "Material expected not '%s'", obj->ob_type->tp_name); |
| 273 | return nullptr; |
| 274 | } |
| 275 | if (!material) { |
| 276 | PyErr_SetString(PyExc_TypeError, "Invalid material object"); |
| 277 | return nullptr; |
| 278 | } |
| 279 | auto sharedMaterial = std::make_shared<Material>(*(material->getMaterialPtr())); |
| 280 | |
| 281 | std::shared_ptr<MaterialLibrary> library; |
| 282 | try { |
| 283 | library = getMaterialManagerPtr()->getLibrary(QString::fromUtf8(libraryName)); |
| 284 | } |
| 285 | catch (const LibraryNotFound&) { |
| 286 | PyErr_SetString(PyExc_LookupError, "Unknown library"); |
| 287 | return nullptr; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | getMaterialManagerPtr()->saveMaterial(library, |
| 292 | sharedMaterial, |
| 293 | QString::fromUtf8(path), |
| 294 | PyObject_IsTrue(overwrite), |
| 295 | PyObject_IsTrue(saveAsCopy), |
| 296 | PyObject_IsTrue(saveInherited)); |
| 297 | material->getMaterialPtr()->setUUID(sharedMaterial->getUUID()); // Make sure they match |
| 298 | |
| 299 | Py_INCREF(Py_None); |
nothing calls this directly
no test coverage detected