diff --git a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp index 9a2b1a7118a3cf27b99676597256912ef162d07f..9b313402a2ca0ca9f2739fe229a9db75b80a69a3 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp @@ -63,6 +63,15 @@ int XmlPrjInterface::readFile(const QString& fileName) return 0; } + auto read_single_mesh = [&](QString const& mesh_str) { + std::unique_ptr<MeshLib::Mesh> mesh{ + MeshLib::IO::readMeshFromFile(mesh_str.toStdString())}; + if (mesh != nullptr) + { + _project.addMesh(std::move(mesh)); + } + }; + QDomNodeList fileList = docElement.childNodes(); for (int i = 0; i < fileList.count(); i++) @@ -93,11 +102,41 @@ int XmlPrjInterface::readFile(const QString& fileName) } else if (node_name == "mesh") { - QString const mesh_str(path + file_name); - std::unique_ptr<MeshLib::Mesh> mesh( - MeshLib::IO::readMeshFromFile(mesh_str.toStdString())); - if (mesh) - _project.addMesh(std::move(mesh)); + read_single_mesh(path + file_name); + } + else if (node_name == "meshes") + { + for (QDomNode meshes_node = node.firstChild(); + meshes_node != QDomNode(); + meshes_node = meshes_node.nextSibling()) + { + if (!meshes_node.isElement()) + { + ERR("Expected an XML element node.") + return 0; + } + if (meshes_node.nodeName() != "mesh") + { + ERR("Expected an XML element node named 'mesh' got '%s'.", + meshes_node.nodeName().data()) + return 0; + } + if (meshes_node.childNodes().count() != 1) + { + ERR("Expected an XML element node named 'mesh' to contain " + "exactly one child node but it has %d children.", + meshes_node.childNodes().count()); + return 0; + } + QDomNode node_text = meshes_node.firstChild(); + if (!node_text.isText()) + { + ERR("Expected an XML element node named 'mesh' to contain " + "text.") + return 0; + } + read_single_mesh(path + node_text.toText().data().trimmed()); + } } else if (node_name == "parameters") diff --git a/Tests/FileIO_Qt/TestQtPrjInterface.cpp b/Tests/FileIO_Qt/TestQtPrjInterface.cpp index 08acbb4985e59717a8e96fabc7c827c1e0545da5..f9598467642a988f378efeea9c9014a69fb1f949 100644 --- a/Tests/FileIO_Qt/TestQtPrjInterface.cpp +++ b/Tests/FileIO_Qt/TestQtPrjInterface.cpp @@ -35,17 +35,16 @@ TEST(TestQtPrjInterface, QtXmlPrjReader) std::string name = BaseLib::BuildInfo::data_path + "/Elliptic/nonuniform_bc_Groundwaterflow/neumann_nonuniform.prj"; - test_files.push_back({name, 1, 1, 2, 0}); + test_files.push_back({name, 0, 3, 2, 0}); name = BaseLib::BuildInfo::data_path + "/Elliptic/nonuniform_bc_Groundwaterflow/neumann_nonuniform.prj"; - test_files.push_back({name, 1, 1, 2, 0}); + test_files.push_back({name, 0, 3, 2, 0}); for (std::size_t i = 0; i < test_files.size(); ++i) { DataHolderLib::Project project; FileIO::XmlPrjInterface xml(project); - int result = - xml.readFile(QString::fromStdString(test_files[i].file_name)); + int result = xml.readFile(test_files[i].file_name); EXPECT_EQ(1, result); std::vector<std::string> geo_names;