added a feature which brings up a error message box, if there was any issue with the msr-file when starting musrview from musredit.

This commit is contained in:
2025-06-29 09:04:45 +02:00
parent 4da145d674
commit b692b78cac
9 changed files with 451 additions and 138 deletions

View File

@@ -38,6 +38,8 @@
#include <iostream>
#include <memory>
#include <vector>
#include <sstream>
#include <TApplication.h>
#include <TSAXParser.h>
@@ -53,6 +55,7 @@
#include "PRunDataHandler.h"
#include "PRunListCollection.h"
#include "PMusrCanvas.h"
#include "PMsgBox.h"
//--------------------------------------------------------------------------
@@ -81,9 +84,21 @@ void musrview_syntax()
std::cout << std::endl << " will produce an ascii dump of the data and fit as plotted.";
std::cout << std::endl << " --timeout <timeout>: <timeout> given in seconds after which musrview terminates.";
std::cout << std::endl << " If <timeout> <= 0, no timeout will take place. Default <timeout> is 0.";
std::cout << std::endl << " -s, --show-errMsgBox: if this tag is defined, error message boxes are shown,";
std::cout << std::endl << " rather than only stderr output.";
std::cout << std::endl << std::endl;
}
//--------------------------------------------------------------------------
void musrview_error_msg(std::string errMsg)
{
int argc=0;
char **argv;
TApplication app("musrviewErrorMsg", &argc, argv);
new PMsgBox(errMsg, gClient->GetRoot(), 600, 200);
app.Run();
}
//--------------------------------------------------------------------------
/**
* <p>The musrview program is used to show muSR fit results in graphical form.
@@ -104,18 +119,20 @@ void musrview_syntax()
*/
int main(int argc, char *argv[])
{
int result = PMUSR_SUCCESS;
bool show_syntax = false;
int result{PMUSR_SUCCESS};
bool show_syntax{false};
int status;
bool success = true;
bool success{true};
char fileName[128];
bool fourier = false;
bool avg = false;
bool theoAtData = false; // theory points only at data points
bool graphicsOutput = false;
bool asciiOutput = false;
bool fourier{false};
bool avg{false};
bool theoAtData{false}; // theory points only at data points
bool graphicsOutput{false};
bool asciiOutput{false};
char graphicsExtension[128];
int timeout = 0;
int timeout{0};
bool show_errMsgBox{false};
std::stringstream errMsg;
memset(fileName, '\0', sizeof(fileName));
@@ -188,6 +205,8 @@ int main(int argc, char *argv[])
show_syntax = true;
break;
}
} else if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--show-errMsgBox")) {
show_errMsgBox = true;
} else {
show_syntax = true;
break;
@@ -227,17 +246,24 @@ int main(int argc, char *argv[])
std::unique_ptr<PMsrHandler> msrHandler = std::make_unique<PMsrHandler>(fileName);
status = msrHandler->ReadMsrFile();
if (status != PMUSR_SUCCESS) {
errMsg << msrHandler->GetLastErrorMsg();
switch (status) {
case PMUSR_MSR_FILE_NOT_FOUND:
std::cerr << std::endl << ">> musrview **ERROR** couldn't find '" << fileName << "'" << std::endl << std::endl;
errMsg << "\n";
errMsg << ">> musrview **ERROR** couldn't find '" << fileName << "'\n\n";
break;
case PMUSR_MSR_SYNTAX_ERROR:
std::cerr << std::endl << ">> musrview **SYNTAX ERROR** in file " << fileName << ", full stop here." << std::endl << std::endl;
errMsg << "\n";
errMsg << ">> musrview **SYNTAX ERROR** in file " << fileName << ", full stop here.\n\n";
break;
default:
std::cerr << std::endl << ">> musrview **UNKNOWN ERROR** when trying to read the msr-file" << std::endl << std::endl;
errMsg << "\n";
errMsg << ">> musrview **UNKNOWN ERROR** when trying to read the msr-file.\n\n";
break;
}
std::cerr << errMsg.str();
if (show_errMsgBox)
musrview_error_msg(errMsg.str());
return status;
}
// make a plot list vector