OpenCores
URL https://opencores.org/ocsvn/modular_oscilloscope/modular_oscilloscope/trunk

Subversion Repositories modular_oscilloscope

[/] [modular_oscilloscope/] [trunk/] [sw/] [src/] [rvioscilloscope.cpp] - Blame information for rev 60

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 budinero
#include <QtGui>
2
#include <QSvgGenerator>
3
#include <QFileDialog>
4
#include "rvioscilloscope.h"
5
#include <qwt_counter.h>
6
#include <qwt_plot_zoomer.h>
7
#include "data_plot.h"
8
#include "ui_rvioscilloscope.h"
9
#include <qwt_plot_picker.h>
10
#include <qwt_picker_machine.h>
11
 
12
 
13
class Zoomer: public QwtPlotZoomer
14
{
15
public:
16
    Zoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas):
17
        QwtPlotZoomer(xAxis, yAxis, canvas)
18
    {
19
        setTrackerMode(QwtPicker::AlwaysOff);
20
        setRubberBand(QwtPicker::NoRubberBand);
21
 
22
        // RightButton: zoom out by 1
23
        // Ctrl+RightButton: zoom out to full size
24
 
25
        setMousePattern(QwtEventPattern::MouseSelect2,
26
            Qt::RightButton, Qt::ControlModifier);
27
 
28
        setMousePattern(QwtEventPattern::MouseSelect3,
29
            Qt::RightButton);
30
 
31
    }
32
};
33
 
34
 
35
RVIOscilloscope::RVIOscilloscope(QWidget *parent)
36
    : QMainWindow(parent), ui(new Ui::RVIOscilloscope)
37
{
38
    ui->setupUi(this);
39
 
40
    extraTools = new RVIBoardTools(this);
41
    ui->toolsLayout->addWidget(extraTools);
42
 
43
    createPlot();
44
 
45
 
46
 
47
    // zoom
48
    d_zoomer[0] = new Zoomer( QwtPlot::xBottom, QwtPlot::yLeft,
49
    plot->canvas());
50
    d_zoomer[0]->setRubberBand(QwtPicker::RectRubberBand);
51
    d_zoomer[0]->setRubberBandPen(QColor(Qt::green));
52
    d_zoomer[0]->setTrackerMode(QwtPicker::ActiveOnly);
53
    d_zoomer[0]->setTrackerPen(QColor(Qt::white));
54
 
55
    d_zoomer[1] = new Zoomer(QwtPlot::xTop, QwtPlot::yRight,
56
    plot->canvas());
57
 
58
    d_panner = new QwtPlotPanner(plot->canvas());
59
    d_panner->setMouseButton(Qt::MidButton);
60
 
61
 
62
 
63
    enableZoomMode(false);
64
 
65
 
66
    // picker
67
    QwtPlotPicker *selectLine = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft ,
68
                                    QwtPlotPicker::VLineRubberBand,
69
                                    QwtPlotPicker::AlwaysOff,
70
                                    plot->canvas());
71
 
72
    //selectLine->setRubberBand(QwtPlotPicker::VLineRubberBand);
73
        selectLine->setStateMachine(new QwtPickerClickPointMachine);
74
    selectLine->setAxis(QwtPlot::xBottom, QwtPlot::yLeft);
75
    selectLine->setRubberBandPen(QPen(Qt::yellow, 0, Qt::SolidLine));
76
    selectLine->setEnabled(true);
77
 
78
    //selectLine->begin();
79
    //selectLine->append(QPoint(0,0));
80
    selectLine->setTrackerPen(QColor(Qt::white));
81
 
82
 
83
    connect(ui->actionDockControls,SIGNAL(triggered(bool)), this, SLOT(setDockedControlsDock(bool)));
84
    connect(ui->controlsDock,SIGNAL(topLevelChanged(bool)), ui->actionDockControls, SLOT(toggle()));
85
    connect(ui->actionShowControls, SIGNAL(toggled(bool)), ui->controlsDock, SLOT(setVisible(bool)));
86
    connect(ui->controlsDock, SIGNAL(visibilityChanged(bool)), ui->actionShowControls, SLOT(setChecked(bool)));
87
 
88
    connect(ui->actionZoom, SIGNAL(triggered(bool)), this,  SLOT(enableZoomMode(bool)));
89
    connect(ui->actionSaveImage, SIGNAL(triggered()), SLOT(exportSVG()));
90
    connect(ui->actionPause, SIGNAL(toggled(bool)), plot, SLOT(setPaused(bool)));
91
    connect(ui->actionPause, SIGNAL(toggled(bool)), extraTools, SLOT(setPaused(bool)));
92
 
93
    connect(ui->actionEnChAGrid, SIGNAL(triggered(bool)), plot, SLOT(curveAShowGrid(bool)));
94
    connect(ui->actionEnChBGrid, SIGNAL(triggered(bool)), plot, SLOT(curveBShowGrid(bool)));
95
    connect(ui->actionEnTimeGrid, SIGNAL(triggered(bool)), plot, SLOT(timeShowGrid(bool)));
96
 
97
    connect(extraTools, SIGNAL(statusChanged(QString)) ,ui->statusBar, SLOT(showMessage(QString)));
98
    connect(extraTools, SIGNAL(channelAEnabled(bool)), plot, SLOT(curveAShow(bool)));
99
    connect(extraTools, SIGNAL(channelBEnabled(bool)), plot, SLOT(curveBShow(bool)));
100
    connect(extraTools, SIGNAL(channelAColorChanged(QColor)),plot,SLOT(setCurveAColor(QColor)));
101
    connect(extraTools, SIGNAL(channelBColorChanged(QColor)),plot,SLOT(setCurveBColor(QColor)));
