| 1035 | } |
| 1036 | |
| 1037 | std::shared_ptr<Material> |
| 1038 | MaterialConfigLoader::getMaterialFromPath(const std::shared_ptr<MaterialLibraryLocal>& library, |
| 1039 | const QString& path) |
| 1040 | { |
| 1041 | QString author = getAuthorAndLicense(path); // Place them both in the author field |
| 1042 | |
| 1043 | QMap<QString, QString> fcmat; |
| 1044 | if (!readFile(path, fcmat)) { |
| 1045 | Base::Console().log("Error reading '%s'\n", path.toStdString().c_str()); |
| 1046 | throw MaterialReadError(); |
| 1047 | } |
| 1048 | |
| 1049 | // General section |
| 1050 | // QString name = value(fcmat, "Name", ""); - always get the name from the filename |
| 1051 | QFileInfo filepath(path); |
| 1052 | QString name = |
| 1053 | filepath.fileName().remove(QStringLiteral(".FCMat"), Qt::CaseInsensitive); |
| 1054 | QString uuid = QUuid::createUuid().toString(QUuid::WithoutBraces); |
| 1055 | |
| 1056 | QString description = value(fcmat, "Description", ""); |
| 1057 | QString sourceReference = value(fcmat, "ReferenceSource", ""); |
| 1058 | QString sourceURL = value(fcmat, "SourceURL", ""); |
| 1059 | |
| 1060 | auto baseLibrary = std::static_pointer_cast<Materials::MaterialLibrary>(library); |
| 1061 | std::shared_ptr<Material> finalModel = |
| 1062 | std::make_shared<Material>(baseLibrary, path, uuid, name); |
| 1063 | finalModel->setOldFormat(true); |
| 1064 | |
| 1065 | finalModel->setAuthor(author); |
| 1066 | finalModel->setDescription(description); |
| 1067 | finalModel->setReference(sourceReference); |
| 1068 | finalModel->setURL(sourceURL); |
| 1069 | |
| 1070 | QString father = value(fcmat, "Father", ""); |
| 1071 | if (!father.isEmpty()) { |
| 1072 | finalModel->addPhysical(ModelUUIDs::ModelUUID_Legacy_Father); |
| 1073 | |
| 1074 | // Now add the data |
| 1075 | setPhysicalValue(finalModel, "Father", father); |
| 1076 | } |
| 1077 | |
| 1078 | QString kindOfMaterial = value(fcmat, "KindOfMaterial", ""); |
| 1079 | QString materialNumber = value(fcmat, "MaterialNumber", ""); |
| 1080 | QString norm = value(fcmat, "Norm", ""); |
| 1081 | QString standardCode = value(fcmat, "StandardCode", ""); |
| 1082 | if (kindOfMaterial.length() + materialNumber.length() + norm.length() + standardCode.length() |
| 1083 | > 0) { |
| 1084 | finalModel->addPhysical(ModelUUIDs::ModelUUID_Legacy_MaterialStandard); |
| 1085 | |
| 1086 | // Now add the data |
| 1087 | setPhysicalValue(finalModel, "KindOfMaterial", kindOfMaterial); |
| 1088 | setPhysicalValue(finalModel, "MaterialNumber", materialNumber); |
| 1089 | setPhysicalValue(finalModel, "StandardCode", norm); // Norm is the same as StandardCode |
| 1090 | setPhysicalValue(finalModel, "StandardCode", standardCode); |
| 1091 | } |
| 1092 | |
| 1093 | // Add the remaining sections |
| 1094 | addMechanical(fcmat, finalModel); |
nothing calls this directly
no test coverage detected