Material: Compatibility with older FCMat files

Provides compatibility loading older files outside the context of
a library.

Older material files were loaded by specifying a path. The new
material system used the path to associated the material with a
library, which may not be appropriate for legacy files. This change
allows the use of materials outside of a library.

Additionally, legacy files often have name/value pairs not part of the
standard list of properties. Since these were unable to be mapped to
a model property they were ignored. Materials now maintain a legacy
map to hold properties not associated with a property model. These
properties are considered transient and will not be saved. It is not
intended for this feature to be used as a generic container for
properties not mapped to an appropriate model.

Fixes #13302
This commit is contained in:
David Carter
2024-04-06 15:41:07 -04:00
committed by Yorik van Havre
parent 0056038ff4
commit f950a0c086
8 changed files with 135 additions and 0 deletions

View File

@@ -1017,6 +1017,22 @@ void MaterialConfigLoader::addMechanical(const QMap<QString, QString>& fcmat,
setPhysicalValue(finalModel, "Stiffness", stiffness);
}
void MaterialConfigLoader::addLegacy(const QMap<QString, QString>& fcmat,
const std::shared_ptr<Material>& finalModel)
{
for (auto const& legacy : fcmat.keys()) {
auto name = legacy;
int last = name.lastIndexOf(QLatin1String("/"));
if (last > 0) {
name = name.mid(last + 1);
}
if (!finalModel->hasNonLegacyProperty(name)) {
setLegacyValue(finalModel, name.toStdString(), fcmat[legacy]);
}
}
}
std::shared_ptr<Material>
MaterialConfigLoader::getMaterialFromPath(const std::shared_ptr<MaterialLibrary>& library,
const QString& path)
@@ -1081,6 +1097,7 @@ MaterialConfigLoader::getMaterialFromPath(const std::shared_ptr<MaterialLibrary>
addRendering(fcmat, finalModel);
addVectorRendering(fcmat, finalModel);
addRenderWB(fcmat, finalModel);
addLegacy(fcmat, finalModel);
return finalModel;
}