diff --git a/FileIO/OpenGeoSysProject.xsd b/FileIO/OpenGeoSysProject.xsd index ef5a3cc2202662814223a97161e82323e18bf44d..d7316b71471f5ac55885e2509a3ffa3e336a9d2f 100644 --- a/FileIO/OpenGeoSysProject.xsd +++ b/FileIO/OpenGeoSysProject.xsd @@ -40,9 +40,7 @@ <xs:sequence> <xs:element name="geo" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="msh" type="mshElement" minOccurs="0" maxOccurs="unbounded" /> - <xs:element name="bc" type="geoElement" minOccurs="0" maxOccurs="unbounded" /> - <xs:element name="ic" type="geoElement" minOccurs="0" maxOccurs="unbounded" /> - <xs:element name="st" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> + <xs:element name="cnd" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="mfp" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="mmp" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> <xs:element name="msp" type="projectElement" minOccurs="0" maxOccurs="unbounded" /> diff --git a/FileIO/XmlIO/Qt/XMLQtInterface.cpp b/FileIO/XmlIO/Qt/XMLQtInterface.cpp index f45588cfd84a9ed7288225811fbd4f6269ee1fc1..4ead65dc16c97ee514e1d7418f414b8be264bf52 100644 --- a/FileIO/XmlIO/Qt/XMLQtInterface.cpp +++ b/FileIO/XmlIO/Qt/XMLQtInterface.cpp @@ -38,7 +38,7 @@ int XMLQtInterface::readFile(const QString &fileName) QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - ERR("XMLQtInterface::readFile(): Can't open xml-file %s.", fileName.data()); + ERR("XMLQtInterface::readFile(): Can't open xml-file %s.", fileName.toStdString().c_str()); return 0; } _fileData = file.readAll(); diff --git a/FileIO/XmlIO/Qt/XmlCndInterface.cpp b/FileIO/XmlIO/Qt/XmlCndInterface.cpp index 685e74e2d7caa56eec561ebee04e7ee94ce793c1..190a119c780d4f9095bab256575ccda139d1a453 100644 --- a/FileIO/XmlIO/Qt/XmlCndInterface.cpp +++ b/FileIO/XmlIO/Qt/XmlCndInterface.cpp @@ -26,7 +26,7 @@ namespace FileIO { -XmlCndInterface::XmlCndInterface(ProjectData* project) +XmlCndInterface::XmlCndInterface(ProjectData &project) : XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysCND.xsd")), _type(FEMCondition::UNSPECIFIED), _project(project) { @@ -46,7 +46,7 @@ int XmlCndInterface::readFile(const QString &fileName) return 0; } - std::size_t const n_cond_before(this->_project->getConditions().size()); + std::size_t const n_cond_before(this->_project.getConditions().size()); QDomNodeList lists = docElement.childNodes(); for (int i = 0; i < lists.count(); i++) { @@ -58,7 +58,7 @@ int XmlCndInterface::readFile(const QString &fileName) else if (list_node.nodeName().compare("SourceTerms") == 0) readConditions(list_node, FEMCondition::SOURCE_TERM); } - std::size_t const n_cond_after(this->_project->getConditions().size()); + std::size_t const n_cond_after(this->_project.getConditions().size()); if (n_cond_after-n_cond_before > 0) return 1; //do something like _geoObjects->addStationVec(stations, stnName, color); else @@ -77,8 +77,8 @@ void XmlCndInterface::readConditions(const QDomNode &listRoot, while (!cond.isNull()) { std::string geometry_name ( cond.attribute("geometry").toStdString() ); - if (this->_project->getGEOObjects()->exists(geometry_name) >= 0 || - this->_project->meshExists(geometry_name)) + if (this->_project.getGEOObjects()->exists(geometry_name) >= 0 || + this->_project.meshExists(geometry_name)) { FEMCondition* c ( new FEMCondition(geometry_name, type) ); @@ -111,7 +111,7 @@ void XmlCndInterface::readConditions(const QDomNode &listRoot, else if (prop_name.compare("Name") == 0) geo_obj_name = geoProps.at(j).toElement().text().toStdString(); } - c->initGeometricAttributes(geometry_name, geo_type, geo_obj_name, *(_project->getGEOObjects())); + c->initGeometricAttributes(geometry_name, geo_type, geo_obj_name, *(_project.getGEOObjects())); } else if (prop_node.nodeName().compare("Distribution") == 0) { @@ -156,7 +156,7 @@ void XmlCndInterface::readConditions(const QDomNode &listRoot, } } } - this->_project->addCondition(c); + this->_project.addCondition(c); } else { @@ -177,7 +177,7 @@ bool XmlCndInterface::write() root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); root.setAttribute( "xsi:noNamespaceSchemaLocation", "http://www.opengeosys.org/images/xsd/OpenGeoSysCND.xsd" ); - std::vector<FEMCondition*> const& conditions (_project->getConditions( + std::vector<FEMCondition*> const& conditions (_project.getConditions( FiniteElement::INVALID_PROCESS, _exportName, _type) ); diff --git a/FileIO/XmlIO/Qt/XmlCndInterface.h b/FileIO/XmlIO/Qt/XmlCndInterface.h index 9871f308b8f57d486b795ce4cee8696a02d89278..de945f1c48279baa6eb68276b0459118a2a24343 100644 --- a/FileIO/XmlIO/Qt/XmlCndInterface.h +++ b/FileIO/XmlIO/Qt/XmlCndInterface.h @@ -37,7 +37,7 @@ public: * Constructor * \param project Project data. */ - XmlCndInterface(ProjectData* project); + XmlCndInterface(ProjectData &project); ~XmlCndInterface() {} @@ -67,7 +67,7 @@ private: FEMCondition::CondType _type; - ProjectData* _project; + ProjectData& _project; }; } diff --git a/FileIO/XmlIO/Qt/XmlGspInterface.cpp b/FileIO/XmlIO/Qt/XmlGspInterface.cpp index d4624cecfa0114a4c02cd2a17ab5dabd0f851416..f9acea1e89f482e31dd3b13ce0232494c6eb1bcc 100644 --- a/FileIO/XmlIO/Qt/XmlGspInterface.cpp +++ b/FileIO/XmlIO/Qt/XmlGspInterface.cpp @@ -21,6 +21,7 @@ #include "XmlGmlInterface.h" #include "XmlStnInterface.h" +#include "FileTools.h" #include "FileFinder.h" #include "FileIO/Legacy/MeshIO.h" #include "FileIO/readMeshFromFile.h" @@ -32,7 +33,7 @@ namespace FileIO { -XmlGspInterface::XmlGspInterface(ProjectData* project) : +XmlGspInterface::XmlGspInterface(ProjectData& project) : XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysProject.xsd")), _project(project) { @@ -62,7 +63,7 @@ int XmlGspInterface::readFile(const QString &fileName) const QString file_node(fileList.at(i).nodeName()); if (file_node.compare("geo") == 0) { - XmlGmlInterface gml(*(_project->getGEOObjects())); + XmlGmlInterface gml(*(_project.getGEOObjects())); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) { @@ -79,7 +80,7 @@ int XmlGspInterface::readFile(const QString &fileName) } else if (file_node.compare("stn") == 0) { - XmlStnInterface stn(*(_project->getGEOObjects())); + XmlStnInterface stn(*(_project.getGEOObjects())); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) if (childList.at(j).nodeName().compare("file") == 0) @@ -92,7 +93,14 @@ int XmlGspInterface::readFile(const QString &fileName) fileList.at(i).toElement().text().toStdString(); MeshLib::Mesh* msh = FileIO::readMeshFromFile(msh_name); if (msh) - _project->addMesh(msh); + _project.addMesh(msh); + } + else if (file_node.compare("cnd") == 0) + { + const std::string cnd_name = path.toStdString() + + fileList.at(i).toElement().text().toStdString(); + XmlCndInterface cnd(_project); + cnd.readFile(cnd_name); } } @@ -107,7 +115,7 @@ int XmlGspInterface::writeToFile(std::string filename) bool XmlGspInterface::write() { - GeoLib::GEOObjects* geoObjects = _project->getGEOObjects(); + GeoLib::GEOObjects* geoObjects = _project.getGEOObjects(); QFileInfo fi(QString::fromStdString(_filename)); std::string path((fi.absolutePath()).toStdString() + "/"); @@ -123,11 +131,10 @@ bool XmlGspInterface::write() doc.appendChild(root); - // GLI + // GML std::vector<std::string> geoNames; geoObjects->getGeometryNames(geoNames); - for (std::vector<std::string>::const_iterator it(geoNames.begin()); it != geoNames.end(); - ++it) + for (std::vector<std::string>::const_iterator it(geoNames.begin()); it != geoNames.end(); ++it) { // write GLI file XmlGmlInterface gml(*geoObjects); @@ -147,9 +154,8 @@ bool XmlGspInterface::write() } // MSH - const std::vector<MeshLib::Mesh*> msh_vec = _project->getMeshObjects(); - for (std::vector<MeshLib::Mesh*>::const_iterator it(msh_vec.begin()); it != msh_vec.end(); - ++it) + const std::vector<MeshLib::Mesh*> msh_vec = _project.getMeshObjects(); + for (std::vector<MeshLib::Mesh*>::const_iterator it(msh_vec.begin()); it != msh_vec.end(); ++it) { // write mesh file Legacy::MeshIO meshIO; @@ -169,8 +175,7 @@ bool XmlGspInterface::write() // STN std::vector<std::string> stnNames; geoObjects->getStationVectorNames(stnNames); - for (std::vector<std::string>::const_iterator it(stnNames.begin()); it != stnNames.end(); - ++it) + for (std::vector<std::string>::const_iterator it(stnNames.begin()); it != stnNames.end(); ++it) { // write STN file XmlStnInterface stn(*geoObjects); @@ -189,7 +194,27 @@ bool XmlGspInterface::write() fileNameTag.appendChild(fileNameText); } else - ERR("XmlGspInterface::writeFile(): Error writing file \"%s\".", name.c_str()); + ERR("XmlGspInterface::writeFile(): Error writing stn-file \"%s\".", name.c_str()); + } + + // CND + const std::vector<FEMCondition*> &cnd_vec (_project.getConditions()); + if (!cnd_vec.empty()) + { + XmlCndInterface cnd(_project); + const std::string cnd_name (BaseLib::extractBaseNameWithoutExtension(_filename) + ".cnd"); + if (cnd.writeToFile(path + cnd_name)) + { + // write entry in project file + QDomElement cndTag = doc.createElement("cnd"); + root.appendChild(cndTag); + QDomElement fileNameTag = doc.createElement("file"); + cndTag.appendChild(fileNameTag); + QDomText fileNameText = doc.createTextNode(QString::fromStdString(cnd_name)); + fileNameTag.appendChild(fileNameText); + } + else + ERR("XmlGspInterface::writeFile(): Error writing cnd-file \"%s\".", cnd_name.c_str()); } std::string xml = doc.toString().toStdString(); diff --git a/FileIO/XmlIO/Qt/XmlGspInterface.h b/FileIO/XmlIO/Qt/XmlGspInterface.h index 437a1de6ae39a1aa39ccdd04b9719822703992f8..67546adc1c001f531ce8d399f30fffeefe3383d6 100644 --- a/FileIO/XmlIO/Qt/XmlGspInterface.h +++ b/FileIO/XmlIO/Qt/XmlGspInterface.h @@ -31,7 +31,7 @@ public: * Constructor * \param project Project data. */ - XmlGspInterface(ProjectData* project); + XmlGspInterface(ProjectData &project); virtual ~XmlGspInterface() {}; @@ -49,7 +49,7 @@ protected: private: std::string _filename; - ProjectData* _project; + ProjectData& _project; }; } diff --git a/Gui/DataView/ProcessModel.cpp b/Gui/DataView/ProcessModel.cpp index 93ee157d707a53aad4019f86a4718901582f3304..3697dc82661b9bb9cea1b46d4b495723967fdcdd 100644 --- a/Gui/DataView/ProcessModel.cpp +++ b/Gui/DataView/ProcessModel.cpp @@ -166,7 +166,26 @@ ProcessItem* ProcessModel::addProcess(ProcessInfo *pcs) } } -void ProcessModel::removeFEMConditions(const FiniteElement::ProcessType pcs_type, +const FEMCondition* ProcessModel::getCondition(const FiniteElement::ProcessType pcs_type, const std::string &geo_name, const FEMCondition::CondType cond_type, const GeoLib::GEOTYPE geo_type, const std::string &cond_name) const +{ + Q_UNUSED(geo_name); + ProcessItem const*const pcs_item (this->getProcessParent(pcs_type)); + if (!pcs_item) + return nullptr; + CondObjectListItem const*const cnd_list = getCondParent(pcs_item, cond_type); + if (!cnd_list) + return nullptr; + for (int i = 0; i < cnd_list->childCount(); i++) + { + CondItem* item = static_cast<CondItem*>(cnd_list->child(i)); + if ((item->data(0).toString().toStdString().compare(cond_name) == 0) && + (item->data(1).toString().toStdString().compare(GeoLib::convertGeoTypeToString(geo_type)) == 0)) + return item->getItem(); + } + return nullptr; +} + +void ProcessModel::removeConditions(const FiniteElement::ProcessType pcs_type, const std::string &geometry_name, const FEMCondition::CondType cond_type) { _project.removeConditions(pcs_type, geometry_name, cond_type); @@ -194,7 +213,7 @@ void ProcessModel::removeFEMConditions(const FiniteElement::ProcessType pcs_type void ProcessModel::removeProcess(const FiniteElement::ProcessType type) { - this->removeFEMConditions(type, "", FEMCondition::UNSPECIFIED); + this->removeConditions(type, "", FEMCondition::UNSPECIFIED); const ProcessItem* processParent = this->getProcessParent(type); if (processParent) @@ -241,11 +260,10 @@ ProcessItem* ProcessModel::getProcessParent(const FiniteElement::ProcessType typ for (int i = 0; i < nLists; i++) if (static_cast<ProcessItem*>(_rootItem->child(i))->getItem()->getProcessType() == type) return static_cast<ProcessItem*>(_rootItem->child(i)); - return nullptr; } -CondObjectListItem* ProcessModel::getCondParent(TreeItem* parent, const FEMCondition::CondType type) +CondObjectListItem* ProcessModel::getCondParent(TreeItem const*const parent, const FEMCondition::CondType type) const { int nLists = parent->childCount(); for (int i = 0; i < nLists; i++) @@ -293,3 +311,12 @@ void ProcessModel::replaceCondition(const QModelIndex &idx, FEMCondition* condit //add new condition this->addCondition(condition); } + +void ProcessModel::updateModel() +{ + const std::vector<FEMCondition*> cnd_vec = _project.getConditions(); + for (auto it(cnd_vec.cbegin()); it != cnd_vec.cend(); ++it) + // if Condition is not yet added to GUI, do it now + if (!this->getCondition((*it)->getProcessType(), (*it)->getAssociatedGeometryName(), (*it)->getCondType(), (*it)->getGeomType(), (*it)->getGeoName())) + addConditionItem(*it); +} diff --git a/Gui/DataView/ProcessModel.h b/Gui/DataView/ProcessModel.h index 61656ea46398d142ae36ce944ac7f651cb96f68c..f17c3a03a1a799203241d652c06eaa6acc7b9174 100644 --- a/Gui/DataView/ProcessModel.h +++ b/Gui/DataView/ProcessModel.h @@ -56,8 +56,11 @@ public slots: /// Adds a process to the model ProcessItem* addProcess(ProcessInfo* pcs); + /// Returns the FEM Condition set on a GeoObject with the given name and type from a certain geometry. + const FEMCondition* getCondition(const FiniteElement::ProcessType pcs_type, const std::string &geo_name, const FEMCondition::CondType cond_type, const GeoLib::GEOTYPE geo_type, const std::string &cond_name) const; + /// Removes FEMConditions from the the model. Conditions can be specified by process type, geometry name or condition type or a combination of the three. - void removeFEMConditions(const FiniteElement::ProcessType pcs_type, const std::string &geometry_name, const FEMCondition::CondType cond_type); + void removeConditions(const FiniteElement::ProcessType pcs_type, const std::string &geometry_name, const FEMCondition::CondType cond_type); /// Removes a process from the model void removeProcess(const FiniteElement::ProcessType type); @@ -68,6 +71,9 @@ public slots: /// Remove the given TreeItem and replace it with another condition (this is used for editing FEMConditions) void replaceCondition(const QModelIndex &idx, FEMCondition* condition); + /// Updates the model based on the ProjectData-object + void updateModel(); + private: /// Adds a new FEM condition to the condition tree model. void addConditionItem(FEMCondition* condition); @@ -79,7 +85,7 @@ private: CondObjectListItem* createCondParent(ProcessItem* parent, FEMCondition* cond); /// Returns the subtree-item for a given type of condtion. - CondObjectListItem* getCondParent(TreeItem* parent, const FEMCondition::CondType type) ; + CondObjectListItem* getCondParent(TreeItem const*const parent, const FEMCondition::CondType type) const; /// Returns the subtree item for a process with the given name. If create_item is true, this item will be created if it doesn't exist yet. ProcessItem* getProcessParent(const FiniteElement::ProcessType type) const; diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 154a7fc267742604f97e3e62628866077c530759..292ba5e970c406e0484d87bf71174ecc6656f4a5 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -227,7 +227,7 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) // Setup connections for process model to GUI connect(modellingTabWidget->treeView, SIGNAL(conditionsRemoved(const FiniteElement::ProcessType, const std::string&, const FEMCondition::CondType)), - _processModel, SLOT(removeFEMConditions(const FiniteElement::ProcessType, const std::string&, const FEMCondition::CondType))); + _processModel, SLOT(removeConditions(const FiniteElement::ProcessType, const std::string&, const FEMCondition::CondType))); connect(modellingTabWidget->treeView, SIGNAL(processRemoved(const FiniteElement::ProcessType)), _processModel, SLOT(removeProcess(const FiniteElement::ProcessType))); connect(modellingTabWidget, SIGNAL(requestNewProcess()), @@ -480,7 +480,7 @@ void MainWindow::save() if (fi.suffix().toLower() == "gsp") { - XmlGspInterface xml(&_project); + XmlGspInterface xml(_project); xml.writeToFile(fileName.toStdString()); } else if (fi.suffix().toLower() == "geo") @@ -540,11 +540,11 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) } else if (fi.suffix().toLower() == "gsp") { - XmlGspInterface xml(&_project); + XmlGspInterface xml(_project); if (xml.readFile(fileName)) { - INFO("Adding missing meshes to GUI."); _meshModels->updateModel(); + _processModel->updateModel(); } else OGSError::box("Failed to load project file.\n Please see console for details."); @@ -887,7 +887,7 @@ void MainWindow::loadFEMConditionsFromFile(const QString &fileName, std::string QDir dir = QDir(fileName); settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); std::vector<FEMCondition*> conditions; - XmlCndInterface xml(&_project); + XmlCndInterface xml(_project); std::size_t const n_cond_before(this->_project.getConditions().size()); if (xml.readFile(fileName)) { std::size_t const n_cond_after(this->_project.getConditions().size()); @@ -943,7 +943,7 @@ void MainWindow::addFEMConditions(std::vector<FEMCondition*> const& conditions) void MainWindow::writeFEMConditionsToFile(const QString &geoName, const FEMCondition::CondType type, const QString &fileName) { QFileInfo fi(fileName); - XmlCndInterface xml(&_project); + XmlCndInterface xml(_project); xml.setNameForExport(geoName.toStdString()); xml.setConditionType(type); xml.writeToFile(fileName.toStdString()); diff --git a/OGS/ProjectData.cpp b/OGS/ProjectData.cpp index 63933b7aab139cfe447184973a57e97f16e4981b..d8726011720ee02ac5272c4f2b2b7086c476be6f 100644 --- a/OGS/ProjectData.cpp +++ b/OGS/ProjectData.cpp @@ -125,7 +125,8 @@ void ProjectData::addConditions(std::vector<FEMCondition*> conds) _cond_vec.push_back(conds[i]); } -const FEMCondition* ProjectData::getCondition(const std::string &geo_name, +const FEMCondition* ProjectData::getCondition(FiniteElement::ProcessType pcs_type, + const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &cond_name) const { @@ -135,14 +136,14 @@ const FEMCondition* ProjectData::getCondition(const std::string &geo_name, ((*it)->getGeomType() == type) ) return *it; - std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" << - cond_name << "\"..." << std::endl; - return NULL; + std::cout << "Error in ProjectData::getCondition() - No condition found with name \"" + << cond_name << "\"..." << std::endl; + return nullptr; } std::vector<FEMCondition*> ProjectData::getConditions(FiniteElement::ProcessType pcs_type, - std::string geo_name, - FEMCondition::CondType cond_type) const + std::string geo_name, + FEMCondition::CondType cond_type) const { // if all if (pcs_type == FiniteElement::INVALID_PROCESS && geo_name.empty() && cond_type == FEMCondition::UNSPECIFIED) diff --git a/OGS/ProjectData.h b/OGS/ProjectData.h index 9984e0ebe5d718ad25501bb663196fa45a93a6d0..abf03c25eaf35fe911742a127f4ca6b07f6ea6a7 100644 --- a/OGS/ProjectData.h +++ b/OGS/ProjectData.h @@ -89,7 +89,8 @@ public: virtual void addConditions(std::vector<FEMCondition*> conds); /// Returns the FEM Condition set on a GeoObject with the given name and type from a certain geometry. - const FEMCondition* getCondition(const std::string &geo_name, + const FEMCondition* getCondition(FiniteElement::ProcessType pcs_type, + const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &cond_name) const;