diff --git a/src/musrgui/PMlog2DbDialog.cpp b/src/musrgui/PMlog2DbDialog.cpp new file mode 100644 index 00000000..1bb51909 --- /dev/null +++ b/src/musrgui/PMlog2DbDialog.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** + + PMlog2DbDialog.cpp + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + + $Id$ + +*****************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2009 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 +#include +#include +#include +#include + +#include "PMlog2DbDialog.h" + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +PMlog2DbDialog::PMlog2DbDialog(const bool keepMinuit2Output) +{ + fRunTag = -1; + + fFirst_lineEdit->setValidator( new QIntValidator(fFirst_lineEdit) ); + fLast_lineEdit->setValidator( new QIntValidator(fLast_lineEdit) ); + fTemplateRunNumber_lineEdit->setValidator( new QIntValidator(fTemplateRunNumber_lineEdit) ); + + fKeepMinuit2Output_checkBox->setChecked(keepMinuit2Output); +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PMlog2DbDialog::runFirstLastEntered() +{ + fRunTag = 0; + + if (!fRunList_lineEdit->text().isEmpty()) + fRunList_lineEdit->clear(); + if (!fRunListFileName_lineEdit->text().isEmpty()) + fRunListFileName_lineEdit->clear(); +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PMlog2DbDialog::runListEntered() +{ + fRunTag = 1; + + if (!fFirst_lineEdit->text().isEmpty()) + fFirst_lineEdit->clear(); + if (!fLast_lineEdit->text().isEmpty()) + fLast_lineEdit->clear(); + if (!fRunListFileName_lineEdit->text().isEmpty()) + fRunListFileName_lineEdit->clear(); +} + +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +void PMlog2DbDialog::runListFileNameEntered() +{ + fRunTag = 2; + + if (!fFirst_lineEdit->text().isEmpty()) + fFirst_lineEdit->clear(); + if (!fLast_lineEdit->text().isEmpty()) + fLast_lineEdit->clear(); + if (!fRunList_lineEdit->text().isEmpty()) + fRunList_lineEdit->clear(); +} + +//---------------------------------------------------------------------------------------------------- +// END +//---------------------------------------------------------------------------------------------------- diff --git a/src/musrgui/PMlog2DbDialog.h b/src/musrgui/PMlog2DbDialog.h new file mode 100644 index 00000000..6ffadde5 --- /dev/null +++ b/src/musrgui/PMlog2DbDialog.h @@ -0,0 +1,63 @@ +/**************************************************************************** + + PMlog2DbDialog.h + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + + $Id$ + +*****************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2009 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 _PMLOG2DBDIALOG_H_ +#define _PMLOG2DBDIALOG_H_ + +#include "forms/PMlog2DbDialogBase.h" + +class PMlog2DbDialog : public PMlog2DbDialogBase +{ + public: + PMlog2DbDialog(const bool keepMinuit2Output); + + int getRunTag() { return fRunTag; } + QString getFirstRunNo() { return fFirst_lineEdit->text(); } + QString getLastRunNo() { return fLast_lineEdit->text(); } + QString getRunList() { return fRunList_lineEdit->text(); } + QString getRunListFileName() { return fRunListFileName_lineEdit->text(); } + QString getExtension() { return fExtension_lineEdit->text(); } + QString getTemplateRunNo() { return fTemplateRunNumber_lineEdit->text(); } + QString getDbOutputFileName() { return fDbOutputFileName_lineEdit->text(); } + bool getWriteDbHeaderFlag() { return fNoHeader_checkBox->isChecked(); } + bool getSummaryFilePresentFlag() { return fSummaryPresent_checkBox->isChecked(); } + bool getMinuit2OutputFlag() { return fKeepMinuit2Output_checkBox->isChecked(); } + + public slots: + void runFirstLastEntered(); + void runListEntered(); + void runListFileNameEntered(); + + private: + int fRunTag; // -1 = not valid, 0 = first last, 1 = run list, 2 = run list file name +}; + +#endif // _PMLOG2DBDIALOG_H_ diff --git a/src/musrgui/PTextEdit.cpp b/src/musrgui/PTextEdit.cpp index f335297f..584c96ee 100644 --- a/src/musrgui/PTextEdit.cpp +++ b/src/musrgui/PTextEdit.cpp @@ -29,6 +29,9 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include +using namespace std; + #include #include #include @@ -58,6 +61,7 @@ #include "PPrefsDialog.h" #include "PGetDefaultDialog.h" #include "forms/PMusrGuiAbout.h" +#include "PMlog2DbDialog.h" //---------------------------------------------------------------------------------------------------- /** @@ -338,6 +342,40 @@ void PTextEdit::doConnections( PSubTextEdit *e ) connect( e, SIGNAL( textChanged() ), this, SLOT( textChanged() )); } +//---------------------------------------------------------------------------------------------------- +/** + *

