source: tools/FAD/ddd_for_fad/GUI.cpp@ 4862

Last change on this file since 4862 was 248, checked in by dneise, 14 years ago
initial check in of FAD tools simple daq - simple command line interface to FAD will produce binary socket_x.dat files ddd_for_fad - simple GUI able to plot FAD raw data.
File size: 6.4 KB
Line 
1/* ============================================================
2
3FAD Data Display
4
5Oliver Grimm, June 2010
6
7============================================================ */
8
9#include "GUI.h"
10
11Qt::GlobalColor LineColors[] = {Qt::black, Qt::blue, Qt::red, Qt::green, Qt::white,
12 Qt::darkRed, Qt::darkGreen, Qt::darkBlue, Qt::cyan, Qt::darkCyan, Qt::magenta, Qt::darkMagenta,
13 Qt::gray, Qt::darkGray, Qt::lightGray};
14
15fad::fad() {
16
17 //---------------------------------------------------------------------
18 //**************************** Main window ****************************
19 //---------------------------------------------------------------------
20
21 Central = new QWidget(this);
22 setCentralWidget(Central);
23
24 // Sockets
25 for (int i=0; i<NUM_SOCKETS; i++) {
26 Socket[i] = new QTcpSocket(Central);
27 connect(Socket[i], SIGNAL(readyRead()), this, SLOT(ReadFromSocket()));
28 connect(Socket[i], SIGNAL(disconnected()), this, SLOT(GotDisconnected()));
29 }
30
31 // Plot area
32 Graph = new QwtPlot(Central);
33 Graph->setAxisTitle(QwtPlot::yLeft, "Signal [V]");
34 Graph->setAxisTitle(QwtPlot::xBottom, "time [ns]");
35 Graph->setAutoReplot(true);
36 Graph->setCanvasBackground(QColor(Qt::yellow));
37 Graph->insertLegend(new QwtLegend(), QwtPlot::TopLegend, 0.3);
38
39 Magnifier = new QwtPlotMagnifier(Graph->canvas());
40 Magnifier->setMouseButton(Qt::NoButton,Qt::NoButton);
41 Magnifier->setZoomInKey(Qt::Key_M, Qt::NoModifier);
42 Magnifier->setZoomOutKey(Qt::Key_M, Qt::ShiftModifier);
43
44 Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,Graph->canvas());
45 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &)));
46
47 Panner = new QwtPlotPanner(Graph->canvas());
48 Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier);
49
50 Grid = new QwtPlotGrid;
51 Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
52 Grid->attach(Graph);
53
54 // Plot curves for all 36 channels
55 for (int i=0; i<NUM_CHANNELS; i++) {
56 Signal[i] = new QwtPlotCurve;
57 Signal[i]->attach(Graph);
58 Signal[i]->setStyle(QwtPlotCurve::Steps);
59 Signal[i]->setTitle(QString("%1").arg(i));
60 Signal[i]->setPen(QColor(LineColors[i % (sizeof(LineColors)/sizeof(Qt::GlobalColor))]));
61 }
62
63 // Layout of all widgets
64 MainLayout = new QGridLayout(Central);
65 MainLayout->addWidget(Graph, 1, 1, 6, 5);
66 MainLayout->setColumnStretch(1, 10);
67
68 // Menu bar
69 QMenu* Menu = menuBar()->addMenu("&Menu");
70 QAction* SaveAction = Menu->addAction("Save plot", this, SLOT(MenuSave()));
71 SaveAction->setShortcut(Qt::CTRL + Qt::Key_S);
72 Menu->addAction("Print plot", this, SLOT(MenuPrint()));
73 Menu->addAction("Save waveform to ASCII", this, SLOT(MenuSaveASCII()));
74 Menu->addSeparator();
75 ConnectAction = Menu->addAction("Connect", this, SLOT(MakeConnection()));
76 ConnectAction->setShortcut(Qt::CTRL + Qt::Key_C);
77 QAction* QuitAction = Menu->addAction("Quit", qApp, SLOT(quit()));
78 QuitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
79
80 //-----------------------------------------------------------------------
81 //**************************** Socket window ****************************
82 //-----------------------------------------------------------------------
83
84 // Create widget (initially hidden)
85 SocketWindow = new QWidget();
86 SocketWindow->setWindowTitle("fad - Socket Interface");
87
88 // Edit box for IP Address
89 IPAddress = new QLineEdit(SocketWindow);
90 //IPAddress->setText("fadboard0");
91 IPAddress->setText("129.217.160.119");
92 IPAddress->setToolTip("Address of socket server");
93 AddressLayout = new QFormLayout;
94 AddressLayout->addRow("&Remote Address", IPAddress);
95
96 // SpinBox for port selection
97 Port = new QSpinBox(SocketWindow);
98 Port->setRange(0,65535);
99 Port->setValue(5000);
100 Port->setToolTip("Port number of socket server");
101 PortLayout = new QFormLayout;
102 PortLayout->addRow("&Port", Port);
103
104 // Button to make connection
105 Connect = new QPushButton("Connect", SocketWindow);
106 Connect->setFont(QFont("Times", 10, QFont::Bold));
107 connect(Connect, SIGNAL(clicked()), this, SLOT(MakeConnection()));
108 Connect->setToolTip("Connect to server");
109
110 // Edit box for command
111 Command = new QLineEdit(SocketWindow);
112 CommandLayout = new QFormLayout;
113 CommandLayout->addRow("&Command", Command);
114 Command->setEnabled(false);
115 connect(Command, SIGNAL(returnPressed()), this, SLOT(SendToSocket()));
116 Command->setToolTip("Command to send to socket server");
117
118 // Text box for socket output
119 SocketOutput= new QPlainTextEdit(SocketWindow);
120 SocketOutput->setReadOnly(true);
121 SocketOutput->setMaximumBlockCount(MAX_OUTPUT_LINES);
122 SocketOutput->setToolTip("Output of socket server");
123
124
125 DRSgroupBox = new QGroupBox("DRS to be plotted", SocketWindow);
126 for (int i =0 ; i<4; i++)
127 {
128 DRS[i] = new QCheckBox (SocketWindow);
129 }
130 DRS[0]->setChecked(true);
131
132 DRSBoxLayout = new QHBoxLayout;
133 for (int i =0 ; i<4; i++)
134 {
135 DRSBoxLayout->addWidget(DRS[i]);
136 }
137 //DRSBoxLayout->addStretch(1); // ??
138 DRSgroupBox->setLayout(DRSBoxLayout);
139
140 ChannelgroupBox = new QGroupBox("Channel to be plotted", SocketWindow);
141 for (int i =0 ; i<9; i++)
142 {
143 ChannelCheckBox[i] = new QCheckBox (SocketWindow);
144 ChannelCheckBox[i]->setChecked(true);
145 }
146
147 ChannelBoxLayout = new QHBoxLayout;
148 for (int i =0 ; i<9; i++)
149 {
150 ChannelBoxLayout->addWidget(ChannelCheckBox[i]);
151 }
152 //ChannelBoxLayout->addStretch(1); // ??
153 ChannelgroupBox->setLayout(ChannelBoxLayout);
154
155
156
157 // Layout of all widgets
158 SocketLayout = new QGridLayout(SocketWindow);
159 SocketLayout->addLayout(AddressLayout, 0, 0, 0, 1);
160 SocketLayout->addLayout(PortLayout, 0, 2);
161 SocketLayout->addWidget(Connect, 0, 3);
162 SocketLayout->addLayout(CommandLayout, 1, 0, 1, 6);
163 SocketLayout->addWidget(SocketOutput, 2, 0, 4, 6);
164 SocketLayout->addWidget(DRSgroupBox, 7, 0);
165 SocketLayout->addWidget(ChannelgroupBox, 7, 1);
166// SocketLayout->addLayout(vbox, 0,6);
167
168 SocketWindow->show();
169
170}
171
172fad::~fad() {
173
174 delete Grid;
175 for (int i=0; i<NUM_CHANNELS; i++) delete Signal[i];
176
177 delete PortLayout;
178 delete CommandLayout;
179 delete AddressLayout;
180 delete SocketWindow;
181}
182
183
184//---------------------------------------------------------------------
185//**************************** Main program ***************************
186//---------------------------------------------------------------------
187
188int main(int argc, char *argv[]) {
189 QApplication app(argc, argv);
190
191 fad MainWindow;
192 MainWindow.setGeometry(100, 100, 800, 500);
193 MainWindow.setWindowTitle("fad - FAD Data Display");
194 MainWindow.show();
195
196 return app.exec();
197}
Note: See TracBrowser for help on using the repository browser.