Fixed metadata in models.yml
This commit is contained in:
@@ -65,7 +65,9 @@ bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
|||||||
for (const auto& model : models) {
|
for (const auto& model : models) {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
model["filename"] >> filename;
|
model["filename"] >> filename;
|
||||||
modelFiles.push_back({ filename, categories.size()-1 });
|
std::string name;
|
||||||
|
model["name"] >> name;
|
||||||
|
modelFiles.push_back({filename, name, (int)categories.size() - 1});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,14 +126,15 @@ bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
|||||||
for (const auto& modelFile: modelFiles) {
|
for (const auto& modelFile: modelFiles) {
|
||||||
|
|
||||||
YAML::Node cat_attrs;
|
YAML::Node cat_attrs;
|
||||||
cat_attrs["filename"] = modelFile.first;
|
cat_attrs["filename"] = modelFile.filename;
|
||||||
|
cat_attrs["name"] = modelFile.name;
|
||||||
|
|
||||||
if (modelFile.second >= (int)categories.size()) {
|
if (modelFile.category >= (int)categories.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string cat_name = categories[modelFile.second].name;
|
const std::string cat_name = categories[modelFile.category].name;
|
||||||
node[modelFile.second][cat_name].push_back(cat_attrs);
|
node[modelFile.category][cat_name].push_back(cat_attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeYamlToByteArray(node, data);
|
writeYamlToByteArray(node, data);
|
||||||
|
|||||||
@@ -29,8 +29,13 @@
|
|||||||
|
|
||||||
constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 };
|
constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 };
|
||||||
|
|
||||||
typedef std::pair<std::string, int> EtxModelfileCategoryPair;
|
struct EtxModelMetadata {
|
||||||
typedef std::list<EtxModelfileCategoryPair> EtxModelfiles;
|
std::string filename;
|
||||||
|
std::string name;
|
||||||
|
int category;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::list<EtxModelMetadata> EtxModelfiles;
|
||||||
|
|
||||||
bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
||||||
EtxModelfiles& modelFiles,
|
EtxModelfiles& modelFiles,
|
||||||
|
|||||||
@@ -258,10 +258,10 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
|||||||
|
|
||||||
int modelIdx = 0;
|
int modelIdx = 0;
|
||||||
for (const auto& mc : modelFiles) {
|
for (const auto& mc : modelFiles) {
|
||||||
qDebug() << "Filename: " << mc.first.c_str() << " / Category: " << mc.second;
|
qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category;
|
||||||
|
|
||||||
QByteArray modelBuffer;
|
QByteArray modelBuffer;
|
||||||
QString filename = "MODELS/" + QString::fromStdString(mc.first);
|
QString filename = "MODELS/" + QString::fromStdString(mc.filename);
|
||||||
if (!loadFile(modelBuffer, filename)) {
|
if (!loadFile(modelBuffer, filename)) {
|
||||||
setError(tr("Can't extract ") + filename);
|
setError(tr("Can't extract ") + filename);
|
||||||
return false;
|
return false;
|
||||||
@@ -277,9 +277,9 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
model.category = mc.second;
|
model.category = mc.category;
|
||||||
model.modelIndex = modelIdx;
|
model.modelIndex = modelIdx;
|
||||||
strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1);
|
strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1);
|
||||||
|
|
||||||
model.used = true;
|
model.used = true;
|
||||||
modelIdx++;
|
modelIdx++;
|
||||||
@@ -317,7 +317,8 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
|||||||
QString modelFilename;
|
QString modelFilename;
|
||||||
if (hasCategories) {
|
if (hasCategories) {
|
||||||
modelFilename = QString("MODELS/%1").arg(model.filename);
|
modelFilename = QString("MODELS/%1").arg(model.filename);
|
||||||
modelFiles.push_back({ std::string(model.filename), model.category });
|
modelFiles.push_back({std::string(model.filename),
|
||||||
|
std::string(model.name), model.category});
|
||||||
} else {
|
} else {
|
||||||
modelFilename = QString("MODELS/model%1.yml")
|
modelFilename = QString("MODELS/model%1.yml")
|
||||||
.arg(model.modelIndex, 2, 10, QLatin1Char('0'));
|
.arg(model.modelIndex, 2, 10, QLatin1Char('0'));
|
||||||
|
|||||||
Reference in New Issue
Block a user