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