102
    connect(extraTools, SIGNAL(channelAData(QVector<double> , QVector<double> )),plot,SLOT(curveAUpdate(QVector<double>,QVector<double>)));
103
    connect(extraTools, SIGNAL(channelBData(QVector<double> , QVector<double> )),plot,SLOT(curveBUpdate(QVector<double> , QVector<double> )));
104
    connect(plot, SIGNAL(aScaleDivChanged(double)), extraTools, SLOT(setChannelADiv(double)));
105
    connect(plot, SIGNAL(tScaleDivChanged(double)), extraTools, SLOT(setTimeDiv(double)));
106
    //connect(extraTools, SIGNAL(channelAChangeDiv(double,double)),plot,SLOT(curveASetLimits(double,double)));
107
    connect(extraTools, SIGNAL(channelAChangeDiv(int)), plot, SLOT(curveAZoom(int)));
108
    connect(extraTools, SIGNAL(channelAMove(int)), plot, SLOT(curveAMove(int)));
109
    connect(extraTools, SIGNAL(channelAResetPos()), plot, SLOT(curveAResetPos()));
110
    connect(extraTools, SIGNAL(channelBChangeDiv(int)), plot, SLOT(curveBZoom(int)));
111
    connect(extraTools, SIGNAL(channelBMove(int)), plot, SLOT(curveBMove(int)));
112
    connect(extraTools, SIGNAL(channelBResetPos()), plot, SLOT(curveBResetPos()));
113
    connect(extraTools, SIGNAL(timeChangeDiv(int)), plot, SLOT(timeZoom(int)));
114
    connect(extraTools, SIGNAL(timeMove(int)), plot, SLOT(timeMove(int)));
115
    connect(extraTools, SIGNAL(timeChangeLimits(double,double)), plot, SLOT(timeSetLimits(double,double)));
116
    connect(extraTools, SIGNAL(timeChangeLimits(double,double)), this, SLOT(updateZoomLimits()));
117
 
118
    connect(extraTools, SIGNAL(showTriggerLine(bool, int)),plot,SLOT(enableTriggerLine(bool, int)));
119
    connect(extraTools, SIGNAL(changeTriggerValue(double)),plot,SLOT(setTriggerLineValue(double)));
120
 
121
    extraTools->setDefaultValues();
122
    plot->updateDivs();
123
}
124
 
125
RVIOscilloscope::~RVIOscilloscope()
126
{
127
    delete ui;
128
}
129
 
130
 
131
void RVIOscilloscope::createPlot()
132
{
133
 
134
    plot = new DataPlot(this);
135
    //setCentralWidget(plot);
136
    ui->mainLayout->addWidget(plot);
137
    plot->setMinimumHeight(200);
138
    plot->setMinimumWidth(200);
139
    plot->setCanvasBackground(QColor(Qt::black));
140
 
141
    plot->setCurveAColor(Qt::red);
142
    plot->setCurveBColor(Qt::yellow);
143
//    QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
144
//    sizePolicy.setVerticalStretch(30);
145
//    plot->setSizePolicy(sizePolicy);
146
    //plot->setMargin(12);
147
 
148
}
149
 
150
 
151
void RVIOscilloscope::enableZoomMode(bool on)
152
{
153
    d_panner->setEnabled(on);
154
 
155
    d_zoomer[0]->setEnabled(on);
156
   // d_zoomer[0]->zoom(0);
157
 
158
    d_zoomer[1]->setEnabled(on);
159
   // d_zoomer[1]->zoom(0);
160
}
161
 
162
 
163
void RVIOscilloscope::updateZoomLimits()
164
{
165
    d_zoomer[0]->setZoomBase();
166
    d_zoomer[1]->setZoomBase();
167
}
168
 
169
 
170
void RVIOscilloscope::on_actionBackgroundColor_triggered()
171
{
172
    QColorDialog *colorChooser = new QColorDialog(plot->canvasBackground());
173
    plot->setCanvasBackground(colorChooser->getColor());
174
 
175
}
176
 
177
void RVIOscilloscope::setDockedControlsDock(bool set)
178
{
179
    ui->controlsDock->setFloating(!(set));
180
}
181
 
182
void RVIOscilloscope::exportSVG()
183
{
184
    QString fileName = "plot.svg";
185
 
186
    fileName = QFileDialog::getSaveFileName(
187
        this, "Export File Name", QString(),
188
        "SVG Documents (*.svg)");
189
 
190
    if ( !fileName.isEmpty() )
191
    {
192
        QSvgGenerator generator;
193
        generator.setFileName(fileName);
194
        generator.setSize(QSize(800, 600));
195
 
196
        plot->print(generator);
197
    }
198
 
199
}
200
 
201
void RVIOscilloscope::on_actionSaveData_triggered()
202
{
203
    QString fileName = "data";
204
 
205
    fileName = QFileDialog::getSaveFileName(
206
        this, "File name:", fileName,
207
        "Text file (*.txt);;All files (*.*)");
208
 
209
    if ( !fileName.isEmpty() )
210
    {
211
        QFile file(fileName);
212
 
213
        if (file.open(QFile::WriteOnly | QFile::Truncate))
214
        {
215
             QTextStream out(&file);
216
             out << qSetFieldWidth(15) << right << "Time"  << "Channel A" << "Channel B" << endl;
217
             for (int i = 0; i < extraTools->getData(RVIBoardTools::Time).size(); i++)
218
             {
219
                 out << qSetFieldWidth(15) << right  \
220
                     << extraTools->getData(RVIBoardTools::Time).value(i, 0.0)\
221
                     << extraTools->getData(RVIBoardTools::ChannelA).value(i, 0.0) \
222
                     << extraTools->getData(RVIBoardTools::ChannelB).value(i, 0.0) << endl;
223
             }
224
 
225
        }
226
    }
227
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.