ПЗ (1204320), страница 7
Текст из файла (страница 7)
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
datas = new AllData;
this->setWindowTitle("Мобильные весы v7.0 [TrainComplex]");
customPlot = new QCustomPlot;
ui->gridLayout->addWidget(customPlot->window(),0,0);
customPlot->xAxis->setLabel("Позиция");
customPlot->yAxis->setLabel("Разряд");
customPlot->addGraph(customPlot->xAxis, customPlot->yAxis);
customPlot->addGraph(customPlot->xAxis, customPlot->yAxis);
customPlot->graph(0)->setAdaptiveSampling(true);
customPlot->graph(1)->setAdaptiveSampling(true);
customPlot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
customPlot->axisRect()->setRangeDrag(Qt::Horizontal);
customPlot->replot();
customPlot->setContextMenuPolicy(Qt::CustomContextMenu);
connect(customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(showValue(QMouseEvent*)));
connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(moveplot(int)));
connect(ui->verticalSlider,SIGNAL(valueChanged(int)),this,SLOT(scaleplot(int)));
connect(customPlot->xAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(moveSlider(QCPRange)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::contextMenuRequest(QPoint pos)
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addAction("Добавить первый максимум", this, SLOT(addMax1Points()));
menu->addAction("Добавить второй максимум", this, SLOT(addMax2Points()));
menu->popup(customPlot->mapToGlobal(pos));
}
void MainWindow::on_gatherButton_clicked()
{
GatherDialog ga;
ga.exec();
}
void MainWindow::on_analizButton_clicked()
{
AnalizDialog *al = new AnalizDialog;
al->exec();
}
void MainWindow::plotGraphs()
{
for(int a=0; a<2; a++){
datas->fresh_points_x[a].clear();
datas->fresh_points_y[a].clear();
datas->minimum[a]=0;
datas->maximum[a]=0;
double pointo = datas->fresh_data[a][0];
datas->fresh_points_x[a] << 0;
datas->fresh_points_y[a] << pointo;
for(double i=1; i<datas->fresh_data[a].size(); i++){
if(pointo != datas->fresh_data[a][i]){
datas->fresh_points_x[a] << i-1;
datas->fresh_points_y[a] << pointo;
datas->fresh_points_x[a] << i;
datas->fresh_points_y[a] << (double)datas->fresh_data[a][i];
if(datas->maximum[a]<datas->fresh_data[a][i]) datas->maximum[a]=datas->fresh_data[a][i];
pointo = datas->fresh_data[a][i];
}
}
datas->fresh_points_x[a] << (double)datas->fresh_data[a].size()-1;
datas->fresh_points_y[a] << pointo;
}
ui->verticalSlider->setMinimum(256);
ui->verticalSlider->setMaximum(datas->fresh_data[0].size());
ui->horizontalSlider->setMinimum(0);
ui->horizontalSlider->setMaximum(datas->fresh_data[0].size()-ui->verticalSlider->value());
customPlot->graph(0)->setData(datas->fresh_points_x[0],datas->fresh_points_y[0]);
customPlot->graph(0)->setPen(QPen(Qt::red));
customPlot->graph(1)->setData(datas->fresh_points_x[1],datas->fresh_points_y[1]);
customPlot->graph(1)->setPen(QPen(Qt::blue));
customPlot->graph(0)->setVisible(true);
customPlot->graph(1)->setVisible(false);
customPlot->rescaleAxes(true);
customPlot->xAxis->setRange(ui->horizontalSlider->value(), ui->horizontalSlider->value()+ui->verticalSlider->value());
customPlot->yAxis->setRange(customPlot->yAxis->range().lower-5,customPlot->yAxis->range().upper+5);
customPlot->replot();
}
void MainWindow::moveplot(int value)
{
customPlot->xAxis->setRange(value, value+ui->verticalSlider->value());//Для оси Ox
customPlot->replot();
}
void MainWindow::scaleplot(int value)
{
ui->horizontalSlider->setMaximum(datas->fresh_data[0].size()-value);
customPlot->xAxis->setRange(ui->horizontalSlider->value(),ui->horizontalSlider->value()+value);
customPlot->replot();
}
void MainWindow::moveSlider(QCPRange range)
{
ui->horizontalSlider->setValue(range.lower);
}
void MainWindow::on_fDatGraph_clicked()
{
customPlot->graph(0)->setVisible(true);
customPlot->graph(1)->setVisible(false);
customPlot->rescaleAxes(true);
customPlot->xAxis->setRange(ui->horizontalSlider->value(), ui->horizontalSlider->value()+ui->verticalSlider->value());
customPlot->yAxis->setRange(customPlot->yAxis->range().lower-5,customPlot->yAxis->range().upper+5);
customPlot->replot();
}
void MainWindow::on_sDatGraph_clicked()
{
customPlot->graph(0)->setVisible(false);
customPlot->graph(1)->setVisible(true);
customPlot->rescaleAxes(true);
customPlot->xAxis->setRange(ui->horizontalSlider->value(), ui->horizontalSlider->value()+ui->verticalSlider->value());
customPlot->yAxis->setRange(customPlot->yAxis->range().lower-5,customPlot->yAxis->range().upper+5);
customPlot->replot();
}
void MainWindow::on_bothDatGraph_clicked()
{
customPlot->graph(0)->setVisible(true);
customPlot->graph(1)->setVisible(true);
customPlot->rescaleAxes(true);
customPlot->xAxis->setRange(ui->horizontalSlider->value(), ui->horizontalSlider->value()+ui->verticalSlider->value());
customPlot->yAxis->setRange(customPlot->yAxis->range().lower-5,customPlot->yAxis->range().upper+5);
customPlot->replot();
}
//void MainWindow::on_sceneButton_clicked()
//{
// QString filename = QFileDialog::getSaveFileName(this, tr("Save graph to Image (PNG)"),
// QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
// tr("PNG (*.png)"));
// customPlot->savePng(filename);
//}
void MainWindow::on_OpenAction_triggered()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("Fresh Data (*.dat)"));
pot = new FeelThread;
connect(pot,SIGNAL(gatherFeed(QString)),ui->statusBar,SLOT(showMessage(QString)));
connect(pot,SIGNAL(plotGraphs()),this,SLOT(plotGraphs()));
pot->setData(datas);
pot->setFileName(filename);
pot->start(QThread::HighPriority);
}
void MainWindow::on_testButton_clicked()
{
QFile F("C:/Users/Kizoku-san/Desktop/ауа.txt");
F.open(QIODevice::ReadOnly);
if(F.isOpen()){
for(;!F.atEnd();){
QList<QByteArray> T = F.readLine().split('\t');
T[1].chop(2);
qDebug() << QVariant(T[0]).toString() << QVariant(T[1]).toString();
datas->fresh_data[0].append(T[0].toShort());
datas->fresh_data[1].append(T[1].toShort());
qDebug() << QVariant(T[0]).toString() << T[1].toShort();
}
}
else qDebug() << F.fileName();
plotGraphs();
}
void MainWindow::addMax1Points(){
if(customPlot->graph(0)->visible() && customPlot->graph(1)->visible()){
qDebug() << "fuck u";
}else if(customPlot->graph(0)->visible()){
datas->max1_points[0].append(QPoint(customPlot->pos().rx(),customPlot->pos().ry()));
}else if(customPlot->graph(1)->visible()){
datas->max1_points[1].append(QPoint(customPlot->pos().rx(),customPlot->pos().ry()));
}
// ui->statusBar->showMessage(QString("Позиция: " + QVarincustomPlot->pos().rx() + " " + customPlot->pos().ry()));
}
void MainWindow::addMax2Points(){
if(customPlot->graph(0)->visible() && customPlot->graph(1)->visible()){
}else if(customPlot->graph(0)->visible()){
datas->max2_points[0].append(QPoint(customPlot->pos().rx(),customPlot->pos().ry()));
}else if(customPlot->graph(1)->visible()){
datas->max2_points[1].append(QPoint(customPlot->pos().rx(),customPlot->pos().ry()));
}
}
void MainWindow::showValue(QMouseEvent *mouseEvent){
if(customPlot->xAxis->pixelToCoord(mouseEvent->pos().x())>0 && customPlot->xAxis->pixelToCoord(mouseEvent->pos().x())<datas->fresh_data[1].size())ui->statusBar->showMessage(QString("Позиция: " + QVariant(QVariant(customPlot->xAxis->pixelToCoord(mouseEvent->pos().x())).toInt()).toString() + " " + QVariant(datas->fresh_data[1][QVariant(customPlot->xAxis->pixelToCoord(mouseEvent->pos().x())).toInt()]).toString()));
}
void MainWindow::on_PrintAction_triggered()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save graph to Image (PNG)"),
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("PNG (*.png)"));
customPlot->savePng(filename);
}
GatherWindow.cpp
#include "gatherdialog.h"
#include "ui_gatherdialog.h"
#include <RshApi.cpp>
#include <iostream>
#include <sstream>
#include <iomanip>
GatherDialog::GatherDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::GatherDialog)
{
ui->setupUi(this);
this->setWindowTitle("Модуль сбора данных с АЦП [TrainGather]");
// this->setWindowIcon(QIcon("C:/Users/Kizoku-san/Documents/eeeboqq/aicon.jpg"));
U32 st = RSH_API_SUCCESS;
std::vector<std::string> allDevices;
potok = new WorkerThread;
st = Client.GetRegisteredList(allDevices);
if(st == RSH_API_SUCCESS) for(uint it=0; it < allDevices.size(); it++) ui->listBox->addItem(QString::fromUtf8(allDevices[it].c_str()),QVariant(it+1));
else ui->connectButton->setEnabled(false);
connect(potok,SIGNAL(errorEmit(QString)),this,SLOT(getError(QString)));
connect(potok,SIGNAL(gatherBlock(QString,int)),this,SLOT(gathered(QString,int)));
}
GatherDialog::~GatherDialog(){delete ui;}
void GatherDialog::getError(QString str){ QMessageBox::warning(this,"Error-chan detected!",str);}
void GatherDialog::gathered(QString a, int pos){
switch (pos) {
case 0:
ui->statusLabel->setText(QString("Собран " + a + " блок..."));
break;
case 1:
ui->textBrowser->append(a);
break;
case 2:
ui->statusLabel->setText(QString("Сохранение в " + a));
break;
default:
break;
}
}
void GatherDialog::on_connectButton_clicked(){
if(potok->connect((U32)ui->listBox->currentData().toUInt(),ui->listBox->currentText())) {
ui->groupBox->setEnabled(true);
ui->startStopButton->setEnabled(true);
}
else {
Client.Free();
ui->groupBox->setEnabled(false);
gathered(QString("--------Connect Error--------"),1);















