MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / saveMaterial

Method saveMaterial

src/Mod/Material/App/MaterialLibrary.cpp:282–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282std::shared_ptr<Material>
283MaterialLibraryLocal::saveMaterial(const std::shared_ptr<Material>& material,
284 const QString& path,
285 bool overwrite,
286 bool saveAsCopy,
287 bool saveInherited)
288{
289 QString filePath = getLocalPath(path);
290 QFile file(filePath);
291
292 QFileInfo info(file);
293 QDir fileDir(info.path());
294 if (!fileDir.exists()) {
295 if (!fileDir.mkpath(info.path())) {
296 Base::Console().error("Unable to create directory path '%s'\n",
297 info.path().toStdString().c_str());
298 }
299 }
300
301 if (info.exists()) {
302 if (!overwrite) {
303 Base::Console().error("File already exists '%s'\n", info.path().toStdString().c_str());
304 throw MaterialExists();
305 }
306 }
307
308 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
309 QTextStream stream(&file);
310#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
311 stream.setCodec("UTF-8");
312#endif
313 stream.setGenerateByteOrderMark(true);
314
315 // Write the contents
316 material->setName(info.fileName().remove(QStringLiteral(".FCMat"), Qt::CaseInsensitive));
317 material->setLibrary(getptr());
318 material->setDirectory(getRelativePath(path));
319 material->save(stream, overwrite, saveAsCopy, saveInherited);
320 }
321
322 return addMaterial(material, path);
323}
324
325bool MaterialLibraryLocal::fileExists(const QString& path) const
326{

Callers 2

saveMethod · 0.45
TEST_FFunction · 0.45

Calls 13

MaterialExistsClass · 0.85
pathMethod · 0.80
toStdStringMethod · 0.80
getptrFunction · 0.70
existsMethod · 0.45
errorMethod · 0.45
c_strMethod · 0.45
openMethod · 0.45
setNameMethod · 0.45
removeMethod · 0.45
fileNameMethod · 0.45
setDirectoryMethod · 0.45

Tested by 1

TEST_FFunction · 0.36