Merged muonspin/musrfit:root6 into master
This commit is contained in:
commit
268772e953
@ -32,6 +32,7 @@
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
#include <QStringRef>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QVector>
|
||||
@ -82,9 +83,56 @@ void PmuppColor::setRGB(const int r, const int g, const int b)
|
||||
*
|
||||
* \param admin pointer to an admin class instance.
|
||||
*/
|
||||
PmuppAdminXMLParser::PmuppAdminXMLParser(PmuppAdmin *admin) : fAdmin(admin)
|
||||
PmuppAdminXMLParser::PmuppAdminXMLParser(const QString& fln, PmuppAdmin *admin) : fAdmin(admin)
|
||||
{
|
||||
fValid = false;
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
QFile file(fln);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
// warning and create default - STILL MISSING
|
||||
}
|
||||
|
||||
fValid = parse(&file);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>parse the mupp startup xml-file.
|
||||
*
|
||||
* \param device QFile object of the mupp startup xml-file
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool PmuppAdminXMLParser::parse(QIODevice *device)
|
||||
{
|
||||
fXml.setDevice(device);
|
||||
|
||||
bool expectChars = false;
|
||||
while (!fXml.atEnd()) {
|
||||
fXml.readNext();
|
||||
if (fXml.isStartDocument()) {
|
||||
startDocument();
|
||||
} else if (fXml.isStartElement()) {
|
||||
startElement();
|
||||
expectChars = true;
|
||||
} else if (fXml.isCharacters() && expectChars) {
|
||||
characters();
|
||||
} else if (fXml.isEndElement()) {
|
||||
endElement();
|
||||
expectChars = false;
|
||||
} else if (fXml.isEndDocument()) {
|
||||
endDocument();
|
||||
}
|
||||
}
|
||||
if (fXml.hasError()) {
|
||||
QString msg;
|
||||
msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber());
|
||||
QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -93,6 +141,7 @@ PmuppAdminXMLParser::PmuppAdminXMLParser(PmuppAdmin *admin) : fAdmin(admin)
|
||||
*/
|
||||
bool PmuppAdminXMLParser::startDocument()
|
||||
{
|
||||
// nothing to be done here for now
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -100,13 +149,11 @@ bool PmuppAdminXMLParser::startDocument()
|
||||
/**
|
||||
* <p>Routine called when a new XML tag is found. Here it is used
|
||||
* to set a tag for filtering afterwards the content.
|
||||
*
|
||||
* \param qName name of the XML tag.
|
||||
*/
|
||||
bool PmuppAdminXMLParser::startElement( const QString&, const QString&,
|
||||
const QString& qName,
|
||||
const QXmlAttributes& )
|
||||
bool PmuppAdminXMLParser::startElement()
|
||||
{
|
||||
QStringRef qName = fXml.name();
|
||||
|
||||
if (qName == "path_file_name") {
|
||||
fKeyWord = eRecentFile;
|
||||
} else if (qName == "dark_theme") {
|
||||
@ -125,10 +172,8 @@ bool PmuppAdminXMLParser::startElement( const QString&, const QString&,
|
||||
* <p>Routine called when the end XML tag is found. It is used to
|
||||
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||
* the entry was a theory function.
|
||||
*
|
||||
* \param qName name of the element.
|
||||
*/
|
||||
bool PmuppAdminXMLParser::endElement( const QString&, const QString&, const QString& )
|
||||
bool PmuppAdminXMLParser::endElement()
|
||||
{
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
@ -139,11 +184,13 @@ bool PmuppAdminXMLParser::endElement( const QString&, const QString&, const QStr
|
||||
/**
|
||||
* <p>This routine delivers the content of an XML tag. It fills the
|
||||
* content into the load data structure.
|
||||
*
|
||||
* \param str keeps the content of the XML tag.
|
||||
*/
|
||||
bool PmuppAdminXMLParser::characters(const QString& str)
|
||||
bool PmuppAdminXMLParser::characters()
|
||||
{
|
||||
QString str = *fXml.text().string();
|
||||
if (str.isEmpty())
|
||||
return true;
|
||||
|
||||
bool ok;
|
||||
int ival, r, g, b;
|
||||
double dval;
|
||||
@ -218,66 +265,6 @@ bool PmuppAdminXMLParser::endDocument()
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report XML warnings.
|
||||
*
|
||||
* \param exception holds the information of the XML warning
|
||||
*/
|
||||
bool PmuppAdminXMLParser::warning( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**WARNING** while parsing mupp_startup.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**WARNING MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report recoverable XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML recoverable errors.
|
||||
*/
|
||||
bool PmuppAdminXMLParser::error( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**ERROR** while parsing mupp_startup.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report fatal XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML fatal errors.
|
||||
*/
|
||||
bool PmuppAdminXMLParser::fatalError( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**FATAL ERROR** while parsing mupp_startup.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**FATAL ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// implementation of PmuppAdmin class
|
||||
//--------------------------------------------------------------------------
|
||||
@ -315,21 +302,16 @@ PmuppAdmin::PmuppAdmin() : QObject(), fDarkTheme(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (QFile::exists(pathFln)) { // administration file present
|
||||
PmuppAdminXMLParser handler(this);
|
||||
QFile xmlFile(pathFln);
|
||||
QXmlInputSource source( &xmlFile );
|
||||
QXmlSimpleReader reader;
|
||||
reader.setContentHandler( &handler );
|
||||
reader.setErrorHandler( &handler );
|
||||
if (!reader.parse( source )) {
|
||||
QMessageBox::critical(0, "ERROR",
|
||||
if (QFile::exists(pathFln)) { // administration file present
|
||||
PmuppAdminXMLParser handler(pathFln, this);
|
||||
if (!handler.isValid()) {
|
||||
QMessageBox::critical(0, "**ERROR**",
|
||||
"Error parsing mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
||||
QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
QMessageBox::critical(0, "ERROR",
|
||||
QMessageBox::critical(0, "**ERROR**",
|
||||
"Couldn't find the mupp_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
||||
QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return;
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
#include <QPixmap>
|
||||
#include <QtXml>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "mupp.h"
|
||||
|
||||
@ -93,29 +93,28 @@ class PmuppMarker {
|
||||
* necessary informations about executable pathes, online help informations,
|
||||
* default font sizes, etc.
|
||||
*/
|
||||
class PmuppAdminXMLParser : public QXmlDefaultHandler
|
||||
class PmuppAdminXMLParser
|
||||
{
|
||||
public:
|
||||
PmuppAdminXMLParser(PmuppAdmin*);
|
||||
PmuppAdminXMLParser(const QString &fln, PmuppAdmin*);
|
||||
virtual ~PmuppAdminXMLParser() {}
|
||||
|
||||
virtual bool isValid() { return fValid; }
|
||||
|
||||
private:
|
||||
enum EAdminKeyWords {eEmpty, eRecentFile, eDarkTheme, eMarker, eColor};
|
||||
|
||||
bool parse(QIODevice *device);
|
||||
bool startDocument();
|
||||
bool startElement( const QString&, const QString&, const QString& ,
|
||||
const QXmlAttributes& );
|
||||
bool endElement( const QString&, const QString&, const QString& );
|
||||
|
||||
bool characters(const QString&);
|
||||
bool startElement();
|
||||
bool endElement();
|
||||
bool characters();
|
||||
bool endDocument();
|
||||
|
||||
bool warning( const QXmlParseException & exception );
|
||||
bool error( const QXmlParseException & exception );
|
||||
bool fatalError( const QXmlParseException & exception );
|
||||
|
||||
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PmuppAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
QXmlStreamReader fXml; ///< xml stream reader object
|
||||
bool fValid; ///< flag showing if XML read has been successful
|
||||
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PmuppAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -27,6 +27,7 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
#include <QProcessEnvironment>
|
||||
|
@ -37,6 +37,8 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
|
||||
#include "mupp_version.h"
|
||||
#include "PmuppScript.h"
|
||||
|
@ -36,6 +36,9 @@ using namespace std;
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QVector>
|
||||
#include <QXmlStreamAttributes>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
#include "PAdmin.h"
|
||||
|
||||
@ -47,28 +50,78 @@ using namespace std;
|
||||
*
|
||||
* \param admin pointer to an admin class instance.
|
||||
*/
|
||||
PFuncXMLParser::PFuncXMLParser(PAdmin *admin) : fAdmin(admin)
|
||||
PFuncXMLParser::PFuncXMLParser(const QString& fln, PAdmin *admin) : fAdmin(admin)
|
||||
{
|
||||
fValid = false;
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
QFile file(fln);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
// warning and create default - STILL MISSING
|
||||
}
|
||||
|
||||
fValid = parse(&file);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p>parse musrfit_funcs.xml
|
||||
*
|
||||
* \param device QFile object of musrfit_funcs.xml
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool PFuncXMLParser::startDocument()
|
||||
bool PFuncXMLParser::parse(QIODevice *device)
|
||||
{
|
||||
fXml.setDevice(device);
|
||||
|
||||
bool expectChars = false;
|
||||
while (!fXml.atEnd()) {
|
||||
fXml.readNext();
|
||||
if (fXml.isStartDocument()) {
|
||||
startDocument();
|
||||
} else if (fXml.isStartElement()) {
|
||||
startElement();
|
||||
expectChars = true;
|
||||
} else if (fXml.isCharacters() && expectChars) {
|
||||
characters();
|
||||
} else if (fXml.isEndElement()) {
|
||||
endElement();
|
||||
expectChars = false;
|
||||
} else if (fXml.isEndDocument()) {
|
||||
endDocument();
|
||||
}
|
||||
}
|
||||
if (fXml.hasError()) {
|
||||
QString msg;
|
||||
msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber());
|
||||
QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p>Routine called at the beginning of the XML parsing process.
|
||||
*/
|
||||
bool PFuncXMLParser::startElement(const QString&, const QString&,
|
||||
const QString& qName,
|
||||
const QXmlAttributes& qAttr)
|
||||
bool PFuncXMLParser::startDocument()
|
||||
{
|
||||
// nothing to be done here for now
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Routine called when a new XML tag is found. Here it is used
|
||||
* to set a tag for filtering afterwards the content.
|
||||
*/
|
||||
bool PFuncXMLParser::startElement()
|
||||
{
|
||||
QStringRef qName = fXml.name();
|
||||
QString str;
|
||||
|
||||
QString errMsg("");
|
||||
int ival;
|
||||
double dval;
|
||||
@ -83,29 +136,26 @@ bool PFuncXMLParser::startElement(const QString&, const QString&,
|
||||
} else if (qName == "theo_fun") {
|
||||
fKeyWord = eTemplateFunc;
|
||||
} else if (qName == "theo_map") {
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
if (qAttr.count() != 2) {
|
||||
errMsg = QString("theo_map should have 2 attributes, called 'no', and 'name', found %1").arg(qAttr.count());
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
PParam map;
|
||||
for (int i=0; i<qAttr.count(); i++) {
|
||||
if (qAttr.qName(i) == "no") {
|
||||
ival = qAttr.value(i).toInt(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("theo_map attribute 'no' is not a number (%1)").arg(qAttr.value(i));
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
map.setNumber(ival);
|
||||
} else if (qAttr.qName(i) == "name") {
|
||||
map.setName(qAttr.value(i));
|
||||
} else {
|
||||
errMsg = QString("found unkown theo_map attribute (%1)").arg(qAttr.qName(i));
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
// get map number
|
||||
str = qAttr.value("no").toString();
|
||||
ival = str.toInt(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("theo_map attribute 'no' is not a number (%1)").arg(str);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
map.setNumber(ival);
|
||||
// get map name
|
||||
str = qAttr.value("name").toString();
|
||||
map.setName(str);
|
||||
|
||||
// check that all necessary attributes where found
|
||||
if ((map.getName() == "UnDef") || (map.getNumber() == -1)) {
|
||||
errMsg = QString("found theo_map with missing attribute(s)");
|
||||
@ -114,45 +164,51 @@ bool PFuncXMLParser::startElement(const QString&, const QString&,
|
||||
}
|
||||
fTheoTemplate.appendMap(map);
|
||||
} else if (qName == "template_param") {
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
if ((qAttr.count() != 4) && (qAttr.count() != 6)) {
|
||||
errMsg = QString("template_param should have 4 or 6 attributes, called\n'no', 'name', 'value', 'step', ['boundLow', 'boundHigh'] found %1").arg(qAttr.count());
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
PParam param;
|
||||
for (int i=0; i<qAttr.count(); i++) {
|
||||
if (qAttr.qName(i) == "no") {
|
||||
ival = qAttr.value(i).toInt(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("template_param attribute 'no' is not a number (%1)").arg(qAttr.value(i));
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
param.setNumber(ival);
|
||||
} else if (qAttr.qName(i) == "name") {
|
||||
param.setName(qAttr.value(i));
|
||||
} else if (qAttr.qName(i) == "value") {
|
||||
dval = qAttr.value(i).toDouble(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("template_param attribute 'value' is not a number (%1)").arg(qAttr.value(i));
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
param.setValue(dval);
|
||||
} else if (qAttr.qName(i) == "step") {
|
||||
dval = qAttr.value(i).toDouble(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("template_param attribute 'step' is not a number (%1)").arg(qAttr.value(i));
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
param.setStep(dval);
|
||||
} else if (qAttr.qName(i) == "boundLow") {
|
||||
param.setBoundLow(qAttr.qName(i));
|
||||
} else if (qAttr.qName(i) == "boundHigh") {
|
||||
param.setBoundHigh(qAttr.qName(i));
|
||||
}
|
||||
// parameter number
|
||||
str = qAttr.value("no").toString();
|
||||
ival = str.toInt(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("template_param attribute 'no' is not a number (%1)").arg(str);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
param.setNumber(ival);
|
||||
// parameter name
|
||||
str = qAttr.value("name").toString();
|
||||
param.setName(str);
|
||||
// parameter value
|
||||
str = qAttr.value("value").toString();
|
||||
dval = str.toDouble(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("template_param attribute 'value' is not a number (%1)").arg(str);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
param.setValue(dval);
|
||||
// parameter step
|
||||
str = qAttr.value("step").toString();
|
||||
dval = str.toDouble(&ok);
|
||||
if (!ok) {
|
||||
errMsg = QString("template_param attribute 'step' is not a number (%1)").arg(str);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return false;
|
||||
}
|
||||
param.setStep(dval);
|
||||
// parameter lower bound
|
||||
str = qAttr.value("boundLow").toString();
|
||||
if (!str.isEmpty())
|
||||
param.setBoundLow(str);
|
||||
// parameter upper bound
|
||||
str = qAttr.value("boundHigh").toString();
|
||||
if (!str.isEmpty())
|
||||
param.setBoundHigh(str);
|
||||
fTheoTemplate.appendParam(param);
|
||||
} else if (qName == "func") {
|
||||
fFunc.initFunc();
|
||||
@ -177,12 +233,16 @@ bool PFuncXMLParser::startElement(const QString&, const QString&,
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p>Routine called when the end XML tag is found. It is used to
|
||||
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||
* the entry was a theory function.
|
||||
*/
|
||||
bool PFuncXMLParser::endElement( const QString&, const QString&, const QString &qName )
|
||||
bool PFuncXMLParser::endElement()
|
||||
{
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
QStringRef qName = fXml.name();
|
||||
|
||||
if (qName == "theo_template") {
|
||||
fAdmin->fTheoTemplate.push_back(fTheoTemplate);
|
||||
} else if (qName == "func") {
|
||||
@ -196,10 +256,15 @@ bool PFuncXMLParser::endElement( const QString&, const QString&, const QString &
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p>This routine delivers the content of an XML tag. It fills the
|
||||
* content into the load data structure.
|
||||
*/
|
||||
bool PFuncXMLParser::characters(const QString &str)
|
||||
bool PFuncXMLParser::characters()
|
||||
{
|
||||
QString str = *fXml.text().string();
|
||||
if (str.isEmpty())
|
||||
return true;
|
||||
|
||||
bool ok;
|
||||
int ival;
|
||||
double dval;
|
||||
@ -246,82 +311,77 @@ bool PFuncXMLParser::characters(const QString &str)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
* <p>Called at the end of the XML parse process. It checks if default paths
|
||||
* contain system variables, and if so expand them for the further use.
|
||||
*/
|
||||
bool PFuncXMLParser::endDocument()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
bool PFuncXMLParser::warning( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**WARNING** while parsing musrfit_funcs.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**WARNING MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
bool PFuncXMLParser::error( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**ERROR** while parsing musrfit_funcs.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
bool PFuncXMLParser::fatalError( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**FATAL ERROR** while parsing musrfit_funcs.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**FATAL ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// implementation of PInstrumentDefXMLParser class
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>XML Parser class for the instrument definition file(s).
|
||||
*
|
||||
* \param file name of the instrument definition file(s).
|
||||
* \param admin pointer to an admin class instance.
|
||||
*/
|
||||
PInstrumentDefXMLParser::PInstrumentDefXMLParser(PAdmin *admin) : fAdmin(admin)
|
||||
PInstrumentDefXMLParser::PInstrumentDefXMLParser(const QString& fln, PAdmin *admin) : fAdmin(admin)
|
||||
{
|
||||
fValid = false;
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
fInstituteName = "";
|
||||
fInstrument = 0;
|
||||
fSetup = 0;
|
||||
|
||||
QFile file(fln);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
// warning and create default - STILL MISSING
|
||||
}
|
||||
|
||||
fValid = parse(&file);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>parse the instrument definition xml-file(s).
|
||||
*
|
||||
* \param device QFile object of the instrument definition xml-file(s).
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::parse(QIODevice *device)
|
||||
{
|
||||
fXml.setDevice(device);
|
||||
|
||||
bool expectChars = false;
|
||||
while (!fXml.atEnd()) {
|
||||
fXml.readNext();
|
||||
if (fXml.isStartDocument()) {
|
||||
startDocument();
|
||||
} else if (fXml.isStartElement()) {
|
||||
startElement();
|
||||
expectChars = true;
|
||||
} else if (fXml.isCharacters() && expectChars) {
|
||||
characters();
|
||||
} else if (fXml.isEndElement()) {
|
||||
endElement();
|
||||
expectChars = false;
|
||||
} else if (fXml.isEndDocument()) {
|
||||
endDocument();
|
||||
}
|
||||
}
|
||||
if (fXml.hasError()) {
|
||||
QString msg;
|
||||
msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber());
|
||||
QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -330,6 +390,7 @@ PInstrumentDefXMLParser::PInstrumentDefXMLParser(PAdmin *admin) : fAdmin(admin)
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::startDocument()
|
||||
{
|
||||
// nothing to be done here for now
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -337,13 +398,11 @@ bool PInstrumentDefXMLParser::startDocument()
|
||||
/**
|
||||
* <p>Routine called when a new XML tag is found. Here it is used
|
||||
* to set a tag for filtering afterwards the content.
|
||||
*
|
||||
* \param qName name of the XML tag.
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
||||
const QString& qName,
|
||||
const QXmlAttributes& qAttr)
|
||||
bool PInstrumentDefXMLParser::startElement()
|
||||
{
|
||||
QStringRef qName = fXml.name();
|
||||
|
||||
bool ok;
|
||||
double dval;
|
||||
double ival;
|
||||
@ -356,6 +415,7 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
||||
fKeyWord = eInstitute;
|
||||
} else if (qName == "instrument") {
|
||||
fKeyWord = eInstrument;
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
if (qAttr.count() != 1) {
|
||||
errMsg = QString("instrument should have 1 attribute, called 'name', found %1").arg(qAttr.count());
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
@ -369,7 +429,7 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
||||
// create an instrument object
|
||||
fInstrument = new PInstrument();
|
||||
fInstrument->setInstitue(fInstituteName);
|
||||
fInstrument->setName(qAttr.value(0));
|
||||
fInstrument->setName(qAttr.value("name").toString());
|
||||
} else if (qName == "run_name_template") {
|
||||
fKeyWord = eRunNameTemplate;
|
||||
} else if (qName == "beamline") {
|
||||
@ -378,23 +438,26 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
||||
fKeyWord = eDataFileFormat;
|
||||
} else if (qName == "tf") {
|
||||
fKeyWord = eTf;
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
fSetup = new PSetup();
|
||||
if (qAttr.count() == 1)
|
||||
fSetup->setName(qAttr.value(0));
|
||||
fSetup->setName(qAttr.value("name").toString());
|
||||
else
|
||||
fSetup->setName("Default");
|
||||
} else if (qName == "zf") {
|
||||
fKeyWord = eZf;
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
fSetup = new PSetup();
|
||||
if (qAttr.count() == 1)
|
||||
fSetup->setName(qAttr.value(0));
|
||||
fSetup->setName(qAttr.value("name").toString());
|
||||
else
|
||||
fSetup->setName("Default");
|
||||
} else if (qName == "lf") {
|
||||
fKeyWord = eLf;
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
fSetup = new PSetup();
|
||||
if (qAttr.count() == 1)
|
||||
fSetup->setName(qAttr.value(0));
|
||||
fSetup->setName(qAttr.value("name").toString());
|
||||
else
|
||||
fSetup->setName("Default");
|
||||
} else if (qName == "no_of_detectors") {
|
||||
@ -406,94 +469,78 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
||||
} else if (qName == "asym_bkg_range") {
|
||||
fKeyWord = eBkgRange;
|
||||
} else if (qName == "logic_detector") {
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
if (qAttr.count() < 3)
|
||||
return false;
|
||||
PDetector detect;
|
||||
int count=0;
|
||||
for (int i=0; i<qAttr.count(); i++) {
|
||||
if (qAttr.localName(i) == "name") {
|
||||
detect.setName(qAttr.value(i)); // detector name
|
||||
count++;
|
||||
} else if (qAttr.localName(i) == "rel_phase") {
|
||||
str = qAttr.value(i);
|
||||
dval = str.toDouble(&ok);
|
||||
if (ok) {
|
||||
detect.setRelGeomPhase(dval);
|
||||
count++;
|
||||
}
|
||||
} else if (qAttr.localName(i) == "forward") {
|
||||
str = qAttr.value(i);
|
||||
strL.clear();
|
||||
strL = str.split(' ');
|
||||
forward.clear();
|
||||
for (int j=0; j<strL.size(); j++) {
|
||||
ival = strL[j].toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
forward.push_back(ival);
|
||||
}
|
||||
detect.setForwards(forward);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count != 3) // i.e. didn't find all needed attributes
|
||||
// detector name
|
||||
str = qAttr.value("name").toString();
|
||||
detect.setName(str);
|
||||
// detector relative phase
|
||||
str = qAttr.value("rel_phase").toString();
|
||||
dval = str.toDouble(&ok);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
detect.setRelGeomPhase(dval);
|
||||
// detector number(s)
|
||||
str = qAttr.value("forward").toString();
|
||||
strL.clear();
|
||||
strL = str.split(' ');
|
||||
forward.clear();
|
||||
for (int j=0; j<strL.size(); j++) {
|
||||
ival = strL[j].toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
forward.push_back(ival);
|
||||
}
|
||||
detect.setForwards(forward);
|
||||
fSetup->addDetector(detect);
|
||||
} else if (qName == "logic_asym_detector") {
|
||||
QXmlStreamAttributes qAttr = fXml.attributes();
|
||||
if (qAttr.count() != 5)
|
||||
return false;
|
||||
PDetector detect;
|
||||
int count=0;
|
||||
for (int i=0; i<5; i++) {
|
||||
if (qAttr.localName(i) == "name") {
|
||||
detect.setName(qAttr.value(i)); // detector name
|
||||
count++;
|
||||
} else if (qAttr.localName(i) == "rel_phase") {
|
||||
str = qAttr.value(i);
|
||||
dval = str.toDouble(&ok);
|
||||
if (ok) {
|
||||
detect.setRelGeomPhase(dval);
|
||||
count++;
|
||||
}
|
||||
} else if (qAttr.localName(i) == "forward") {
|
||||
str = qAttr.value(i);
|
||||
strL.clear();
|
||||
strL = str.split(' ');
|
||||
forward.clear();
|
||||
for (int j=0; j<strL.size(); j++) {
|
||||
ival = strL[j].toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
forward.push_back(ival);
|
||||
}
|
||||
detect.setForwards(forward);
|
||||
count++;
|
||||
} else if (qAttr.localName(i) == "backward") {
|
||||
str = qAttr.value(i);
|
||||
strL.clear();
|
||||
strL = str.split(' ');
|
||||
backward.clear();
|
||||
for (int j=0; j<strL.size(); j++) {
|
||||
ival = strL[j].toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
backward.push_back(ival);
|
||||
}
|
||||
detect.setBackwards(backward);
|
||||
count++;
|
||||
} else if (qAttr.localName(i) == "alpha") {
|
||||
str = qAttr.value(i);
|
||||
dval = str.toDouble(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
detect.setAlpha(dval);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count != 5) // i.e. didn't find all needed attributes
|
||||
// detector name
|
||||
str = qAttr.value("name").toString();
|
||||
detect.setName(str);
|
||||
// detector relative phase
|
||||
str = qAttr.value("rel_phase").toString();
|
||||
dval = str.toDouble(&ok);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
detect.setRelGeomPhase(dval);
|
||||
// detector forward
|
||||
str = qAttr.value("forward").toString();
|
||||
strL.clear();
|
||||
strL = str.split(' ');
|
||||
forward.clear();
|
||||
for (int j=0; j<strL.size(); j++) {
|
||||
ival = strL[j].toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
forward.push_back(ival);
|
||||
}
|
||||
detect.setForwards(forward);
|
||||
// detector backward
|
||||
str = qAttr.value("backward").toString();
|
||||
strL.clear();
|
||||
strL = str.split(' ');
|
||||
backward.clear();
|
||||
for (int j=0; j<strL.size(); j++) {
|
||||
ival = strL[j].toInt(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
backward.push_back(ival);
|
||||
}
|
||||
detect.setForwards(backward);
|
||||
// detector alpha
|
||||
str = qAttr.value("alpha").toString();
|
||||
dval = str.toDouble(&ok);
|
||||
if (!ok)
|
||||
return false;
|
||||
detect.setAlpha(dval);
|
||||
fSetup->addAsymDetector(detect);
|
||||
}
|
||||
|
||||
@ -505,13 +552,13 @@ bool PInstrumentDefXMLParser::startElement( const QString&, const QString&,
|
||||
* <p>Routine called when the end XML tag is found. It is used to
|
||||
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||
* the entry was a theory function.
|
||||
*
|
||||
* \param qName name of the element.
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::endElement( const QString&, const QString&, const QString &qName )
|
||||
bool PInstrumentDefXMLParser::endElement()
|
||||
{
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
QStringRef qName = fXml.name();
|
||||
|
||||
if (qName == "instrument") {
|
||||
// store instrument
|
||||
fAdmin->addInstrument(fInstituteName, *fInstrument);
|
||||
@ -557,11 +604,13 @@ bool PInstrumentDefXMLParser::endElement( const QString&, const QString&, const
|
||||
/**
|
||||
* <p>This routine delivers the content of an XML tag. It fills the
|
||||
* content into the load data structure.
|
||||
*
|
||||
* \param str keeps the content of the XML tag.
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::characters(const QString& str)
|
||||
bool PInstrumentDefXMLParser::characters()
|
||||
{
|
||||
QString str = *fXml.text().string();
|
||||
if (str.isEmpty())
|
||||
return true;
|
||||
|
||||
bool ok;
|
||||
int ival, start, end;
|
||||
QString errMsg;
|
||||
@ -649,66 +698,6 @@ bool PInstrumentDefXMLParser::endDocument()
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report XML warnings.
|
||||
*
|
||||
* \param exception holds the information of the XML warning
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::warning( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**WARNING** while parsing instrument_def_XXX.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**WARNING MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report recoverable XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML recoverable errors.
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::error( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**ERROR** while parsing instrument_def_XXX.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report fatal XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML fatal errors.
|
||||
*/
|
||||
bool PInstrumentDefXMLParser::fatalError( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**FATAL ERROR** while parsing parsing instrument_def_XXX.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**FATAL ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// implementation of PMusrWizDefault class
|
||||
//--------------------------------------------------------------------------
|
||||
@ -730,9 +719,56 @@ PMusrWizDefault::PMusrWizDefault()
|
||||
*
|
||||
* \param admin pointer to an admin class instance.
|
||||
*/
|
||||
PMusrWizDefaultXMLParser::PMusrWizDefaultXMLParser(PAdmin *admin) : fAdmin(admin)
|
||||
PMusrWizDefaultXMLParser::PMusrWizDefaultXMLParser(const QString& fln, PAdmin *admin) : fAdmin(admin)
|
||||
{
|
||||
fValid = false;
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
QFile file(fln);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
// warning and create default - STILL MISSING
|
||||
}
|
||||
|
||||
fValid = parse(&file);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>parse the musrWiz startup xml-file.
|
||||
*
|
||||
* \param device QFile object of the musrWiz startup xml-file
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::parse(QIODevice *device)
|
||||
{
|
||||
fXml.setDevice(device);
|
||||
|
||||
bool expectChars = false;
|
||||
while (!fXml.atEnd()) {
|
||||
fXml.readNext();
|
||||
if (fXml.isStartDocument()) {
|
||||
startDocument();
|
||||
} else if (fXml.isStartElement()) {
|
||||
startElement();
|
||||
expectChars = true;
|
||||
} else if (fXml.isCharacters() && expectChars) {
|
||||
characters();
|
||||
} else if (fXml.isEndElement()) {
|
||||
endElement();
|
||||
expectChars = false;
|
||||
} else if (fXml.isEndDocument()) {
|
||||
endDocument();
|
||||
}
|
||||
}
|
||||
if (fXml.hasError()) {
|
||||
QString msg;
|
||||
msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber());
|
||||
QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -741,6 +777,7 @@ PMusrWizDefaultXMLParser::PMusrWizDefaultXMLParser(PAdmin *admin) : fAdmin(admin
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::startDocument()
|
||||
{
|
||||
// nothing to be done here for now
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -748,13 +785,11 @@ bool PMusrWizDefaultXMLParser::startDocument()
|
||||
/**
|
||||
* <p>Routine called when a new XML tag is found. Here it is used
|
||||
* to set a tag for filtering afterwards the content.
|
||||
*
|
||||
* \param qName name of the XML tag.
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::startElement( const QString&, const QString&,
|
||||
const QString& qName,
|
||||
const QXmlAttributes& )
|
||||
bool PMusrWizDefaultXMLParser::startElement()
|
||||
{
|
||||
QStringRef qName = fXml.name();
|
||||
|
||||
if (qName == "institute") {
|
||||
fKeyWord = eInstitute;
|
||||
} else if (qName == "instrument") {
|
||||
@ -771,10 +806,8 @@ bool PMusrWizDefaultXMLParser::startElement( const QString&, const QString&,
|
||||
* <p>Routine called when the end XML tag is found. It is used to
|
||||
* put the filtering tag to 'empty'. It also resets the fFunc flag in case
|
||||
* the entry was a theory function.
|
||||
*
|
||||
* \param qName name of the element.
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::endElement( const QString&, const QString&, const QString& )
|
||||
bool PMusrWizDefaultXMLParser::endElement()
|
||||
{
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
@ -785,11 +818,13 @@ bool PMusrWizDefaultXMLParser::endElement( const QString&, const QString&, const
|
||||
/**
|
||||
* <p>This routine delivers the content of an XML tag. It fills the
|
||||
* content into the load data structure.
|
||||
*
|
||||
* \param str keeps the content of the XML tag.
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::characters(const QString& str)
|
||||
bool PMusrWizDefaultXMLParser::characters()
|
||||
{
|
||||
QString str = *fXml.text().string();
|
||||
if (str.isEmpty())
|
||||
return true;
|
||||
|
||||
switch (fKeyWord) {
|
||||
case eInstitute:
|
||||
fDefault.setInstitute(str);
|
||||
@ -818,66 +853,6 @@ bool PMusrWizDefaultXMLParser::endDocument()
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report XML warnings.
|
||||
*
|
||||
* \param exception holds the information of the XML warning
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::warning( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**WARNING** while parsing musrWiz.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**WARNING MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report recoverable XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML recoverable errors.
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::error( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**ERROR** while parsing musrWiz.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report fatal XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML fatal errors.
|
||||
*/
|
||||
bool PMusrWizDefaultXMLParser::fatalError( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**FATAL ERROR** while parsing parsing musrWiz.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**FATAL ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// implementation of PAdmin class
|
||||
//--------------------------------------------------------------------------
|
||||
@ -1245,12 +1220,8 @@ int PAdmin::loadMusrWizDefault(QString fln)
|
||||
}
|
||||
}
|
||||
|
||||
PMusrWizDefaultXMLParser handler(this);
|
||||
QFile xmlFile(fln);
|
||||
QXmlInputSource source( &xmlFile );
|
||||
QXmlSimpleReader reader;
|
||||
reader.setContentHandler( &handler );
|
||||
if (!reader.parse(source)) {
|
||||
PMusrWizDefaultXMLParser handler(fln, this);
|
||||
if (!handler.isValid()) {
|
||||
QString errMsg = QString("Error parsing %1 file.").arg(fln);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return 1;
|
||||
@ -1282,12 +1253,8 @@ int PAdmin::loadMusrfitFunc(QString fln)
|
||||
}
|
||||
}
|
||||
|
||||
PFuncXMLParser handler(this);
|
||||
QFile xmlFile(fln);
|
||||
QXmlInputSource source( &xmlFile );
|
||||
QXmlSimpleReader reader;
|
||||
reader.setContentHandler( &handler );
|
||||
if (!reader.parse(source)) {
|
||||
PFuncXMLParser handler(fln, this);
|
||||
if (!handler.isValid()) {
|
||||
QString errMsg = QString("Error parsing %1 musrfit func file.").arg(fln);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return 1;
|
||||
@ -1326,12 +1293,8 @@ int PAdmin::loadInstrumentDef(QString path, QString fln)
|
||||
}
|
||||
}
|
||||
|
||||
PInstrumentDefXMLParser handler(this);
|
||||
QFile xmlFile(pathFln);
|
||||
QXmlInputSource source( &xmlFile );
|
||||
QXmlSimpleReader reader;
|
||||
reader.setContentHandler( &handler );
|
||||
if (!reader.parse(source)) {
|
||||
PInstrumentDefXMLParser handler(pathFln, this);
|
||||
if (!handler.isValid()) {
|
||||
QString errMsg = QString("Error parsing %1 instrument def file.").arg(pathFln);
|
||||
QMessageBox::critical(0, "ERROR", errMsg);
|
||||
return 1;
|
||||
|
@ -32,7 +32,10 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QtXml>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QIODevice>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QDir>
|
||||
|
||||
#include "PTheoTemplate.h"
|
||||
#include "PMusrfitFunc.h"
|
||||
@ -41,32 +44,32 @@
|
||||
class PAdmin;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
class PFuncXMLParser : public QXmlDefaultHandler
|
||||
class PFuncXMLParser
|
||||
{
|
||||
public:
|
||||
PFuncXMLParser(PAdmin*);
|
||||
PFuncXMLParser(const QString &fln, PAdmin*);
|
||||
virtual ~PFuncXMLParser() {}
|
||||
|
||||
virtual bool isValid() { return fValid; }
|
||||
|
||||
private:
|
||||
enum EFuncKeyWords {eEmpty,
|
||||
eTemplateName, eTemplateTheo, eTemplateFunc,
|
||||
eName, eAbbrv, eNoOfParam, eParam,
|
||||
eParamName, eParamValue, eParamMap};
|
||||
|
||||
bool parse(QIODevice *device);
|
||||
bool startDocument();
|
||||
bool startElement(const QString&, const QString&, const QString& ,
|
||||
const QXmlAttributes& qAttr);
|
||||
bool endElement( const QString&, const QString&, const QString& );
|
||||
|
||||
bool characters(const QString&);
|
||||
bool startElement();
|
||||
bool endElement();
|
||||
bool characters();
|
||||
bool endDocument();
|
||||
|
||||
bool warning( const QXmlParseException & exception );
|
||||
bool error( const QXmlParseException & exception );
|
||||
bool fatalError( const QXmlParseException & exception );
|
||||
|
||||
EFuncKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
QXmlStreamReader fXml; ///< xml stream reader object
|
||||
bool fValid; ///< flag showing if XML read has been successful
|
||||
EFuncKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
|
||||
PTheoTemplate fTheoTemplate;
|
||||
PMusrfitFunc fFunc;
|
||||
@ -74,32 +77,31 @@ class PFuncXMLParser : public QXmlDefaultHandler
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
class PInstrumentDefXMLParser : public QXmlDefaultHandler
|
||||
class PInstrumentDefXMLParser
|
||||
{
|
||||
public:
|
||||
PInstrumentDefXMLParser(PAdmin*);
|
||||
PInstrumentDefXMLParser(const QString &fln, PAdmin*);
|
||||
virtual ~PInstrumentDefXMLParser() {}
|
||||
|
||||
virtual bool isValid() { return fValid; }
|
||||
|
||||
private:
|
||||
enum EKeyWords {eEmpty, eInstitute, eInstrument, eRunNameTemplate,
|
||||
eBeamline, eDataFileFormat, eTf, eZf, eLf,
|
||||
eNoOfDetectors, eFgbOffset, eLgb, eBkgRange,
|
||||
eLogicDetector};
|
||||
|
||||
bool parse(QIODevice *device);
|
||||
bool startDocument();
|
||||
bool startElement(const QString&, const QString&, const QString& ,
|
||||
const QXmlAttributes& qAttr);
|
||||
bool endElement( const QString&, const QString&, const QString& );
|
||||
|
||||
bool characters(const QString&);
|
||||
bool startElement();
|
||||
bool endElement();
|
||||
bool characters();
|
||||
bool endDocument();
|
||||
|
||||
bool warning( const QXmlParseException & exception );
|
||||
bool error( const QXmlParseException & exception );
|
||||
bool fatalError( const QXmlParseException & exception );
|
||||
|
||||
EKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
QXmlStreamReader fXml; ///< xml stream reader object
|
||||
bool fValid; ///< flag showing if XML read has been successful
|
||||
EKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
|
||||
QString fInstituteName;
|
||||
PInstrument *fInstrument;
|
||||
@ -128,27 +130,26 @@ class PMusrWizDefault
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
class PMusrWizDefaultXMLParser : public QXmlDefaultHandler
|
||||
class PMusrWizDefaultXMLParser
|
||||
{
|
||||
public:
|
||||
PMusrWizDefaultXMLParser(PAdmin*);
|
||||
PMusrWizDefaultXMLParser(const QString &fln, PAdmin*);
|
||||
virtual ~PMusrWizDefaultXMLParser() {}
|
||||
|
||||
virtual bool isValid() { return fValid; }
|
||||
|
||||
private:
|
||||
enum EKeyWords {eEmpty, eInstitute, eInstrument, eFitType};
|
||||
|
||||
bool parse(QIODevice *device);
|
||||
bool startDocument();
|
||||
bool startElement(const QString&, const QString&, const QString& ,
|
||||
const QXmlAttributes& );
|
||||
bool endElement( const QString&, const QString&, const QString& );
|
||||
|
||||
bool characters(const QString&);
|
||||
bool startElement();
|
||||
bool endElement();
|
||||
bool characters();
|
||||
bool endDocument();
|
||||
|
||||
bool warning( const QXmlParseException & exception );
|
||||
bool error( const QXmlParseException & exception );
|
||||
bool fatalError( const QXmlParseException & exception );
|
||||
|
||||
QXmlStreamReader fXml; ///< xml stream reader object
|
||||
bool fValid; ///< flag showing if XML read has been successful
|
||||
EKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PAdmin *fAdmin; ///< a pointer to the main administration class object
|
||||
|
||||
|
@ -27,21 +27,76 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QString>
|
||||
#include <QStringRef>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QListWidgetItem>
|
||||
#include <QIODevice>
|
||||
#include <QFile>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "PChangeDefaultPathsDialog.h"
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
/**
|
||||
* @brief PDefaultPathsXMLParser::PDefaultPathsXMLParser
|
||||
* <p>XML Parser class for the musrfit administration file.
|
||||
*
|
||||
* \param fln file name of the musredit startup xml-file
|
||||
* @param defaultPaths
|
||||
*/
|
||||
PDefaultPathsXMLParser::PDefaultPathsXMLParser(PDefaultPaths *defaultPaths) :
|
||||
PDefaultPathsXMLParser::PDefaultPathsXMLParser(const QString& fln, PDefaultPaths *defaultPaths) :
|
||||
fDefaultPaths(defaultPaths)
|
||||
{
|
||||
fValid = false;
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
QFile file(fln);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
// warning and create default - STILL MISSING
|
||||
}
|
||||
|
||||
fValid = parse(&file);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>parse the musrfit startup xml-file.
|
||||
*
|
||||
* \param device QFile object of the musrfit startup xml-file
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::parse(QIODevice *device)
|
||||
{
|
||||
fXml.setDevice(device);
|
||||
|
||||
bool expectChars = false;
|
||||
while (!fXml.atEnd()) {
|
||||
fXml.readNext();
|
||||
if (fXml.isStartDocument()) {
|
||||
startDocument();
|
||||
} else if (fXml.isStartElement()) {
|
||||
startElement();
|
||||
expectChars = true;
|
||||
} else if (fXml.isCharacters() && expectChars) {
|
||||
characters();
|
||||
} else if (fXml.isEndElement()) {
|
||||
endElement();
|
||||
expectChars = false;
|
||||
} else if (fXml.isEndDocument()) {
|
||||
endDocument();
|
||||
}
|
||||
}
|
||||
if (fXml.hasError()) {
|
||||
QString msg;
|
||||
msg = QString("%1 Line %2, column %3").arg(fXml.errorString()).arg(fXml.lineNumber()).arg(fXml.columnNumber());
|
||||
QMessageBox::critical(0, "**ERROR**", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@ -50,6 +105,7 @@ PDefaultPathsXMLParser::PDefaultPathsXMLParser(PDefaultPaths *defaultPaths) :
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::startDocument()
|
||||
{
|
||||
// nothing to be done here for now
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -57,13 +113,11 @@ bool PDefaultPathsXMLParser::startDocument()
|
||||
/**
|
||||
* <p>Routine called when a new XML tag is found. Here it is used
|
||||
* to set a tag for filtering afterwards the content.
|
||||
*
|
||||
* \param qName name of the XML tag.
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::startElement( const QString&, const QString&,
|
||||
const QString& qName,
|
||||
const QXmlAttributes& )
|
||||
bool PDefaultPathsXMLParser::startElement()
|
||||
{
|
||||
QStringRef qName = fXml.name();
|
||||
|
||||
if (qName == "data_path") {
|
||||
fKeyWord = eDataPath;
|
||||
}
|
||||
@ -75,10 +129,8 @@ bool PDefaultPathsXMLParser::startElement( const QString&, const QString&,
|
||||
/**
|
||||
* <p>Routine called when the end XML tag is found. It is used to
|
||||
* put the filtering tag to 'empty'.
|
||||
*
|
||||
* \param qName name of the element.
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::endElement( const QString&, const QString&, const QString & )
|
||||
bool PDefaultPathsXMLParser::endElement()
|
||||
{
|
||||
fKeyWord = eEmpty;
|
||||
|
||||
@ -89,11 +141,13 @@ bool PDefaultPathsXMLParser::endElement( const QString&, const QString&, const Q
|
||||
/**
|
||||
* <p>This routine delivers the content of an XML tag. It fills the
|
||||
* content into the load data structure.
|
||||
*
|
||||
* \param str keeps the content of the XML tag.
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::characters(const QString& str)
|
||||
bool PDefaultPathsXMLParser::characters()
|
||||
{
|
||||
QString str = *fXml.text().string();
|
||||
if (str.isEmpty())
|
||||
return true;
|
||||
|
||||
switch (fKeyWord) {
|
||||
case eDataPath:
|
||||
fDefaultPaths->appendDefaultPath(str);
|
||||
@ -115,67 +169,10 @@ bool PDefaultPathsXMLParser::endDocument()
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report XML warnings.
|
||||
*
|
||||
* \param exception holds the information of the XML warning
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::warning( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**WARNING** while parsing musrfit_startup.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**WARNING MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::warning(0, "WARNING", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report recoverable XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML recoverable errors.
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::error( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**ERROR** while parsing musrfit_startup.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Report fatal XML errors.
|
||||
*
|
||||
* \param exception holds the information of the XML fatal errors.
|
||||
*/
|
||||
bool PDefaultPathsXMLParser::fatalError( const QXmlParseException & exception )
|
||||
{
|
||||
QString msg;
|
||||
|
||||
msg = QString("**FATAL ERROR** while parsing musrfit_startup.xml in line no %1\n").arg(exception.lineNumber());
|
||||
msg += QString("**FATAL ERROR MESSAGE** ") + exception.message();
|
||||
|
||||
qWarning() << endl << msg << endl;
|
||||
|
||||
QMessageBox::critical(0, "FATAL ERROR", msg, QMessageBox::Ok, QMessageBox::NoButton);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
/**
|
||||
* @brief PDefaultPaths::PDefaultPaths
|
||||
*/
|
||||
PDefaultPaths::PDefaultPaths() : QObject()
|
||||
{
|
||||
fValid = true;
|
||||
@ -204,13 +201,8 @@ PDefaultPaths::PDefaultPaths() : QObject()
|
||||
fPrefPathName = pathFln;
|
||||
|
||||
// read musrfit_startup.xml and extract default data file search paths
|
||||
PDefaultPathsXMLParser handler(this);
|
||||
QFile xmlFile(fPrefPathName);
|
||||
QXmlInputSource source( &xmlFile );
|
||||
QXmlSimpleReader reader;
|
||||
reader.setContentHandler( &handler );
|
||||
reader.setErrorHandler( &handler );
|
||||
if (!reader.parse( source )) {
|
||||
PDefaultPathsXMLParser handler(fPrefPathName, this);
|
||||
if (!handler.isValid()) {
|
||||
fValid = false;
|
||||
QMessageBox::critical(0, "ERROR",
|
||||
"Error parsing musrfit_startup.xml settings file.\nProbably a few things will not work porperly.\nPlease fix this first.",
|
||||
|
@ -32,36 +32,36 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QtXml>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QIODevice>
|
||||
|
||||
#include "ui_PChangeDefaultPathsDialog.h"
|
||||
|
||||
class PDefaultPaths;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
class PDefaultPathsXMLParser : public QXmlDefaultHandler
|
||||
class PDefaultPathsXMLParser
|
||||
{
|
||||
public:
|
||||
PDefaultPathsXMLParser(PDefaultPaths *defaultPaths);
|
||||
PDefaultPathsXMLParser(const QString &fln, PDefaultPaths *defaultPaths);
|
||||
virtual ~PDefaultPathsXMLParser() {}
|
||||
|
||||
virtual bool isValid() { return fValid; }
|
||||
|
||||
private:
|
||||
enum EAdminKeyWords {eEmpty, eDataPath};
|
||||
|
||||
bool parse(QIODevice *device);
|
||||
bool startDocument();
|
||||
bool startElement( const QString&, const QString&, const QString& ,
|
||||
const QXmlAttributes& );
|
||||
bool endElement( const QString&, const QString&, const QString& );
|
||||
|
||||
bool characters(const QString&);
|
||||
bool startElement();
|
||||
bool endElement();
|
||||
bool characters();
|
||||
bool endDocument();
|
||||
|
||||
bool warning( const QXmlParseException & exception );
|
||||
bool error( const QXmlParseException & exception );
|
||||
bool fatalError( const QXmlParseException & exception );
|
||||
|
||||
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PDefaultPaths *fDefaultPaths; ///< keeps the default search paths for the data files
|
||||
QXmlStreamReader fXml; ///< xml stream reader object
|
||||
bool fValid; ///< flag showing if XML read has been successful
|
||||
EAdminKeyWords fKeyWord; ///< key word tag to know how to handle the content
|
||||
PDefaultPaths *fDefaultPaths; ///< keeps the default search paths for the data files
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user