work an interactive variable definition in mupp. Up to checking it is already working. Add variable still missing.
This commit is contained in:
parent
51b9126e2b
commit
c755dec623
@ -48,7 +48,8 @@ set(MUPP_SOURCE_FILES
|
|||||||
Pmupp.cpp
|
Pmupp.cpp
|
||||||
PmuppScript.cpp
|
PmuppScript.cpp
|
||||||
PmuppGui.cpp
|
PmuppGui.cpp
|
||||||
PGetNormValDialog.cpp
|
PVarDialog.cpp
|
||||||
|
#as35 PGetNormValDialog.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
|
|
||||||
PGetNormValDialog.h
|
|
||||||
|
|
||||||
Author: Andreas Suter
|
|
||||||
e-mail: andreas.suter@psi.ch
|
|
||||||
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2007-2020 by Andreas Suter *
|
|
||||||
* andreas.suter@psi.ch *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
#ifndef _PGETNORMVALDIALOG_H_
|
|
||||||
#define _PGETNORMVALDIALOG_H_
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QLineEdit>
|
|
||||||
|
|
||||||
class PGetNormValDialog : public QDialog
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
PGetNormValDialog(double dval, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
|
||||||
virtual ~PGetNormValDialog() {}
|
|
||||||
|
|
||||||
virtual double getValue() { return fValue; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
double fValue;
|
|
||||||
QLineEdit *fEdit;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
virtual void gotValue(const QString& str);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _PGETNORMVALDIALOG_H_
|
|
404
src/musredit_qt5/mupp/PVarDialog.cpp
Normal file
404
src/musredit_qt5/mupp/PVarDialog.cpp
Normal file
@ -0,0 +1,404 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
|
||||||
|
PVarDialog.cpp
|
||||||
|
|
||||||
|
Author: Andreas Suter
|
||||||
|
e-mail: andreas.suter@psi.ch
|
||||||
|
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2007-2020 by Andreas Suter *
|
||||||
|
* andreas.suter@psi.ch *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QSplitter>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
#include "PVarDialog.h"
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
PShowVarNameDialog::PShowVarNameDialog(PCollInfo &info)
|
||||||
|
{
|
||||||
|
// if fCollName is a path name, extract the fln
|
||||||
|
QString collNameStr(info.fCollName);
|
||||||
|
if (collNameStr.contains("/")) {
|
||||||
|
QStringList tok = collNameStr.split('/', QString::SkipEmptyParts);
|
||||||
|
collNameStr = tok[tok.count()-1];
|
||||||
|
}
|
||||||
|
QLabel *collName = new QLabel(collNameStr);
|
||||||
|
QLabel *numVars = new QLabel(QString("#variables: %1").arg(info.fVarName.count()));
|
||||||
|
QListWidget *list = new QListWidget();
|
||||||
|
for (int i=0; i<info.fVarName.count(); i++) {
|
||||||
|
QListWidgetItem *newItem = new QListWidgetItem;
|
||||||
|
newItem->setText(QString("%1 : %2").arg(i, 2).arg(info.fVarName[i]));
|
||||||
|
list->addItem(newItem);
|
||||||
|
}
|
||||||
|
QPushButton *done = new QPushButton("Done", this);
|
||||||
|
|
||||||
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
||||||
|
vLayout->addWidget(collName);
|
||||||
|
vLayout->addWidget(numVars);
|
||||||
|
vLayout->addWidget(list);
|
||||||
|
vLayout->addWidget(done);
|
||||||
|
|
||||||
|
connect(done, SIGNAL( clicked() ), this, SLOT( accept() ));
|
||||||
|
|
||||||
|
resize(300, 450);
|
||||||
|
setLayout(vLayout);
|
||||||
|
setModal(false);
|
||||||
|
setWindowTitle("Variable Names");
|
||||||
|
|
||||||
|
QString iconName("");
|
||||||
|
if (true) // <-- NEEDS TO BE PROPERLY IMPLEMENTED
|
||||||
|
iconName = QString(":/icons/varEdit-dark.svg");
|
||||||
|
else
|
||||||
|
iconName = QString(":/icons/varEdit-plain.svg");
|
||||||
|
setWindowIcon( QIcon( QPixmap(iconName) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
PVarDialog::PVarDialog(QVector<PCollInfo> collection_list, bool darkTheme,
|
||||||
|
QWidget *parent, Qt::WindowFlags f) :
|
||||||
|
QDialog(parent, f), fCollList(collection_list)
|
||||||
|
{
|
||||||
|
fVarEdit = new QPlainTextEdit();
|
||||||
|
fCollectionView = new QListWidget();
|
||||||
|
fCancel = new QPushButton("&Cancel", this);
|
||||||
|
fCheck = new QPushButton("Chec&k", this);
|
||||||
|
fAdd = new QPushButton("&Add", this);
|
||||||
|
fHelp = new QPushButton("&Help", this);
|
||||||
|
fShowVarName = new QPushButton("Show&VarName", this);
|
||||||
|
|
||||||
|
// fill collection view
|
||||||
|
for (int i=0; i<fCollList.count(); i++) {
|
||||||
|
QListWidgetItem *newItem = new QListWidgetItem;
|
||||||
|
newItem->setText(fCollList[i].fCollName);
|
||||||
|
fCollectionView->addItem(newItem);
|
||||||
|
}
|
||||||
|
fCollectionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
|
||||||
|
QHBoxLayout *hLayout0 = new QHBoxLayout;
|
||||||
|
hLayout0->addWidget(fShowVarName);
|
||||||
|
hLayout0->addWidget(fHelp);
|
||||||
|
|
||||||
|
QHBoxLayout *hLayout1 = new QHBoxLayout;
|
||||||
|
hLayout1->addWidget(fCancel);
|
||||||
|
hLayout1->addWidget(fCheck);
|
||||||
|
hLayout1->addWidget(fAdd);
|
||||||
|
|
||||||
|
QLabel *varLabel = new QLabel("Edit Variables:");
|
||||||
|
QVBoxLayout *varVLayout = new QVBoxLayout;
|
||||||
|
varVLayout->addWidget(varLabel);
|
||||||
|
varVLayout->addWidget(fVarEdit);
|
||||||
|
|
||||||
|
QLabel *collLabel = new QLabel("Collections:");
|
||||||
|
QVBoxLayout *collVLayout = new QVBoxLayout;
|
||||||
|
collVLayout->addWidget(collLabel);
|
||||||
|
collVLayout->addWidget(fCollectionView);
|
||||||
|
|
||||||
|
QWidget *varWidget = new QWidget(this); // only needed since splitter needs a QWidget
|
||||||
|
varWidget->setLayout(varVLayout);
|
||||||
|
QWidget *collWidget = new QWidget(this); // only needed since splitter needs a QWidget
|
||||||
|
collWidget->setLayout(collVLayout);
|
||||||
|
|
||||||
|
QSplitter *splitter = new QSplitter(Qt::Vertical, this);
|
||||||
|
splitter->addWidget(varWidget);
|
||||||
|
splitter->addWidget(collWidget);
|
||||||
|
|
||||||
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
||||||
|
vLayout->addWidget(splitter);
|
||||||
|
vLayout->addLayout(hLayout0);
|
||||||
|
vLayout->addLayout(hLayout1);
|
||||||
|
|
||||||
|
fVarEdit->resize(600, 300);
|
||||||
|
setLayout(vLayout);
|
||||||
|
resize(600, 450);
|
||||||
|
|
||||||
|
connect(fCancel, SIGNAL( clicked() ), this, SLOT( reject() ));
|
||||||
|
connect(fCheck, SIGNAL( clicked() ), this, SLOT( check() ));
|
||||||
|
connect(fAdd, SIGNAL( clicked() ), this, SLOT( add() ));
|
||||||
|
connect(fHelp, SIGNAL( clicked() ), this, SLOT( help() ));
|
||||||
|
connect(fShowVarName, SIGNAL( clicked() ), this, SLOT( showVarNames() ));
|
||||||
|
|
||||||
|
QString iconName("");
|
||||||
|
if (darkTheme)
|
||||||
|
iconName = QString(":/icons/varEdit-dark.svg");
|
||||||
|
else
|
||||||
|
iconName = QString(":/icons/varEdit-plain.svg");
|
||||||
|
setWindowIcon( QIcon( QPixmap(iconName) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
void PVarDialog::check()
|
||||||
|
{
|
||||||
|
if (!basic_check())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!var_consistency_check())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// create the collection index vector
|
||||||
|
QVector<int> idx;
|
||||||
|
QList<QListWidgetItem *> selected = fCollectionView->selectedItems();
|
||||||
|
for (int i=0; i<selected.count(); i++) {
|
||||||
|
idx.push_back(fCollectionView->row(selected[i]));
|
||||||
|
}
|
||||||
|
emit check_request(fVarEdit->toPlainText(), idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
void PVarDialog::add()
|
||||||
|
{
|
||||||
|
if (fVarEdit->toPlainText().isEmpty()) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "No input available.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fCollectionView->selectedItems().count() == 0) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "One or more collection(s) need to linked to the variable(s).");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!basic_check())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!var_consistency_check())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// create the collection index vector
|
||||||
|
QVector<int> idx;
|
||||||
|
QList<QListWidgetItem *> selected = fCollectionView->selectedItems();
|
||||||
|
for (int i=0; i<selected.count(); i++) {
|
||||||
|
idx.push_back(fCollectionView->row(selected[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
emit check_request(fVarEdit->toPlainText(), idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
void PVarDialog::help()
|
||||||
|
{
|
||||||
|
QMessageBox::information(this, "Var Help", "Syntax: var <var_name> = <expr>.\n<expr> can contain identifiers defined in the collections.\nExample:\nvar sigSC = pow(abs(pow($sigma,2.0)-pow(0.11,2.0)),0.5)");
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
void PVarDialog::showVarNames()
|
||||||
|
{
|
||||||
|
// get the selected collection
|
||||||
|
if (fCollectionView->selectedItems().count() == 0) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "At least one collection needs to be selected.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fCollectionView->selectedItems().count() > 1) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "Currently only the vars of a single collection can be shown.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int idx = fCollectionView->currentRow();
|
||||||
|
|
||||||
|
if (idx >= fCollList.count()) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", QString("Collection idx=%1 > #Collections=%2. This never should have happened.").arg(idx).arg(fCollList.count()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PCollInfo info = fCollList[idx];
|
||||||
|
|
||||||
|
PShowVarNameDialog *dialog = new PShowVarNameDialog(info);
|
||||||
|
dialog->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
bool PVarDialog::basic_check()
|
||||||
|
{
|
||||||
|
QString varStr = fVarEdit->toPlainText();
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (varStr.isEmpty()) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "No input available.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (fCollectionView->selectedItems().count() == 0) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "One or more collection(s) need to linked to the variable(s).");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tokenize variable input
|
||||||
|
QStringList strList = varStr.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
|
||||||
|
|
||||||
|
// check if there are ANY var definitions
|
||||||
|
ok = false;
|
||||||
|
for (int i=0; i<strList.count(); i++) {
|
||||||
|
if (strList[i] == "var") {
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "<b>NO</b> 'var' definition found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that for each variable, there is also an Err variable present
|
||||||
|
QStringList varNames = collectVarNames(strList, ok);
|
||||||
|
if (!ok) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", "found 'var' without <var_name>.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QString name("");
|
||||||
|
if (!hasErrorDef(varNames, name)) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", QString("found <var_name>=%1 without corresponding %1Err.<br>Both, a variable <b>and</b> its corresponding error variable needs to be defined.").arg(name));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
bool PVarDialog::var_consistency_check()
|
||||||
|
{
|
||||||
|
QString varStr = fVarEdit->toPlainText();
|
||||||
|
|
||||||
|
// collect all identifiers
|
||||||
|
int idx = 0, idxEnd = 0;
|
||||||
|
QStringList varNames;
|
||||||
|
QVector<int> isIdendifier;
|
||||||
|
char ch;
|
||||||
|
bool done;
|
||||||
|
do {
|
||||||
|
idx = varStr.indexOf("$", idx);
|
||||||
|
if (idx > -1) { // found identifier
|
||||||
|
idxEnd = idx+1;
|
||||||
|
done = false;
|
||||||
|
do {
|
||||||
|
ch = varStr[idxEnd].toLatin1();
|
||||||
|
if (isalnum(ch) || (ch == '_'))
|
||||||
|
idxEnd++;
|
||||||
|
else
|
||||||
|
done = true;
|
||||||
|
} while (!done && (idxEnd <= varStr.length()));
|
||||||
|
varNames << varStr.mid(idx+1, idxEnd-idx-1);
|
||||||
|
isIdendifier.push_back(1);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
} while (idx != -1);
|
||||||
|
|
||||||
|
// collect all the variable names
|
||||||
|
idx = 0;
|
||||||
|
do {
|
||||||
|
idx = varStr.indexOf("var ", idx);
|
||||||
|
if (idx > -1) { // found variable
|
||||||
|
idxEnd = varStr.indexOf("=", idx);
|
||||||
|
if (idxEnd == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
varNames << varStr.mid(idx+4, idxEnd-idx-5);
|
||||||
|
isIdendifier.push_back(0);
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
} while (idx != -1);
|
||||||
|
|
||||||
|
// make sure that identifier is found in collection if it is not a variable
|
||||||
|
bool isVar = false;
|
||||||
|
bool found = false;
|
||||||
|
QString str;
|
||||||
|
QList<QListWidgetItem *> selColl = fCollectionView->selectedItems();
|
||||||
|
for (int i=0; i<varNames.count(); i++) {
|
||||||
|
if (isIdendifier[i] == 0) // it is a variable, hence nothing to be done
|
||||||
|
continue;
|
||||||
|
str = varNames[i];
|
||||||
|
if (str.endsWith("Err")) {
|
||||||
|
str = str.left(str.indexOf("Err"));
|
||||||
|
}
|
||||||
|
isVar = false;
|
||||||
|
for (int j=i+1; j<varNames.count(); j++) {
|
||||||
|
if ((varNames[j] == str) && isIdendifier[j] == 0) {
|
||||||
|
isVar = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isVar)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int j=0; j<selColl.count(); j++) {
|
||||||
|
idx = fCollectionView->row(selColl[j]);
|
||||||
|
found = false;
|
||||||
|
for (int k=0; k<fCollList[idx].fVarName.count(); k++) {
|
||||||
|
if (str == fCollList[idx].fVarName[k]) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
QMessageBox::critical(this, "**ERROR**", QString("Identifier '%1' not present in selected collection '%2'").arg(str).arg(fCollList[idx].fCollName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
QStringList PVarDialog::collectVarNames(QStringList &list, bool &ok)
|
||||||
|
{
|
||||||
|
QStringList name;
|
||||||
|
|
||||||
|
ok = true;
|
||||||
|
for (int i=0; i<list.count(); i++) {
|
||||||
|
if (list[i] == "var") {
|
||||||
|
if (i+1 >= list.count()) {
|
||||||
|
ok = false;
|
||||||
|
} else {
|
||||||
|
name << list[i+1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
bool PVarDialog::hasErrorDef(QStringList &varNames, QString &name)
|
||||||
|
{
|
||||||
|
QString errStr;
|
||||||
|
for (int i=0; i<varNames.count(); i++) {
|
||||||
|
if (!varNames[i].contains("Err", Qt::CaseSensitive)) { // not an error variable
|
||||||
|
errStr = varNames[i] + "Err";
|
||||||
|
bool ok = false;
|
||||||
|
for (int j=0; j<varNames.count(); j++) {
|
||||||
|
if (varNames[j] == errStr) {
|
||||||
|
ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
name = varNames[i];
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
|
|
||||||
PGetNormValDialog.cpp
|
PVarDialog.h
|
||||||
|
|
||||||
Author: Andreas Suter
|
Author: Andreas Suter
|
||||||
e-mail: andreas.suter@psi.ch
|
e-mail: andreas.suter@psi.ch
|
||||||
@ -27,49 +27,66 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#ifndef _PVARDIALOG_H_
|
||||||
#include <QHBoxLayout>
|
#define _PVARDIALOG_H_
|
||||||
#include <QLabel>
|
|
||||||
#include <QLineEdit>
|
#include <QDialog>
|
||||||
#include <QDoubleValidator>
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QPlainTextEdit>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
#include "PGetNormValDialog.h"
|
//-----------------------------------------------------------------------------
|
||||||
|
struct PCollInfo
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
PGetNormValDialog::PGetNormValDialog(double dval, QWidget *parent, Qt::WindowFlags f) :
|
|
||||||
QDialog(parent, f), fValue(dval)
|
|
||||||
{
|
{
|
||||||
QVBoxLayout *vbox = new QVBoxLayout;
|
QString fCollName;
|
||||||
QHBoxLayout *hbox1 = new QHBoxLayout;
|
QStringList fVarName;
|
||||||
QHBoxLayout *hbox2 = new QHBoxLayout;
|
};
|
||||||
|
|
||||||
vbox->addLayout(hbox1);
|
//-----------------------------------------------------------------------------
|
||||||
vbox->addLayout(hbox2);
|
class PShowVarNameDialog : public QDialog
|
||||||
|
|
||||||
QLabel *lab = new QLabel("Norm Value: ");
|
|
||||||
QLineEdit *fEdit = new QLineEdit();
|
|
||||||
fEdit->setValidator(new QDoubleValidator());
|
|
||||||
fEdit->setText(QString("%1").arg(fValue));
|
|
||||||
hbox1->addWidget(lab);
|
|
||||||
hbox1->addWidget(fEdit);
|
|
||||||
|
|
||||||
QPushButton *ok = new QPushButton("OK");
|
|
||||||
QPushButton *cancel = new QPushButton("Cancel");
|
|
||||||
hbox2->addWidget(ok);
|
|
||||||
hbox2->addWidget(cancel);
|
|
||||||
|
|
||||||
setModal(true);
|
|
||||||
|
|
||||||
setLayout(vbox);
|
|
||||||
|
|
||||||
connect( fEdit, SIGNAL(textChanged(const QString&)), this, SLOT(gotValue(const QString&)));
|
|
||||||
connect( ok, SIGNAL(clicked()), this, SLOT(accept()));
|
|
||||||
connect( cancel, SIGNAL(clicked()), this, SLOT(reject()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
void PGetNormValDialog::gotValue(const QString& str)
|
|
||||||
{
|
{
|
||||||
fValue = str.toDouble();
|
Q_OBJECT
|
||||||
}
|
|
||||||
|
public:
|
||||||
|
PShowVarNameDialog(PCollInfo &info);
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
class PVarDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
PVarDialog(QVector<PCollInfo> collection_list, bool darkTheme,
|
||||||
|
QWidget *parent = nullptr,
|
||||||
|
Qt::WindowFlags f = Qt::WindowFlags());
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPlainTextEdit *fVarEdit;
|
||||||
|
QListWidget *fCollectionView;
|
||||||
|
QPushButton *fCancel;
|
||||||
|
QPushButton *fAdd;
|
||||||
|
QPushButton *fCheck;
|
||||||
|
QPushButton *fHelp;
|
||||||
|
QPushButton *fShowVarName;
|
||||||
|
|
||||||
|
QVector<PCollInfo> fCollList;
|
||||||
|
|
||||||
|
bool basic_check();
|
||||||
|
bool var_consistency_check();
|
||||||
|
QStringList collectVarNames(QStringList &list, bool& ok);
|
||||||
|
bool hasErrorDef(QStringList &varNames, QString& name);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void check();
|
||||||
|
void add();
|
||||||
|
void help();
|
||||||
|
void showVarNames();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void check_request(QString varStr, QVector<int> idx);
|
||||||
|
void add_request(QString varStr, QVector<int> idx);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _PVARDIALOG_H_
|
@ -59,7 +59,6 @@
|
|||||||
|
|
||||||
#include "mupp_version.h"
|
#include "mupp_version.h"
|
||||||
#include "PmuppGui.h"
|
#include "PmuppGui.h"
|
||||||
#include "PGetNormValDialog.h"
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
@ -211,7 +210,8 @@ PmuppGui::PmuppGui( QStringList fln, QWidget *parent, Qt::WindowFlags f )
|
|||||||
fNormalizeAction = nullptr;
|
fNormalizeAction = nullptr;
|
||||||
|
|
||||||
fNormalize = false;
|
fNormalize = false;
|
||||||
fNormVal = 0.0;
|
|
||||||
|
fVarDlg = nullptr;
|
||||||
|
|
||||||
fMacroPath = QString("./");
|
fMacroPath = QString("./");
|
||||||
fMacroName = QString("");
|
fMacroName = QString("");
|
||||||
@ -549,16 +549,25 @@ void PmuppGui::setupToolActions()
|
|||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
|
a = new QAction(tr( "Add Variable" ), this );
|
||||||
|
a->setStatusTip( tr("Calls a dialog which allows to add variables which are expressions of db/dat vars.") );
|
||||||
|
connect( a, SIGNAL( triggered() ), this, SLOT( addVar() ));
|
||||||
|
menu->addAction(a);
|
||||||
|
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
fNormalizeAction = new QAction(tr( "Normalize" ), this);
|
fNormalizeAction = new QAction(tr( "Normalize" ), this);
|
||||||
fNormalizeAction->setStatusTip( tr("Plot Data Normalized (y-axis)") );
|
fNormalizeAction->setStatusTip( tr("Plot Data Normalized (y-axis)") );
|
||||||
fNormalizeAction->setCheckable(true);
|
fNormalizeAction->setCheckable(true);
|
||||||
connect( fNormalizeAction, SIGNAL( changed() ), this, SLOT( normalize() ) );
|
connect( fNormalizeAction, SIGNAL( changed() ), this, SLOT( normalize() ) );
|
||||||
menu->addAction(fNormalizeAction);
|
menu->addAction(fNormalizeAction);
|
||||||
|
|
||||||
|
/* //as35 - eventually also remove PGetNormValDialog.* from the source
|
||||||
a = new QAction(tr( "Normalize by Value" ), this);
|
a = new QAction(tr( "Normalize by Value" ), this);
|
||||||
a->setStatusTip( tr("Normalize by Value") );
|
a->setStatusTip( tr("Normalize by Value") );
|
||||||
connect( a, SIGNAL( triggered() ), this, SLOT( normVal() ) );
|
connect( a, SIGNAL( triggered() ), this, SLOT( normVal() ) );
|
||||||
menu->addAction(a);
|
menu->addAction(a);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -705,27 +714,6 @@ void PmuppGui::normalize()
|
|||||||
fNormalize = fNormalizeAction->isChecked();
|
fNormalize = fNormalizeAction->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
|
||||||
void PmuppGui::normVal()
|
|
||||||
{
|
|
||||||
PGetNormValDialog *dlg = new PGetNormValDialog(fNormVal);
|
|
||||||
if (dlg == nullptr) {
|
|
||||||
QMessageBox::critical(this, "**ERROR**", "Couldn't invoke dialog, sorry :-(", QMessageBox::Ok, QMessageBox::NoButton);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dlg->exec();
|
|
||||||
|
|
||||||
if (dlg->result() != QDialog::Accepted) {
|
|
||||||
delete dlg;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fNormVal = dlg->getValue();
|
|
||||||
|
|
||||||
delete dlg;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief PmuppGui::helpCmds
|
* @brief PmuppGui::helpCmds
|
||||||
@ -733,6 +721,7 @@ void PmuppGui::normVal()
|
|||||||
void PmuppGui::helpCmds()
|
void PmuppGui::helpCmds()
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, "cmd help", "<b>help:</b> this help.<br>"\
|
QMessageBox::information(this, "cmd help", "<b>help:</b> this help.<br>"\
|
||||||
|
"<b>add var</b>: allows to add a variable which is formula of collection vars.<br>"\
|
||||||
"<b>ditto</b>: addX/Y for the new selection as for the previous ones.<br>"\
|
"<b>ditto</b>: addX/Y for the new selection as for the previous ones.<br>"\
|
||||||
"<b>dump collections:</b> dumps all currently loaded collections.<br>"\
|
"<b>dump collections:</b> dumps all currently loaded collections.<br>"\
|
||||||
"<b>dump XY:</b> dumps X/Y tree.<br>"\
|
"<b>dump XY:</b> dumps X/Y tree.<br>"\
|
||||||
@ -1244,6 +1233,76 @@ void PmuppGui::addDitto()
|
|||||||
fColList->clearSelection();
|
fColList->clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void PmuppGui::addVar()
|
||||||
|
{
|
||||||
|
// create collection list
|
||||||
|
QVector<PCollInfo> collection_list;
|
||||||
|
|
||||||
|
// go through all available collections and obtain the needed information
|
||||||
|
PCollInfo collInfo;
|
||||||
|
for (int i=0; i<fParamDataHandler->GetNoOfCollections(); i++) {
|
||||||
|
// get collection name
|
||||||
|
collInfo.fCollName = fParamDataHandler->GetCollectionName(i);
|
||||||
|
// get variable names
|
||||||
|
for (int j=0; j<fParamDataHandler->GetCollection(i)->GetRun(0).GetNoOfParam(); j++) {
|
||||||
|
collInfo.fVarName << fParamDataHandler->GetCollection(i)->GetRun(0).GetParam(j).GetName();
|
||||||
|
}
|
||||||
|
collection_list.push_back(collInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// call variable dialog
|
||||||
|
if (fVarDlg == nullptr) {
|
||||||
|
fVarDlg = new PVarDialog(collection_list, fDarkTheme);
|
||||||
|
connect(fVarDlg, SIGNAL(check_request(QString,QVector<int>)), this, SLOT(check(QString,QVector<int>)));
|
||||||
|
connect(fVarDlg, SIGNAL(add_request(QString,QVector<int>)), this, SLOT(add(QString,QVector<int>)));
|
||||||
|
}
|
||||||
|
fVarDlg->show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void PmuppGui::check(QString varStr, QVector<int> idx)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (int i=0; i<idx.size(); i++) {
|
||||||
|
PVarHandler var_check(fParamDataHandler->GetCollection(i), varStr.toLatin1().data());
|
||||||
|
if (var_check.isValid()) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
// get error messages
|
||||||
|
QString mupp_err = QString("%1/.musrfit/mupp/mupp_err.log").arg(QString(qgetenv("HOME")));
|
||||||
|
QFile fin(mupp_err);
|
||||||
|
QString errStr("");
|
||||||
|
if (fin.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QTextStream in(&fin);
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
errStr += in.readLine();
|
||||||
|
errStr += "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fin.close();
|
||||||
|
QFile::remove(mupp_err);
|
||||||
|
|
||||||
|
if (errStr.isEmpty())
|
||||||
|
errStr = "unknown error - should never happen.";
|
||||||
|
QString msg = QString("Parse error(s):\n");
|
||||||
|
msg += errStr;
|
||||||
|
QMessageBox::critical(this, "**ERROR**", msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == idx.size()) {
|
||||||
|
QMessageBox::information(this, "**INFO**", "Parsing successful.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void PmuppGui::add(QString varStr, QVector<int> idx)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief PmuppGui::findValue
|
* @brief PmuppGui::findValue
|
||||||
@ -1765,13 +1824,9 @@ void PmuppGui::plot()
|
|||||||
double max=0.0;
|
double max=0.0;
|
||||||
for (int k=0; k<yyy.size(); k++) {
|
for (int k=0; k<yyy.size(); k++) {
|
||||||
max=0.0;
|
max=0.0;
|
||||||
if (fNormVal == 0.0) {
|
for (int j=0; j<xx.size(); j++) {
|
||||||
for (int j=0; j<xx.size(); j++) {
|
if (yyy[k][j] > max)
|
||||||
if (yyy[k][j] > max)
|
max = yyy[k][j];
|
||||||
max = yyy[k][j];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
max = fNormVal;
|
|
||||||
}
|
}
|
||||||
for (int j=0; j<xx.size(); j++) {
|
for (int j=0; j<xx.size(); j++) {
|
||||||
yyy[k][j] /= max;
|
yyy[k][j] /= max;
|
||||||
@ -1998,6 +2053,8 @@ void PmuppGui::handleCmds()
|
|||||||
QMessageBox::critical(this, "**ERROR**", "found wrong norm cmd, will ignore it.");
|
QMessageBox::critical(this, "**ERROR**", "found wrong norm cmd, will ignore it.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (cmd.startsWith("add var")) {
|
||||||
|
addVar();
|
||||||
} else if (cmd.startsWith("flush")) {
|
} else if (cmd.startsWith("flush")) {
|
||||||
fCmdHistory.clear();
|
fCmdHistory.clear();
|
||||||
fCmdLine->setText("$ ");
|
fCmdLine->setText("$ ");
|
||||||
@ -2190,48 +2247,32 @@ QString PmuppGui::substituteDefaultLabels(QString label)
|
|||||||
result =QString("E (keV)");
|
result =QString("E (keV)");
|
||||||
} else if (!label.compare("sigma", Qt::CaseInsensitive)) {
|
} else if (!label.compare("sigma", Qt::CaseInsensitive)) {
|
||||||
if (fNormalize) {
|
if (fNormalize) {
|
||||||
if (fNormVal == 0.0)
|
result = QString("#sigma/max(#sigma)");
|
||||||
result = QString("#sigma/max(#sigma)");
|
|
||||||
else
|
|
||||||
result = QString("#sigma/%1 (1/#mus)").arg(fNormVal);
|
|
||||||
} else {
|
} else {
|
||||||
result = QString("#sigma (1/#mus)");
|
result = QString("#sigma (1/#mus)");
|
||||||
}
|
}
|
||||||
} else if (!label.compare("lambda", Qt::CaseInsensitive)) {
|
} else if (!label.compare("lambda", Qt::CaseInsensitive)) {
|
||||||
if (fNormalize) {
|
if (fNormalize) {
|
||||||
if (fNormVal == 0.0)
|
result = QString("#lambda/max(#lambda)");
|
||||||
result = QString("#lambda/max(#lambda)");
|
|
||||||
else
|
|
||||||
result = QString("#lambda/%1 (1/#mus)").arg(fNormVal);
|
|
||||||
} else {
|
} else {
|
||||||
result = QString("#lambda (1/#mus)");
|
result = QString("#lambda (1/#mus)");
|
||||||
}
|
}
|
||||||
} else if (!label.compare("alpha_LR", Qt::CaseInsensitive)) {
|
} else if (!label.compare("alpha_LR", Qt::CaseInsensitive)) {
|
||||||
if (fNormalize) {
|
if (fNormalize) {
|
||||||
if (fNormVal == 0.0)
|
result = QString("#alpha_{LR}/max(#alpha_{LR})");
|
||||||
result = QString("#alpha_{LR}/max(#alpha_{LR})");
|
|
||||||
else
|
|
||||||
result = QString("#alpha_{LR}/%1").arg(fNormVal);
|
|
||||||
} else {
|
} else {
|
||||||
result = QString("#alpha_{LR}");
|
result = QString("#alpha_{LR}");
|
||||||
}
|
}
|
||||||
} else if (!label.compare("alpha_TB", Qt::CaseInsensitive)) {
|
} else if (!label.compare("alpha_TB", Qt::CaseInsensitive)) {
|
||||||
if (fNormalize) {
|
if (fNormalize) {
|
||||||
if (fNormVal == 0.0)
|
result = QString("#alpha_{TB}/max(#alpha_{TB})");
|
||||||
result = QString("#alpha_{TB}/max(#alpha_{TB})");
|
|
||||||
else
|
|
||||||
result = QString("#alpha_{TB}/%1").arg(fNormVal);
|
|
||||||
} else {
|
} else {
|
||||||
result = QString("#alpha_{TB}");
|
result = QString("#alpha_{TB}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fNormalize) {
|
if (fNormalize) {
|
||||||
if (fNormVal == 0.0) {
|
result = QString("Normalized ");
|
||||||
result = QString("Normalized ");
|
result += label;
|
||||||
result += label;
|
|
||||||
} else {
|
|
||||||
result = QString("%1/%2").arg(label).arg(fNormVal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,13 @@
|
|||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
#include "PVarHandler.h"
|
||||||
|
#include "PVarDialog.h"
|
||||||
#include "PmuppAdmin.h"
|
#include "PmuppAdmin.h"
|
||||||
#include "Pmupp.h"
|
#include "Pmupp.h"
|
||||||
#include "mupp.h"
|
#include "mupp.h"
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
class PmuppXY
|
class PmuppXY
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -78,7 +80,7 @@ private:
|
|||||||
void init();
|
void init();
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Layout Scheme of PmuppGui:
|
// Layout Scheme of PmuppGui:
|
||||||
// |--------------------------------------------------------------------|
|
// |--------------------------------------------------------------------|
|
||||||
// | Main |
|
// | Main |
|
||||||
@ -96,9 +98,11 @@ private:
|
|||||||
// | |----------------------------------------------------------------| |
|
// | |----------------------------------------------------------------| |
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Grid Left contains: fColLabel, fColParamSplitter, fRemoveCollection, fRefreshCollection
|
// Grid Left contains: fColLabel, fColParamSplitter,
|
||||||
// Grid Right contains: f(X,Y)axisLabel, fView(X,Y), fAdd(X,Y), fRemove(X,Y), fAddDitto, fPlot
|
// fRemoveCollection, fRefreshCollection
|
||||||
//----------------------------------------------------------------------------------------------
|
// Grid Right contains: f(X,Y)axisLabel, fView(X,Y), fAdd(X,Y), fRemove(X,Y),
|
||||||
|
// fAddDitto, fPlot
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
class PmuppGui : public QMainWindow
|
class PmuppGui : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -115,8 +119,8 @@ public slots:
|
|||||||
|
|
||||||
void toolDumpCollections();
|
void toolDumpCollections();
|
||||||
void toolDumpXY();
|
void toolDumpXY();
|
||||||
|
void addVar();
|
||||||
void normalize();
|
void normalize();
|
||||||
void normVal();
|
|
||||||
|
|
||||||
void helpCmds();
|
void helpCmds();
|
||||||
void helpAbout();
|
void helpAbout();
|
||||||
@ -132,13 +136,13 @@ private:
|
|||||||
bool fDarkTheme;
|
bool fDarkTheme;
|
||||||
bool fDarkToolBarIcon;
|
bool fDarkToolBarIcon;
|
||||||
bool fNormalize;
|
bool fNormalize;
|
||||||
double fNormVal;
|
|
||||||
|
|
||||||
uint fDatime;
|
uint fDatime;
|
||||||
uint fMuppInstance;
|
uint fMuppInstance;
|
||||||
|
|
||||||
PParamDataHandler *fParamDataHandler;
|
PParamDataHandler *fParamDataHandler;
|
||||||
QVector<PmuppXY> fXY;
|
QVector<PmuppXY> fXY;
|
||||||
|
QVector<PVarHandler> fVarHandler;
|
||||||
|
|
||||||
QString fMacroPath;
|
QString fMacroPath;
|
||||||
QString fMacroName;
|
QString fMacroName;
|
||||||
@ -178,6 +182,8 @@ private:
|
|||||||
|
|
||||||
QVector<QString> fCmdHistory;
|
QVector<QString> fCmdHistory;
|
||||||
|
|
||||||
|
PVarDialog *fVarDlg;
|
||||||
|
|
||||||
QProcess *fMuppPlot;
|
QProcess *fMuppPlot;
|
||||||
|
|
||||||
void setupFileActions();
|
void setupFileActions();
|
||||||
@ -198,34 +204,37 @@ private:
|
|||||||
void selectCollection(QString cmd);
|
void selectCollection(QString cmd);
|
||||||
uint getFirstAvailableMuppInstance();
|
uint getFirstAvailableMuppInstance();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void refresh();
|
|
||||||
void remove();
|
|
||||||
void addX(QString param="");
|
|
||||||
void addY(QString param="");
|
|
||||||
void removeX(QString param="");
|
|
||||||
void removeY(QString param="");
|
|
||||||
void addDitto();
|
|
||||||
void createMacro();
|
|
||||||
void plot();
|
|
||||||
void handleCmds();
|
|
||||||
|
|
||||||
void handleNewData();
|
|
||||||
void updateCollectionList();
|
void updateCollectionList();
|
||||||
void updateParamList(int currentRow);
|
|
||||||
void updateXYList(int idx);
|
void updateXYList(int idx);
|
||||||
void updateXYListGui();
|
void updateXYListGui();
|
||||||
void editCollName(QListWidgetItem *item);
|
|
||||||
void dropOnViewX(QListWidgetItem *item);
|
|
||||||
void dropOnViewY(QListWidgetItem *item);
|
|
||||||
void refreshY();
|
|
||||||
|
|
||||||
bool findValue(PmuppRun &run, EAxis tag);
|
bool findValue(PmuppRun &run, EAxis tag);
|
||||||
bool allXYEqual();
|
bool allXYEqual();
|
||||||
bool indexAlreadyPresent(int idx);
|
bool indexAlreadyPresent(int idx);
|
||||||
void replaceIndex(PmuppXY &data, const int idx);
|
void replaceIndex(PmuppXY &data, const int idx);
|
||||||
|
|
||||||
void startMuppPlot();
|
void startMuppPlot();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void addDitto();
|
||||||
|
void addX(QString param="");
|
||||||
|
void addY(QString param="");
|
||||||
|
void createMacro();
|
||||||
|
void handleCmds();
|
||||||
|
void plot();
|
||||||
|
void refresh();
|
||||||
|
void remove();
|
||||||
|
void removeX(QString param="");
|
||||||
|
void removeY(QString param="");
|
||||||
|
|
||||||
|
void handleNewData();
|
||||||
|
void updateParamList(int currentRow);
|
||||||
|
void editCollName(QListWidgetItem *item);
|
||||||
|
void dropOnViewX(QListWidgetItem *item);
|
||||||
|
void dropOnViewY(QListWidgetItem *item);
|
||||||
|
void refreshY();
|
||||||
|
|
||||||
|
void check(QString varStr, QVector<int> idx);
|
||||||
|
void add(QString varStr, QVector<int> idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PMUPPGUI_H_
|
#endif // _PMUPPGUI_H_
|
||||||
|
@ -807,8 +807,23 @@ int PmuppScript::var_cmd(const QString str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PVarHandler varHandler(fParamDataHandler->GetCollection(idx), parse_str, tok[1].toLatin1().data());
|
PVarHandler varHandler(fParamDataHandler->GetCollection(idx), parse_str, tok[1].toLatin1().data());
|
||||||
if (!varHandler.isValid())
|
if (!varHandler.isValid()) {
|
||||||
|
// deal with errors
|
||||||
|
QString mupp_err = QString("%1/.musrfit/mupp/mupp_err.log").arg(QString(qgetenv("HOME")));
|
||||||
|
|
||||||
|
// dump error messages if present
|
||||||
|
QFile fout(mupp_err);
|
||||||
|
if (fout.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QString msg;
|
||||||
|
while (!fout.atEnd()) {
|
||||||
|
msg = fout.readLine();
|
||||||
|
std::cerr << msg.toLatin1().data();
|
||||||
|
}
|
||||||
|
// delete potentially present mupp_err.log file
|
||||||
|
QFile::remove(mupp_err);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
fVarHandler.push_back(varHandler);
|
fVarHandler.push_back(varHandler);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
<file>icons/mupp-dark.svg</file>
|
<file>icons/mupp-dark.svg</file>
|
||||||
<file>icons/document-open-plain.svg</file>
|
<file>icons/document-open-plain.svg</file>
|
||||||
<file>icons/document-open-dark.svg</file>
|
<file>icons/document-open-dark.svg</file>
|
||||||
|
<file>icons/varEdit-plain.svg</file>
|
||||||
|
<file>icons/varEdit-dark.svg</file>
|
||||||
<file>icons/mupp.icns</file>
|
<file>icons/mupp.icns</file>
|
||||||
<file>mupp_startup.xml.in</file>
|
<file>mupp_startup.xml.in</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#define _PERROR_HANDLER_HPP_
|
#define _PERROR_HANDLER_HPP_
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -59,15 +60,19 @@ namespace mupp
|
|||||||
{
|
{
|
||||||
int line;
|
int line;
|
||||||
Iterator line_start = get_pos(err_pos, line);
|
Iterator line_start = get_pos(err_pos, line);
|
||||||
|
const char *homeStr = getenv("HOME");
|
||||||
|
char fln[1024];
|
||||||
|
sprintf(fln, "%s/.musrfit/mupp/mupp_err.log", homeStr);
|
||||||
|
std::ofstream fout(fln, std::ofstream::app);
|
||||||
if (err_pos != last) {
|
if (err_pos != last) {
|
||||||
std::cout << message << what << ':' << std::endl;
|
fout << message << what << ':' << std::endl;
|
||||||
std::cout << get_line(line_start) << std::endl;
|
fout << get_line(line_start) << std::endl;
|
||||||
for (; line_start != err_pos; ++line_start)
|
for (; line_start != err_pos; ++line_start)
|
||||||
std::cout << ' ';
|
fout << ' ';
|
||||||
std::cout << "^~~" << std::endl;
|
fout << "^~~" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "**ERROR** Unexpected end of file. ";
|
fout << "**ERROR** Unexpected end of file. ";
|
||||||
std::cout << message << what << " line " << line << std::endl;
|
fout << message << what << " line " << line << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,15 +42,16 @@
|
|||||||
class PVarHandler {
|
class PVarHandler {
|
||||||
public:
|
public:
|
||||||
PVarHandler();
|
PVarHandler();
|
||||||
PVarHandler(PmuppCollection *coll, std::string parse_str, std::string var_name);
|
PVarHandler(PmuppCollection *coll, std::string parse_str, std::string var_name="");
|
||||||
|
|
||||||
bool isValid() { return fIsValid; }
|
bool isValid() { return fIsValid; }
|
||||||
|
QString getCollName() { return fColl->GetName(); }
|
||||||
QString getVarName() { return QString(fVarName.c_str()); }
|
QString getVarName() { return QString(fVarName.c_str()); }
|
||||||
std::vector<double> getValues();
|
std::vector<double> getValues();
|
||||||
std::vector<double> getErrors();
|
std::vector<double> getErrors();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PmuppCollection *fColl; ///< collection need for parsing and evaluation
|
PmuppCollection *fColl; ///< collection needed for parsing and evaluation
|
||||||
std::string fParseStr; ///< the variable input to be parsed
|
std::string fParseStr; ///< the variable input to be parsed
|
||||||
std::string fVarName; ///< variable name
|
std::string fVarName; ///< variable name
|
||||||
mupp::prog::PVarHandler fVar; ///< values of the evaluation
|
mupp::prog::PVarHandler fVar; ///< values of the evaluation
|
||||||
|
@ -74,15 +74,17 @@ PVarHandler::PVarHandler(PmuppCollection *coll, std::string parse_str, std::stri
|
|||||||
dataErr = getDataErr(i);
|
dataErr = getDataErr(i);
|
||||||
prog.add_predef_var_values(getVarName(i), data, dataErr);
|
prog.add_predef_var_values(getVarName(i), data, dataErr);
|
||||||
}
|
}
|
||||||
mupp::prog::PProgEval eval(prog.getVars()); // setup evaluation stage
|
if (!fVarName.empty()) {
|
||||||
eval(fAst); // evaluate stuff
|
mupp::prog::PProgEval eval(prog.getVars()); // setup evaluation stage
|
||||||
|
eval(fAst); // evaluate stuff
|
||||||
|
|
||||||
// keep data
|
// keep data
|
||||||
bool ok;
|
bool ok;
|
||||||
fVar = eval.getVar(fVarName, ok);
|
fVar = eval.getVar(fVarName, ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
std::cerr << "**ERROR** evalution failed..." << std::endl;
|
std::cerr << "**ERROR** evalution failed..." << std::endl;
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fIsValid = true;
|
fIsValid = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user