This commit is contained in:
2019-06-18 17:51:28 +02:00
parent 7b456cb9c6
commit e4190285be
9 changed files with 84 additions and 430 deletions

View File

@ -187,7 +187,7 @@ void qCloneWidget::SetCloneHists(int nHists, int histNBins, double *histXAxis, d
void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d) {
cloneplot2D->GetPlot()->SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d);
cloneplot2D->UpdateNKeepSetRangeIfSet();
cloneplot2D->KeepZRangeIfSet();
}
void qCloneWidget::SetRange(bool IsXYRange[], double XYRangeValues[]) {

View File

@ -1433,7 +1433,7 @@ void qDrawPlot::UpdatePlot() {
plot2D->SetYTitle(imageYAxisTitle);
plot2D->SetZTitle(imageZAxisTitle);
//zmin and zmax of plot already calculated using SetData, now recalculate if z is set
plot2D->UpdateZRange();
plot2D->KeepZRangeIfSet();
if (gainPlotEnable) {
gainplot2D->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, gainImageArray);
gainplot2D->setTitle(GetImageTitle());
@ -1743,7 +1743,7 @@ void qDrawPlot::DisableZoom(bool disable) {
plot2D->SetYTitle("Pixel");
plot2D->SetZTitle("Trimbits");
//zmin and zmax of plot already calculated using SetData, now recalculate if z is set
plot2D->UpdateZRange();
plot2D->KeepZRangeIfSet();
#ifdef VERBOSE
std::cout << "Trimbits Plot updated" <<'\n';
#endif

View File

@ -24,18 +24,18 @@ void qServer::FunctionTable() {
flist[qDefs::QF_EXIT_SERVER] = &qServer::ExitServer;
}
void qServer::DecodeFunction(sls::ServerInterface2 *socket) {
qFuncNames fnum;
void qServer::DecodeFunction(sls::ServerInterface2 &socket) {
qDefs::qFuncNames fnum;
socket.Receive(fnum);
if (fnum < 0 || fnum >= QF_NUM_FUNCTIONS) {
throw RuntimeError("Unrecognized Function enum " + std::to_string(fnum) + "\n");
if (fnum < 0 || fnum >= qDefs::QF_NUM_FUNCTIONS) {
throw sls::RuntimeError("Unrecognized Function enum " + std::to_string(fnum) + "\n");
}
FILE_LOG(logDEBUG1) << "calling function fnum: " << fnum << " ("
<< slsDetectorDefs::getQFunctionNameFromEnum(fnum) << ")";
(this->*flist[fnum])(socket);
FILE_LOG(logDEBUG1) << "Function " << getQFunctionNameFromEnum(fnum) << " finished";
<< qDefs::getQFunctionNameFromEnum(fnum) << ")";
(this->*flist[static_cast<int>(fnum)])(socket);
FILE_LOG(logDEBUG1) << "Function " << qDefs::getQFunctionNameFromEnum(fnum) << " finished";
}
void qServer::CreateServers() {
@ -44,16 +44,16 @@ void qServer::CreateServers() {
tcpThreadCreated = true;
try {
// start control server
controlStatus = std::async(std::launch::async, ServerThread, true);
controlStatus = std::async(std::launch::async, &qServer::ServerThread, this, true);
FILE_LOG(logDEBUG) << "Gui control server thread created successfully.";
// start stop server
stopStatus = std::async(std::launch::async, ServerThread, false);
stopStatus = std::async(std::launch::async, &qServer::ServerThread, this, false);
FILE_LOG(logDEBUG) << "Gui stop server thread created successfully.";
} catch (...) {
std::string mess = "Could not create Gui TCP servers";
FILE_LOG(logERROR) << mess;
qDefs::Message(qDefs::WARNING, message, "qServer::CreateServers");
qDefs::Message(qDefs::WARNING, mess, "qServer::CreateServers");
DestroyServers();
}
}
@ -75,21 +75,18 @@ void qServer::DestroyServers() {
}
}
void qServer::ServerThread(isControlServer) {
sls::ServerSocket* sock = nullptr;
if (isControl) {
void qServer::ServerThread(bool isControlServer) {
if (isControlServer) {
FILE_LOG(logDEBUG) << "Starting Gui Server (Control port: " << controlPort << ")";
controlSocket = sls::make_unique<sls::ServerSocket>(controlPort);
sock = controlSocket;
} else {
FILE_LOG(logDEBUG) << "Starting Gui Server (Stop port: " << stopPort << ")";
stopSocket = sls::make_unique<sls::ServerSocket>(stopPort);
sock = stopSocket;
}
while (true) {
try{
auto socket = sock->accept();
auto socket = (isControlServer ? controlSocket->accept() : stopSocket->accept());
try{
decode_function(socket);
} catch(const sls::NonCriticalError &e) {
@ -116,46 +113,46 @@ void qServer::ServerThread(isControlServer) {
FILE_LOG(logDEBUG) << "Stopped gui server thread";
}
void qServer::GetStatus(sls::ServerInterface2* socket) {
void qServer::GetStatus(sls::ServerInterface2 &socket) {
slsDetectorDefs::runStatus status = slsDetectorDefs::ERROR;
int progress = 0;
if (myMainTab->isPlotRunning())
if (mainTab->isPlotRunning())
status = slsDetectorDefs::RUNNING;
else
status = slsDetectorDefs::IDLE;
progress = myMainTab->GetProgress();
progress = mainTab->GetProgress();
int retvals[2] = {static_cast<int>(status), progress};
socket.SendResult(retvals);
}
void qServer::StartAcquisition(sls::ServerInterface2* socket) {
if (myMainTab->StartStopAcquisitionFromClient(true) == slsDetectorDefs::FAIL) {
void qServer::StartAcquisition(sls::ServerInterface2 &socket) {
if (mainTab->StartStopAcquisitionFromClient(true) == slsDetectorDefs::FAIL) {
throw sls::NonCriticalError("Could not start acquistion in Gui");
}
socket.Send(slsDetectorDefs::OK);
}
void qServer::StopsAcquisition(sls::ServerInterface2* socket) {
if (myMainTab->StartStopAcquisitionFromClient(false) == slsDetectorDefs::FAIL) {
void qServer::StopsAcquisition(sls::ServerInterface2 &socket) {
if (mainTab->StartStopAcquisitionFromClient(false) == slsDetectorDefs::FAIL) {
throw sls::NonCriticalError("Could not stop acquistion in Gui");
}
socket.Send(slsDetectorDefs::OK);
}
void qServer::Acquire(sls::ServerInterface2* socket) {
if (myMainTab->StartStopAcquisitionFromClient(true) == slsDetectorDefs::FAIL) {
void qServer::Acquire(sls::ServerInterface2 &socket) {
if (mainTab->StartStopAcquisitionFromClient(true) == slsDetectorDefs::FAIL) {
throw sls::NonCriticalError("Could not start blocking acquistion in Gui");
}
// blocking
usleep(5000);
while (myMainTab->isPlotRunning()) {
while (mainTab->isPlotRunning()) {
usleep(5000);
}
socket.Send(slsDetectorDefs::OK);
}
void qServer::ExitServer(sls::ServerInterface2* socket) {
void qServer::ExitServer(sls::ServerInterface2 &socket) {
throw sls::NonCriticalError("Server exited");
}

View File

@ -21,8 +21,7 @@ QString qTabPlot::defaultImageZAxisTitle("Intensity");
qTabPlot::qTabPlot(QWidget *parent, multiSlsDetector *detector, qDrawPlot *plot) :
QWidget(parent), myDet(detector), myPlot(plot), isOneD(false),
stackedLayout(nullptr), spinNthFrame(nullptr), spinTimeGap(nullptr), comboTimeGapUnit(nullptr),
btnGroupPlotType(0) {
btnGroupPlotType(0), stackedLayout(nullptr), spinNthFrame(nullptr), spinTimeGap(nullptr), comboTimeGapUnit(nullptr) {
setupUi(this);
SetupWidgetWindow();
FILE_LOG(logDEBUG) << "Plot ready";
@ -75,17 +74,11 @@ void qTabPlot::SetupWidgetWindow() {
dispZMax->setValidator(new QDoubleValidator(dispZMax));
// Plot titles
dispTitle->setText("");
myPlot->SetPlotTitlePrefix("");
dispXAxis->setText(defaultHistXAxisTitle);
dispYAxis->setText(defaultHistYAxisTitle);
myPlot->SetHistXAxisTitle(defaultHistXAxisTitle);
myPlot->SetHistYAxisTitle(defaultHistYAxisTitle);
dispXAxis->setText(defaultImageXAxisTitle);
dispYAxis->setText(defaultImageYAxisTitle);
dispZAxis->setText(defaultImageZAxisTitle);
myPlot->SetImageXAxisTitle(defaultImageXAxisTitle);
myPlot->SetImageYAxisTitle(defaultImageYAxisTitle);
myPlot->SetImageZAxisTitle(defaultImageZAxisTitle);
// enabling according to det type
isOneD = false;
@ -202,7 +195,7 @@ void qTabPlot::Select1DPlot(bool enable) {
FILE_LOG(logDEBUG) << "Selecting " << (enable ? "1" : "2") << "D Plot";
isOneD = enable;
box1D->setEnabled(enable);
box2D->setEnabled(!benable);
box2D->setEnabled(!enable);
chkZAxis->setEnabled(!enable);
dispZAxis->setEnabled(!enable);
chkZMin->setEnabled(!enable);
@ -247,48 +240,48 @@ void qTabPlot::SetPlot() {
void qTabPlot::Set1DPlotOptionsRight() {
FILE_LOG(logDEBUG) << "1D Options Right";
int i = stackedWidget->currentIndex();
if (i == (stackedWidget->count() - 1))
stackedWidget->setCurrentIndex(0);
int i = stackedWidget1D->currentIndex();
if (i == (stackedWidget1D->count() - 1))
stackedWidget1D->setCurrentIndex(0);
else
stackedWidget->setCurrentIndex(i + 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget->currentIndex() + 1));
stackedWidget1D->setCurrentIndex(i + 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
}
void qTabPlot::Set1DPlotOptionsLeft() {
FILE_LOG(logDEBUG) << "1D Options Left";
int i = stackedWidget->currentIndex();
int i = stackedWidget1D->currentIndex();
if (i == 0)
stackedWidget->setCurrentIndex(stackedWidget->count() - 1);
stackedWidget1D->setCurrentIndex(stackedWidget1D->count() - 1);
else
stackedWidget->setCurrentIndex(i - 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget->currentIndex() + 1));
stackedWidget1D->setCurrentIndex(i - 1);
box1D->setTitle(QString("1D Plot Options %1").arg(stackedWidget1D->currentIndex() + 1));
}
void qTabPlot::Set2DPlotOptionsRight() {
FILE_LOG(logDEBUG) << "2D Options Right";
int i = stackedWidget_2->currentIndex();
if (i == (stackedWidget_2->count() - 1))
stackedWidget_2->setCurrentIndex(0);
int i = stackedWidget2D->currentIndex();
if (i == (stackedWidget2D->count() - 1))
stackedWidget2D->setCurrentIndex(0);
else
stackedWidget_2->setCurrentIndex(i + 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget_2->currentIndex() + 1));
stackedWidget2D->setCurrentIndex(i + 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
}
void qTabPlot::Set2DPlotOptionsLeft() {
FILE_LOG(logDEBUG) << "2D Options Left";
int i = stackedWidget_2->currentIndex();
int i = stackedWidget2D->currentIndex();
if (i == 0)
stackedWidget_2->setCurrentIndex(stackedWidget_2->count() - 1);
stackedWidget2D->setCurrentIndex(stackedWidget2D->count() - 1);
else
stackedWidget_2->setCurrentIndex(i - 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget_2->currentIndex() + 1));
stackedWidget2D->setCurrentIndex(i - 1);
box2D->setTitle(QString("2D Plot Options %1").arg(stackedWidget2D->currentIndex() + 1));
}
void qTabPlot::EnablePersistency(bool enable) {
FILE_LOG(logINFO) << "Superimpose " << (enable ? "enabled" : "disabled");
lblPersistency->setEnabled(val);
spinPersistency->setEnabled(val);
lblPersistency->setEnabled(enable);
spinPersistency->setEnabled(enable);
if (enable)
myPlot->SetPersistency(spinPersistency->value());
else
@ -423,7 +416,7 @@ void qTabPlot::CheckAspectRatio() {
}
void qTabPlot::SetXYRange() {
FILE_LOG(LOGDEBUG) << "Set XY Range";
FILE_LOG(logDEBUG) << "Set XY Range";
disconnect(dispXMin, SIGNAL(editingFinished()), this, SLOT(SetXRange()));
disconnect(dispXMax, SIGNAL(editingFinished()), this, SLOT(SetXRange()));
disconnect(dispYMin, SIGNAL(editingFinished()), this, SLOT(SetYRange()));
@ -528,7 +521,7 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
ranges[qDefs::YMINIMUM] = myPlot->GetYMinimum();
ranges[qDefs::YMAXIMUM] = myPlot->GetYMaximum();
double idealAspectratio = (ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]);
FILE_LOG(logDEBUG) << "Ideal Aspect ratio: %f for x(%f - %f), y(%f - %f)\n", idealAspectratio, ranges[qDefs::XMINIMUM], ranges[qDefs::XMAXIMUM], ranges[qDefs::YMINIMUM], ranges[qDefs::YMAXIMUM]);
FILE_LOG(logDEBUG) << "Ideal Aspect ratio: " << idealAspectratio << " for x(" << ranges[qDefs::XMINIMUM] << " - " << ranges[qDefs::XMAXIMUM] << "), y(" << ranges[qDefs::YMINIMUM] << " - " << ranges[qDefs::YMAXIMUM] << ")";
// calculate current aspect ratio
ranges[qDefs::XMINIMUM] = dispXMin->text().toDouble();
@ -536,9 +529,9 @@ void qTabPlot::MaintainAspectRatio(int dimension) {
ranges[qDefs::YMINIMUM] = dispYMin->text().toDouble();
ranges[qDefs::YMAXIMUM] = dispYMax->text().toDouble();
double currentAspectRatio = (ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) / (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]);
FILE_LOG(logDEBUG) << "Current Aspect ratio: %f for x(%f - %f), y(%f - %f)\n", currentAspectRatio, ranges[qDefs::XMINIMUM], ranges[qDefs::XMAXIMUM], ranges[qDefs::YMINIMUM], ranges[qDefs::YMAXIMUM]);
if (newAspectRatio != idealAspectratio) {
FILE_LOG(logDEBUG) << "Current Aspect ratio: " << currentAspectRatio << " for x(" << ranges[qDefs::XMINIMUM] << " - " << ranges[qDefs::XMAXIMUM] << "), y(" << ranges[qDefs::YMINIMUM] << " - " << ranges[qDefs::YMAXIMUM] << ")";
if (currentAspectRatio != idealAspectratio) {
// dimension: 1(x changed: y adjusted), 0(y changed: x adjusted), -1(aspect ratio clicked: larger one adjusted)
if (dimension == -1) {
dimension = ((ranges[qDefs::XMAXIMUM] - ranges[qDefs::XMINIMUM]) > (ranges[qDefs::YMAXIMUM] - ranges[qDefs::YMINIMUM]))
@ -603,10 +596,10 @@ void qTabPlot::SetZRange() {
bool isZmin = chkZMin->isChecked();
bool isZmax = chkZMax->isChecked();
double zmin = 0, zmax = 1;
if (!dispZMin->text().empty()) {
if (!dispZMin->text().isEmpty()) {
zmin = dispZMin->text().toDouble();
}
if (!dispZMax->text().empty()) {
if (!dispZMax->text().isEmpty()) {
zmax = dispZMax->text().toDouble();
}
emit ResetZMinZMaxSignal(isZmin, isZmax, zmin, zmax);
@ -636,7 +629,7 @@ void qTabPlot::GetStreamingFrequency() {
double timeS = static_cast<double>(timeMs) / 1000.00;
auto time = qDefs::getCorrectTime(timeS);
spinTimeGap->setValue(time.first);
comboTimeGapUnit->setcurrentIndex(static_cast<int>(time.second));
comboTimeGapUnit->setCurrentIndex(static_cast<int>(time.second));
}
} catch(const sls::NonCriticalError &e) {
qDefs::ExceptionMessage("Could not get streaming timer.", e.what(), "qTabPlot::GetStreamingFrequency");