+ */ +bool PTextEdit::validRunList(const QString runList) +{ + bool success = true; + + int i = 0; + QString subStr; + bool done = false; + int val; + bool ok; + while (!done) { + subStr = runList.section(' ', i, i); + if (subStr.isEmpty()) { + done = true; + continue; + } + i++; + val = subStr.toInt(&ok); + if (!ok) { + done = true; + success = false; + } + } + + if (i == 0) { // no token found + success = false; + } + + return success; +} + //---------------------------------------------------------------------------------------------------- /** *

@@ -806,9 +844,142 @@ void PTextEdit::musrMlog2Db() if ( !currentEditor() ) return; - QMessageBox::information( this, "musrMlog2Db", - "Will call mlog2db.\n" - "NOT IMPLEMENTED YET :-(" ); + PMlog2DbDialog *dlg = new PMlog2DbDialog(fKeepMinuit2Output); + + if (dlg->exec() == QDialog::Accepted) { + QString first, last; + QString runList; + QString runListFileName; + QFileInfo fi; + QString str; + int i, end; + + // analyze parameters + switch (dlg->getRunTag()) { + case -1: // not valid + QMessageBox::critical(this, "**ERROR**", + "No valid run list input found :-(\nCannot do anything.", + QMessageBox::Ok, QMessageBox::NoButton); + return; + break; + case 0: // first last + first = dlg->getFirstRunNo(); + last = dlg->getLastRunNo(); + if (first.isEmpty() || last.isEmpty()) { + QMessageBox::critical(this, "**ERROR**", + "If you choose the first/last option,\nfirst AND last needs to be provided.", + QMessageBox::Ok, QMessageBox::NoButton); + return; + } + break; + case 1: // run list + runList = dlg->getRunList(); + if (!validRunList(runList)) { + QMessageBox::critical(this, "**ERROR**", + "Invalid Run List!\nThe run list needs to be a space separated list of run numbers.", + QMessageBox::Ok, QMessageBox::NoButton); + return; + } + break; + case 2: // run list file name + runListFileName = dlg->getRunListFileName(); + fi = runListFileName; + if (!fi.exists()) { + str = QString("Run List File '%1' doesn't exist.").arg(runListFileName); + QMessageBox::critical(this, "**ERROR**", + str, QMessageBox::Ok, QMessageBox::NoButton); + return; + } + break; + default: // never should reach this point + QMessageBox::critical(this, "**ERROR**", + "No idea how you could reach this point.\nPlease contact the developers.", + QMessageBox::Ok, QMessageBox::NoButton); + return; + break; + } + + // form command + QValueVector cmd; + str = fAdmin->getExecPath() + "/mlog2db"; + cmd.append(str); + + // run list argument + switch (dlg->getRunTag()) { + case 0: + cmd.append(first); + cmd.append(last); + break; + case 1: + end = 0; + while (!runList.section(' ', end, end).isEmpty()) { + end++; + } + // first element + if (end == 1) { + str = "[" + runList.section(' ', 0, 0) + "]"; + } else { + str = "[" + runList.section(' ', 0, 0); + cmd.append(str); + // middle elements + for (i=1; igetExtension(); + if (str.isEmpty()) + cmd.append(""); + else + cmd.append(str); + + // options + + // no header flag? + if (!dlg->getWriteDbHeaderFlag()) + cmd.append("noheader"); + + // no summary flag? + if (!dlg->getSummaryFilePresentFlag()) + cmd.append("nosummary"); + + // template run no + if (!dlg->getTemplateRunNo().isEmpty()) { + str = "fit-" + dlg->getTemplateRunNo(); + cmd.append(str); + } + + // keep minuit2 output + if (dlg->getMinuit2OutputFlag()) { + fKeepMinuit2Output = dlg->getMinuit2OutputFlag(); + cmd.append("-k"); + } + + // DB output wished + if (!dlg->getDbOutputFileName().isEmpty()) { + str = "-o" + dlg->getDbOutputFileName(); + cmd.append(str); + } + +for (unsigned int i=0; i> " << cmd[i].latin1(); +cout << endl; + + PFitOutputHandler fitOutputHandler(cmd); + fitOutputHandler.setModal(true); + fitOutputHandler.exec(); + } } //---------------------------------------------------------------------------------------------------- diff --git a/src/musrgui/PTextEdit.h b/src/musrgui/PTextEdit.h index b7b80c80..487469a0 100644 --- a/src/musrgui/PTextEdit.h +++ b/src/musrgui/PTextEdit.h @@ -59,6 +59,7 @@ private: void load( const QString &f ); PSubTextEdit *currentEditor() const; void doConnections( PSubTextEdit *e ); + bool validRunList(const QString runList); private slots: void fileNew(); diff --git a/src/musrgui/forms/PMlog2DbDialogBase.ui b/src/musrgui/forms/PMlog2DbDialogBase.ui new file mode 100644 index 00000000..3d61e5a1 --- /dev/null +++ b/src/musrgui/forms/PMlog2DbDialogBase.ui @@ -0,0 +1,541 @@ + +PMlog2DbDialogBase + + + PMlog2DbDialogBase + + + + 0 + 0 + 604 + 576 + + + + mlog2db input + + + image0 + + + true + + + true + + + + fRunList_groupBox + + + + 10 + 10 + 580 + 150 + + + + run list input + + + + fFirst_textLabel + + + + 10 + 33 + 40 + 20 + + + + First + + + + + fFirst_lineEdit + + + + 50 + 30 + 90 + 24 + + + + + + fLast_textLabel + + + + 180 + 33 + 40 + 20 + + + + Last + + + + + fLast_lineEdit + + + + 220 + 30 + 100 + 24 + + + + + + fRunList_textLabel + + + + 10 + 70 + 71 + 20 + + + + Run List + + + + + fOr2_textLabel + + + + 540 + 70 + 29 + 21 + + + + <b>OR</b> + + + + + fOr1_textLabel + + + + 540 + 30 + 30 + 20 + + + + <b>OR</b> + + + + + fRunListFileName_textLabel + + + + 10 + 113 + 130 + 20 + + + + Run List File Name + + + + + fRunListFileName_lineEdit + + + + 150 + 110 + 370 + 24 + + + + + + fRunList_lineEdit + + + + 80 + 70 + 440 + 24 + + + + + + + Layout1 + + + + 10 + 530 + 580 + 33 + + + + + unnamed + + + 0 + + + 6 + + + + fHelp_button + + + &Help + + + F1 + + + true + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + fOk_button + + + &OK + + + + + + true + + + true + + + + + fCancel_button + + + &Cancel + + + + + + true + + + + + + + fExtension_groupBox + + + + 10 + 170 + 580 + 65 + + + + msr file extension + + + + fExtension_textLabel + + + + 20 + 30 + 71 + 20 + + + + Extension + + + + + fExtension_lineEdit + + + + 170 + 27 + 140 + 24 + + + + + + + fTemplateRunInput_groupBox + + + + 10 + 250 + 580 + 65 + + + + template run input + + + + fTemplateRunNumber_textLabel + + + + 10 + 30 + 150 + 20 + + + + Template Run Number + + + + + fTemplateRunNumber_lineEdit + + + + 170 + 27 + 140 + 24 + + + + + + + fDbOutputFileName_groupBox + + + + 10 + 325 + 580 + 65 + + + + DB output file name + + + + fDbOutputFileName_lineEdit + + + + 170 + 25 + 350 + 24 + + + + + + fDbOutputFileName_textLabel + + + + 10 + 30 + 150 + 20 + + + + DB Output File Name + + + + + + fOptions_groupBox + + + + 10 + 400 + 581 + 110 + + + + options + + + + fKeepMinuit2Output_checkBox + + + + 20 + 70 + 170 + 22 + + + + Keep Minuit2 Output + + + + + fNoHeader_checkBox + + + + 20 + 30 + 150 + 22 + + + + Write DB Header + + + + + fSummaryPresent_checkBox + + + + 20 + 50 + 180 + 22 + + + + Summary Files Present + + + + + + + 89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000ab49444154388dbd93510ec420084421e9a9e0fc702dfbc5c6b580a8db9d9fa68a30be4e5154201313b7fe5d5490899b3dc77a51410080cb3b181547eb36a8dfbba243a72a39b69a151325c73bb77a383e6df869fc1663048029e3adc6b31c7b22e2a613035f8c7f89e57f393679034704199265c6d419c9386fa5a2f2f1b6525151c97174fd0c4b39157670c410adbba9c886a90a967e90d31c1b8e078a951c7b0a51ac3aae6000783115376b3ca3338719d7820000000049454e44ae426082 + + + + + fOk_button + clicked() + PMlog2DbDialogBase + accept() + + + fCancel_button + clicked() + PMlog2DbDialogBase + reject() + + + fFirst_lineEdit + textChanged(const QString&) + PMlog2DbDialogBase + runFirstLastEntered() + + + fLast_lineEdit + textChanged(const QString&) + PMlog2DbDialogBase + runFirstLastEntered() + + + fRunList_lineEdit + textChanged(const QString&) + PMlog2DbDialogBase + runListEntered() + + + fRunListFileName_lineEdit + textChanged(const QString&) + PMlog2DbDialogBase + runListFileNameEntered() + + + + fFirst_lineEdit + fLast_lineEdit + fRunList_lineEdit + fRunListFileName_lineEdit + fExtension_lineEdit + fTemplateRunNumber_lineEdit + fDbOutputFileName_lineEdit + fNoHeader_checkBox + fSummaryPresent_checkBox + fKeepMinuit2Output_checkBox + fOk_button + fCancel_button + fHelp_button + + + runFirstLastEntered() + runListEntered() + runListFileNameEntered() + + + diff --git a/src/musrgui/musrgui.pro b/src/musrgui/musrgui.pro index 0f0a42ad..a83ba4f3 100644 --- a/src/musrgui/musrgui.pro +++ b/src/musrgui/musrgui.pro @@ -21,6 +21,7 @@ HEADERS = PTextEdit.h \ PGetDefaultDialog.h \ PGetParameterDialog.h \ PGetFourierDialog.h \ + PMlog2DbDialog.h \ PGetPlotDialog.h SOURCES = PTextEdit.cpp \ @@ -32,6 +33,7 @@ SOURCES = PTextEdit.cpp \ PGetParameterDialog.cpp \ PGetFourierDialog.cpp \ PGetPlotDialog.cpp \ + PMlog2DbDialog.cpp \ main.cpp FORMS = forms/PGetDefaultDialogBase.ui \ @@ -40,7 +42,8 @@ FORMS = forms/PGetDefaultDialogBase.ui \ forms/PGetTitleDialog.ui \ forms/PGetParameterDialogBase.ui \ forms/PGetFourierDialogBase.ui \ - forms/PGetPlotDialogBase.ui + forms/PGetPlotDialogBase.ui \ + forms/PMlog2DbDialogBase.ui IMAGES = images/editcopy.xpm \ images/editcut.xpm \