going to start actions

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@19 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d
2012-07-19 14:20:51 +00:00
parent d2b9b6ae1d
commit 3b59d03526
30 changed files with 1433 additions and 610 deletions

View File

@ -1,4 +1,8 @@
/** Qt Project Class Headers */
/**********************************************************************
* TO DO
* 1. settcpsocket is done with slsdetector.maybe do for all detectors connected: mythen
* ********************************************************************/
// Qt Project Class Headers
#include "qDetectorMain.h"
#include "qDefs.h"
#include "qDrawPlot.h"
@ -11,14 +15,14 @@
#include "qTabDebugging.h"
#include "qTabDeveloper.h"
#include "qTabMessages.h"
/** Project Class Headers */
// Project Class Headers
#include "slsDetector.h"
#include "multiSlsDetector.h"
#include "sls_detector_defs.h"
/** Qt Include Headers */
// Qt Include Headers
#include <QSizePolicy>
#include <QFileDialog>
/** C++ Include Headers */
// C++ Include Headers
#include<iostream>
#include <string>
using namespace std;
@ -44,17 +48,17 @@ int main (int argc, char **argv) {
qDetectorMain::qDetectorMain(int argc, char **argv, QApplication *app, QWidget *parent) :
QMainWindow(parent), theApp(app),myDet(0),detID(0),myPlot(NULL),tabs(NULL),isDeveloper(0){
/** Getting all the command line arguments */
// Getting all the command line arguments
for(int iarg=1; iarg<argc; iarg++){
if(!strcasecmp(argv[iarg],"-developer")) {isDeveloper=1;}
if(!strcasecmp(argv[iarg],"-id")) {detID=atoi(argv[iarg+1]);}
if(!strcasecmp(argv[iarg],"-help")){
cout<<"Possible Arguments are:"<<endl;
cout<<"-help \t\t : \t This help"<<endl;
cout<<"-developer \t : \t Enables the developer tab"<<endl;
cout<<"-id i \t : \t Sets the detector to id i (the default is 0). "
"Required only when more than one detector is connected in parallel."<<endl;
cout << "Possible Arguments are:" << endl;
cout << "-help \t\t : \t This help" << endl;
cout << "-developer \t : \t Enables the developer tab" << endl;
cout << "-id i \t : \t Sets the detector to id i (the default is 0). "
"Required only when more than one detector is connected in parallel." << endl;
}
}
@ -81,33 +85,33 @@ qDetectorMain::~qDetectorMain(){
void qDetectorMain::SetUpWidgetWindow(){
/** Layout */
// Layout
layoutTabs= new QGridLayout;
centralwidget->setLayout(layoutTabs);
/** plot setup*/
// plot setup
myPlot = new qDrawPlot(dockWidgetPlot,myDet);
dockWidgetPlot->setWidget(myPlot);
/**tabs setup*/
//tabs setup
tabs = new MyTabWidget(this);
layoutTabs->addWidget(tabs);
/** creating all the tab widgets */
// creating all the tab widgets
tab_messages = new qTabMessages (this, myDet);
tab_measurement = new qTabMeasurement (this, myDet,myPlot);
tab_dataoutput = new qTabDataOutput (this, myDet);
tab_dataoutput = new qTabDataOutput (this, myDet, detID);
tab_plot = new qTabPlot (this, myDet,myPlot);
tab_actions = new qTabActions (this, myDet);
tab_settings = new qTabSettings (this, myDet, detID);
tab_advanced = new qTabAdvanced (this, myDet);
tab_debugging = new qTabDebugging (this, myDet);
tab_developer = new qTabDeveloper (this, myDet);
/** creating the scroll area widgets for the tabs */
// creating the scroll area widgets for the tabs
for(int i=0;i<NumberOfTabs;i++){
scroll[i] = new QScrollArea;
scroll[i]->setFrameShape(QFrame::NoFrame);
}
/** setting the tab widgets to the scrollareas*/
// setting the tab widgets to the scrollareas
scroll[Measurement] ->setWidget(tab_measurement);
scroll[DataOutput] ->setWidget(tab_dataoutput);
scroll[Plot] ->setWidget(tab_plot);
@ -116,7 +120,7 @@ void qDetectorMain::SetUpWidgetWindow(){
scroll[Advanced] ->setWidget(tab_advanced);
scroll[Debugging] ->setWidget(tab_debugging);
scroll[Developer] ->setWidget(tab_developer);
/** inserting all the tabs*/
// inserting all the tabs
tabs->insertTab(Measurement, scroll[Measurement], "Measurement");
tabs->insertTab(DataOutput, scroll[DataOutput], "Data Output");
tabs->insertTab(Plot, scroll[Plot], "Plot");
@ -125,20 +129,20 @@ void qDetectorMain::SetUpWidgetWindow(){
tabs->insertTab(Advanced, scroll[Advanced], "Advanced");
tabs->insertTab(Debugging, scroll[Debugging], "Debugging");
tabs->insertTab(Developer, scroll[Developer], "Developer");
/** Prefer this to expand and not have scroll buttons*/
// Prefer this to expand and not have scroll buttons
tabs->insertTab(Messages, tab_messages, "Messages");
/** Default tab color*/
// Default tab color
defaultTabColor = tabs->tabBar()->tabTextColor(DataOutput);
/**Set the current tab(measurement) to blue as it is the current one*/
//Set the current tab(measurement) to blue as it is the current one
tabs->tabBar()->setTabTextColor(0,QColor(0,0,200,255));
/** increase the width so it uses all the empty space for the tab titles*/
// increase the width so it uses all the empty space for the tab titles
tabs->tabBar()->setFixedWidth(width()+61);
/** mode setup - to set up the tabs initially as disabled, not in form so done here */
// mode setup - to set up the tabs initially as disabled, not in form so done here
#ifdef VERBOSE
cout<<"Setting Debug Mode to 0\nSetting Beamline Mode to 0\n"
cout << "Setting Debug Mode to 0\nSetting Beamline Mode to 0\n"
"Setting Expert Mode to 0\nSetting Dockable Mode to false\n"
"Setting Developer Mode to "<<isDeveloper<<endl;
"Setting Developer Mode to " << isDeveloper << endl;
#endif
tabs->setTabEnabled(Debugging,false);
//beamline mode to false
@ -147,11 +151,11 @@ void qDetectorMain::SetUpWidgetWindow(){
dockWidgetPlot->setFeatures(QDockWidget::NoDockWidgetFeatures);
tabs->setTabEnabled(Developer,isDeveloper);
/** Other setup*/
/**Height of plot and central widget*/
// Other setup
//Height of plot and central widget
heightPlotWindow = dockWidgetPlot->size().height();
heightCentralWidget = centralwidget->size().height();
/** Default zoom Tool Tip */
// Default zoom Tool Tip
zoomToolTip = dockWidgetPlot->toolTip();
}
@ -162,38 +166,43 @@ void qDetectorMain::SetUpWidgetWindow(){
void qDetectorMain::SetUpDetector(){
/**instantiate detector and set window title*/
//instantiate detector and set window title
myDet = new multiSlsDetector(detID);
if(!myDet->getHostname(detID).length()){
string host = myDet->getHostname(detID);
slsDetector *s = myDet->getSlsDetector(detID);
//if hostname doesnt exist even in shared memory
if(!host.length()){
#ifdef VERBOSE
cout<<endl<<"No Detector Connected at id:"<<detID<<endl;
cout<<myDet->getHostname(detID)<<endl;
cout << endl << "No Detector Connected at id:" << detID << endl;
#endif
char cIndex[10];
sprintf(cIndex,"%d",detID);
qDefs::ErrorMessage(string("No Detector Connected at id : ")+string(cIndex),"Main");
exit(-1);
}//if the detector is not even connected
else if(s->setTCPSocket()==slsDetectorDefs::FAIL){
qDefs::ErrorMessage(string("The detector ")+host+string(" is not connected. Exiting GUI."),"Main");
cout << "The detector " << host << "is not connected. Exiting GUI." << endl;
exit(-1);
}
else{
/** Check if type valid. If not, exit*/
switch(myDet->getDetectorsType()){
slsDetectorDefs::detectorType detType = myDet->getDetectorsType();
// Check if type valid. If not, exit
switch(detType){
case slsDetectorDefs::MYTHEN: break;
case slsDetectorDefs::EIGER: break;
case slsDetectorDefs::GOTTHARD: break;
default:
string detName = myDet->slsDetectorBase::getDetectorType(myDet->getDetectorsType());
string hostname = myDet->getHostname(detID);
string errorMess = hostname+string(" has unknown detector type \"")+
string detName = myDet->slsDetectorBase::getDetectorType(detType);
string errorMess = host+string(" has unknown detector type \"")+
detName+string("\". Exiting GUI.");
qDefs::ErrorMessage(errorMess,"Main");
exit(-1);
}
setWindowTitle("SLS Detector GUI : "+
QString(slsDetectorBase::getDetectorType(myDet->getDetectorsType()).c_str())+
" - "+QString(myDet->getHostname(detID).c_str()));
QString(slsDetectorBase::getDetectorType(detType).c_str())+ " - "+QString(host.c_str()));
#ifdef VERBOSE
cout<<endl<<"Type : "<<slsDetectorBase::getDetectorType(myDet->getDetectorsType())<<"\t\t\tDetector : "
""<<myDet->getHostname(detID)<<endl;
cout << endl << "Type : " << slsDetectorBase::getDetectorType(detType) << "\nDetector : " << host << endl;
#endif
myDet->setOnline(slsDetectorDefs::ONLINE_FLAG);
}
@ -204,27 +213,30 @@ void qDetectorMain::SetUpDetector(){
void qDetectorMain::Initialization(){
/** Dockable Plot*/
// Dockable Plot
connect(dockWidgetPlot, SIGNAL(topLevelChanged(bool)), this,SLOT(ResizeMainWindow(bool)));
/** tabs */
// tabs
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(Refresh(int)));//( QWidget*)));
/** Measurement tab*/
// Measurement tab
connect(tab_measurement, SIGNAL(StartSignal()), this,SLOT(EnableTabs()));
connect(tab_measurement, SIGNAL(StopSignal()), this,SLOT(EnableTabs()));
connect(tab_measurement, SIGNAL(CheckPlotIntervalSignal()), tab_plot,SLOT(SetFrequency()));
/** Plot tab */
// Plot tab
connect(tab_plot, SIGNAL(DisableZoomSignal(bool)), this,SLOT(SetZoomToolTip(bool)));
/** Plotting */
/** When the acquisition is finished, must update the meas tab */
// Actions tab
connect(tab_actions, SIGNAL(EnableScanBox(bool,int)), tab_plot,SLOT(EnableScanBox(bool,int)));
// Plotting
// When the acquisition is finished, must update the meas tab
connect(myPlot, SIGNAL(UpdatingPlotFinished()), this, SLOT(EnableTabs()));
connect(myPlot, SIGNAL(UpdatingPlotFinished()), tab_measurement, SLOT(UpdateFinished()));
connect(myPlot, SIGNAL(SetCurrentMeasurementSignal(int)), tab_measurement, SLOT(SetCurrentMeasurement(int)));
/** menubar */
/** Modes Menu */
// menubar
// Modes Menu
connect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
/** Utilities Menu */
// Utilities Menu
connect(menuUtilities, SIGNAL(triggered(QAction*)), this,SLOT(ExecuteUtilities(QAction*)));
/** Help Menu */
// Help Menu
connect(menuHelp, SIGNAL(triggered(QAction*)), this,SLOT(ExecuteHelp(QAction*)));
}
@ -235,33 +247,34 @@ void qDetectorMain::Initialization(){
void qDetectorMain::EnableModes(QAction *action){
bool enable;
/**Set DebugMode */
//Set DebugMode
if(action==actionDebug){
enable = actionDebug->isChecked();
tabs->setTabEnabled(Debugging,enable);
#ifdef VERBOSE
cout<<"Setting Debug Mode to "<<enable<<endl;
cout << "Setting Debug Mode to " << enable << endl;
#endif
}
/**Set BeamlineMode */
//Set BeamlineMode
else if(action==actionBeamline){
enable = actionBeamline->isChecked();
#ifdef VERBOSE
cout<<"Setting Beamline Mode to "<<enable<<endl;
cout << "Setting Beamline Mode to " << enable << endl;
#endif
}
/**Set ExpertMode */
//Set ExpertMode
else if(action==actionExpert){
enable = actionExpert->isChecked();
tabs->setTabEnabled(Advanced,enable);
tab_settings->EnableExpertMode(enable);
#ifdef VERBOSE
cout<<"Setting Expert Mode to "<<enable<<endl;
cout << "Setting Expert Mode to " << enable << endl;
#endif
}
/**Set DockableMode */
//Set DockableMode
else{
enable = actionDockable->isChecked();
if(enable)
@ -271,7 +284,7 @@ void qDetectorMain::EnableModes(QAction *action){
dockWidgetPlot->setFeatures(QDockWidget::NoDockWidgetFeatures);
}
#ifdef VERBOSE
cout<<"Setting Dockable Mode to "<<enable<<endl;
cout << "Setting Dockable Mode to " << enable << endl;
#endif
}
}
@ -284,13 +297,13 @@ void qDetectorMain::ExecuteUtilities(QAction *action){
if(action==actionOpenSetup){
#ifdef VERBOSE
cout<<"Opening Setup"<<endl;
cout << "Opening Setup" << endl;
#endif
QString fName = QString(myDet->getFilePath().c_str());
fName = QFileDialog::getOpenFileName(this,
tr("Load Detector Setup"),fName,
tr("Detector Setup files (*.det)"));
/** Gets called when cancelled as well*/
// Gets called when cancelled as well
if (!fName.isEmpty()){
myDet->retrieveDetectorSetup(string(fName.toAscii().constData()));
qDefs::InfoMessage("The parameters have been successfully setup.","Main");
@ -298,13 +311,13 @@ void qDetectorMain::ExecuteUtilities(QAction *action){
}
else if(action==actionSaveSetup){
#ifdef VERBOSE
cout<<"Saving Setup"<<endl;
cout << "Saving Setup" << endl;
#endif
QString fName = QString(myDet->getFilePath().c_str());
fName = QFileDialog::getSaveFileName(this,
tr("Save Current Detector Setup"),fName,
tr("Detector Setup files (*.det) "));
/** Gets called when cancelled as well*/
// Gets called when cancelled as well
if (!fName.isEmpty()){
myDet->dumpDetectorSetup(string(fName.toAscii().constData()));
qDefs::InfoMessage("The setup parameters have been successfully saved.","Main");
@ -312,18 +325,18 @@ void qDetectorMain::ExecuteUtilities(QAction *action){
}
else if(action==actionMeasurementWizard){
#ifdef VERBOSE
cout<<"Measurement Wizard"<<endl;
cout << "Measurement Wizard" << endl;
#endif
}
else if(action==actionOpenConfiguration){
#ifdef VERBOSE
cout<<"Opening Configuration"<<endl;
cout << "Opening Configuration" << endl;
#endif
QString fName = QString(myDet->getFilePath().c_str());
fName = QFileDialog::getOpenFileName(this,
tr("Load Detector Configuration"),fName,
tr("Configuration files (*.config)"));
/** Gets called when cancelled as well*/
// Gets called when cancelled as well
if (!fName.isEmpty()){
myDet->readConfigurationFile(string(fName.toAscii().constData()));
qDefs::InfoMessage("The parameters have been successfully configured.","Main");
@ -331,13 +344,13 @@ void qDetectorMain::ExecuteUtilities(QAction *action){
}
else if(action==actionSaveConfiguration){
#ifdef VERBOSE
cout<<"Saving Configuration"<<endl;
cout << "Saving Configuration" << endl;
#endif
QString fName = QString(myDet->getFilePath().c_str());
fName = QFileDialog::getSaveFileName(this,
tr("Save Current Detector Configuration"),fName,
tr("Configuration files (*.config) "));
/** Gets called when cancelled as well*/
// Gets called when cancelled as well
if (!fName.isEmpty()){
myDet->writeConfigurationFile(string(fName.toAscii().constData()));
qDefs::InfoMessage("The configuration parameters have been successfully saved.","Main");
@ -345,12 +358,12 @@ void qDetectorMain::ExecuteUtilities(QAction *action){
}
else if(action==actionEnergyCalibration){
#ifdef VERBOSE
cout<<"Executing Energy Calibration"<<endl;
cout << "Executing Energy Calibration" << endl;
#endif
}
else{
#ifdef VERBOSE
cout<<"Executing Angular Calibration"<<endl;
cout << "Executing Angular Calibration" << endl;
#endif
}
@ -362,15 +375,18 @@ void qDetectorMain::ExecuteUtilities(QAction *action){
void qDetectorMain::ExecuteHelp(QAction *action){
if(action==actionVersion){
if(action==actionAbout){
#ifdef VERBOSE
cout<<"Version"<<endl;
#endif
}
else{
#ifdef VERBOSE
cout<<"About"<<endl;
cout << "About: Common GUI for Mythen, Eiger, Gotthard and Agipd detectors" << endl;
#endif
//<h1 style="font-family:verdana;">A heading</h1>
qDefs::InfoMessage("<p style=\"font-family:verdana;\">SLS Detector GUI version: 1.0<br><br>"
"Common GUI to control the SLS Detectors: "
"Mythen, Eiger, Gotthard and Agipd.<br><br>"
"It can be operated in parallel with the command line interface:<br>"
"sls_detector_put,<br>sls_detector_get,<br>sls_detector_acquire and<br>sls_detector_help.<br><br>"
"The software is still in progress. "
"Please report bugs to dhanya.maliakal@psi.ch.<\\p>","About SLS Detector GUI");
}
}
@ -405,18 +421,18 @@ void qDetectorMain::Refresh(int index){
void qDetectorMain::ResizeMainWindow(bool b){
#ifdef VERBOSE
cout<<"Resizing Main Window: height:"<<height()<<endl;
cout << "Resizing Main Window: height:" << height() << endl;
#endif
/** undocked from the main window */
// undocked from the main window
if(b){
/** sets the main window height to a smaller maximum to get rid of space*/
// sets the main window height to a smaller maximum to get rid of space
setMaximumHeight(height()-heightPlotWindow-9);
dockWidgetPlot->setMinimumHeight(0);
cout<<"undocking it from main window"<<endl;
cout << "undocking it from main window" << endl;
}
else{
setMaximumHeight(QWIDGETSIZE_MAX);
/** the minimum for plot will be set when the widget gets resized automatically*/
// the minimum for plot will be set when the widget gets resized automatically
}
}
@ -445,26 +461,26 @@ void qDetectorMain::resizeEvent(QResizeEvent* event){
void qDetectorMain::EnableTabs(){
#ifdef VERBOSE
cout<<"Entering EnableTabs function"<<endl;
cout << "Entering EnableTabs function" << endl;
#endif
bool enable;
enable=!(tabs->isTabEnabled(DataOutput));
// or use the Enable/Disable button
/** normal tabs*/
// normal tabs
tabs->setTabEnabled(DataOutput,enable);
tabs->setTabEnabled(Actions,enable);
tabs->setTabEnabled(Settings,enable);
tabs->setTabEnabled(Messages,enable);
/** special tabs */
// special tabs
if(enable==false){
tabs->setTabEnabled(Debugging,enable);
tabs->setTabEnabled(Advanced,enable);
tabs->setTabEnabled(Developer,enable);
}
else{
/** enable these tabs only if they were enabled earlier */
// enable these tabs only if they were enabled earlier
if(actionDebug->isChecked())
tabs->setTabEnabled(Debugging,enable);
if(actionExpert->isChecked())