Fixes saving b&w models
This commit is contained in:
@@ -116,6 +116,10 @@ bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
||||
YAML::Node cat_attrs;
|
||||
cat_attrs["filename"] = modelFile.first;
|
||||
|
||||
if (modelFile.second >= categories.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string cat_name = categories[modelFile.second].name;
|
||||
node[modelFile.second][cat_name].push_back(cat_attrs);
|
||||
}
|
||||
|
||||
@@ -286,19 +286,21 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
}
|
||||
}
|
||||
|
||||
node["inputNames"] =
|
||||
convert_array<char[INPUT_NAME_LEN + 1], CPN_MAX_INPUTS>::encode(
|
||||
rhs.inputNames);
|
||||
|
||||
std::set<int> inputs;
|
||||
for (int i = 0; i < CPN_MAX_EXPOS; i++) {
|
||||
const ExpoData& expo = rhs.expoData[i];
|
||||
if (!expo.isEmpty()) {
|
||||
Node expoNode;
|
||||
expoNode = expo;
|
||||
node["expoData"].push_back(expoNode);
|
||||
inputs.insert(expo.chn);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto input : inputs) {
|
||||
node["inputNames"][std::to_string(input)]["val"] = rhs.inputNames[input];
|
||||
}
|
||||
|
||||
for (int i = 0; i < CPN_MAX_CURVES; i++) {
|
||||
const CurveData& curve = rhs.curves[i];
|
||||
if (!curve.isEmpty()) {
|
||||
@@ -308,7 +310,9 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
|
||||
YAML::Node points;
|
||||
YamlWriteCurvePoints(points, rhs.curves);
|
||||
node["points"] = points;
|
||||
if (points && (points.IsMap() || points.IsSequence())) {
|
||||
node["points"] = points;
|
||||
}
|
||||
|
||||
// logicalSw[]
|
||||
// customFn[]
|
||||
@@ -384,7 +388,6 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
||||
node["inputNames"] >> rhs.inputNames;
|
||||
node["expoData"] >> rhs.expoData;
|
||||
|
||||
// curves[]
|
||||
node["curves"] >> rhs.curves;
|
||||
YamlReadCurvePoints(node["points"], rhs.curves);
|
||||
|
||||
|
||||
@@ -294,25 +294,39 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasCategories = getCurrentFirmware()->getCapability(HasModelCategories);
|
||||
|
||||
EtxModelfiles modelFiles;
|
||||
for (const auto& model : radioData.models) {
|
||||
|
||||
// TODO: verify '.yml' (in case we moved from '.bin')
|
||||
QString modelFilename = QString("MODELS/%1").arg(model.filename);
|
||||
qDebug() << "Model index: " << model.modelIndex;
|
||||
if (model.isEmpty())
|
||||
continue;
|
||||
|
||||
// TODO: verify '.yml' (in case we moved from '.bin')
|
||||
|
||||
QString modelFilename;
|
||||
if (hasCategories) {
|
||||
modelFilename = QString("MODELS/%1").arg(model.filename);
|
||||
modelFiles.push_back({ std::string(model.filename), model.category });
|
||||
} else {
|
||||
modelFilename = QString("MODELS/model%1").arg(model.modelIndex, 2, QLatin1Char('0'));
|
||||
}
|
||||
|
||||
QByteArray modelData;
|
||||
writeModelToYaml(model, modelData);
|
||||
if (!writeFile(modelData, modelFilename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
modelFiles.push_back({ std::string(model.filename), model.category });
|
||||
}
|
||||
|
||||
// TODO: sort 'modelFiles' by category index
|
||||
QByteArray modelslistBuffer;
|
||||
if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer)
|
||||
|| !writeFile(modelslistBuffer, "MODELS/models.yml")) {
|
||||
return false;
|
||||
if (hasCategories) {
|
||||
// TODO: sort 'modelFiles' by category index
|
||||
QByteArray modelslistBuffer;
|
||||
if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer)
|
||||
|| !writeFile(modelslistBuffer, "MODELS/models.yml")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// force error to avoid overwriting the archive...
|
||||
|
||||
Reference in New Issue
Block a user