/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ElmerGUI egini *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter Råback *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/3940#include <iostream>41#include "egini.h"4243using namespace std;4445EgIni::EgIni(QWidget *parent)46: QDialog(parent)47{48iniLoaded = false;4950// Determine ini-file location and name:51//--------------------------------------52QString elmerGuiHome;53QString paraViewHome;5455#ifdef __APPLE__DONTGOHERE_TODO56//QString iniFileName = this->homePath + "/edf/egini.xml";57QString iniFileName = QDir::homePath() + "/edf/egini.xml";58#else59QString iniFileName = QCoreApplication::applicationDirPath() + "/../share/ElmerGUI/edf/egini.xml"; // @TODO: fix path to share/ElmerGUI/edf6061elmerGuiHome = QString(getenv("ELMERGUI_HOME"));6263if(!elmerGuiHome.isEmpty())64iniFileName = elmerGuiHome + "/edf/egini.xml";6566paraViewHome = QString(getenv("PARAVIEW_HOME"))+"/bin";67#endif6869// Load initialization file:70//---------------------------71#if WITH_QT5 || WITH_QT672cout << "Load " << string(iniFileName.toLatin1()) << "...";73#else74cout << "Load " << string(iniFileName.toAscii()) << "...";75#endif76cout.flush();7778QFile file(iniFileName);79QString errStr;80int errRow;81int errCol;8283if(!file.exists()) {8485QMessageBox::information(window(), tr("Eg ini-file loader: ") + iniFileName,86tr("Initialization file does not exist"));87return;8889} else {9091if(!iniDoc.setContent(&file, true, &errStr, &errRow, &errCol)) {9293QMessageBox::information(window(), tr("Eg ini-file loader: ") + iniFileName,94tr("Parse error at line %1, col %2:\n%3")95.arg(errRow).arg(errCol).arg(errStr));96file.close();97return;9899} else {100101if(iniDoc.documentElement().tagName() != "egini") {102QMessageBox::information(window(), tr("Eg ini-file loader: ") + iniFileName,103tr("This is not an eg initialization file"));104file.close();105return;106}107}108}109110cout << " done" << endl;111file.close();112iniLoaded = true;113}114115116EgIni::~EgIni()117{118}119120121bool EgIni::isPresent(QString tag)122{123if(!iniLoaded)124return false;125126root = iniDoc.documentElement();127element = root.firstChildElement(tag);128129if(element.isNull())130return false;131132return true;133}134135136bool EgIni::isSet(QString tag)137{138if(!iniLoaded)139return false;140141root = iniDoc.documentElement();142element = root.firstChildElement(tag);143144if(element.isNull())145return false;146147if(element.text().trimmed() != "0")148return true;149150return false;151}152153154QString EgIni::value(QString tag)155{156if(!iniLoaded)157return "";158159root = iniDoc.documentElement();160element = root.firstChildElement(tag);161162if(element.isNull())163return "";164165return element.text().trimmed();166}167168169