2250 lines
66 KiB
C++
2250 lines
66 KiB
C++
#include "stdafx.h"
|
||
//#include <afx.h>
|
||
|
||
#include <exception>
|
||
#include <QMessageBox>
|
||
|
||
#include "HPPA.h"
|
||
#include "ImageReaderWriter.h"
|
||
|
||
|
||
HPPA::HPPA(QWidget *parent)
|
||
: QMainWindow(parent)
|
||
{
|
||
ui.setupUi(this);
|
||
|
||
QCoreApplication::setOrganizationName("IRIS");
|
||
QCoreApplication::setOrganizationDomain("iris.com");
|
||
QCoreApplication::setApplicationName("HPPA");
|
||
|
||
|
||
|
||
//配置文件:如果没有,就创建配置文件
|
||
string HPPACfgFile = getPathofEXE() + "\\HPPA.cfg";
|
||
mConfigfile.setConfigfilePath(HPPACfgFile);
|
||
if (!mConfigfile.isConfigfileExist())
|
||
{
|
||
mConfigfile.createConfigFile();
|
||
qDebug() << "create: " << QString::fromStdString(HPPACfgFile);
|
||
}
|
||
mConfigfile.parseConfigfile();
|
||
qDebug() << "exist: " << QString::fromStdString(HPPACfgFile);
|
||
|
||
/*int max, min;
|
||
mConfigfile.getPositionRestriction(max, min);
|
||
|
||
string sn;
|
||
mConfigfile.getSN(sn);
|
||
|
||
int coarse, fine;
|
||
mConfigfile.getTuningStepSize(coarse, fine);
|
||
float fa, fb;
|
||
mConfigfile.getFitParams(fa, fb);
|
||
int max_FocusRange, min_FocusRange;
|
||
mConfigfile.getAutoFocusRange(max_FocusRange, min_FocusRange);
|
||
|
||
float StepAnglemar_x, Lead_x, ScaleFactor_x;
|
||
int SubdivisionMultiples_x;
|
||
mConfigfile.getXMotorParm(StepAnglemar_x, Lead_x, SubdivisionMultiples_x, ScaleFactor_x);
|
||
float StepAnglemar_y, Lead_y, ScaleFactor_y;
|
||
int SubdivisionMultiples_y;
|
||
mConfigfile.getYMotorParm(StepAnglemar_y, Lead_y, SubdivisionMultiples_y, ScaleFactor_y);*/
|
||
|
||
//状态栏
|
||
xmotor_state_label1 = new QLabel();
|
||
ymotor_state_label1 = new QLabel();
|
||
xmotor_state_label1->setText("xMotor");
|
||
ymotor_state_label1->setText("yMotor");
|
||
ui.statusBar->addPermanentWidget(xmotor_state_label1);
|
||
ui.statusBar->addPermanentWidget(ymotor_state_label1);
|
||
|
||
|
||
connect(this->ui.action_exit, SIGNAL(triggered()), this, SLOT(onExit()));
|
||
|
||
//ui.cam_label->setScaledContents(true);
|
||
|
||
/*ui.splitter->setStretchFactor(0, 1);
|
||
ui.splitter->setStretchFactor(1, 1);
|
||
ui.splitter->setStretchFactor(2, 3);*/
|
||
|
||
|
||
|
||
//在工具栏上添加输入框QLineEdit
|
||
frame_number = new QLineEdit(ui.mainToolBar);
|
||
frame_number->setStyleSheet("QLineEdit{background-color:rgb(255,255,255);}");
|
||
frame_number->setMaximumWidth(100);
|
||
frame_number->setText("5000");
|
||
QAction *action = ui.mainToolBar->insertWidget(ui.action_start_recording, frame_number);
|
||
|
||
m_FilenameLineEdit = new QLineEdit(ui.mainToolBar);
|
||
m_FilenameLineEdit->setStyleSheet("QLineEdit{background-color:rgb(255,255,255);}");
|
||
m_FilenameLineEdit->setMaximumWidth(100);
|
||
m_FilenameLineEdit->setText("tmp_image");
|
||
QAction *action1 = ui.mainToolBar->insertWidget(ui.action_start_recording, m_FilenameLineEdit);
|
||
|
||
|
||
|
||
|
||
/*QToolBar *ptoolbar = ui.mainToolBar;
|
||
QAction *pAction = new QAction("tangchao");
|
||
ptoolbar->addAction(pAction);*/
|
||
|
||
|
||
|
||
|
||
|
||
//光谱仪操作
|
||
m_Imager = nullptr;
|
||
m_RecordState = 0;
|
||
connect(this->ui.action_connect_imager, SIGNAL(triggered()), this, SLOT(onconnect()));//信号与槽:连接相机,相机操作相关信号与槽绑定放在函数onconnect中
|
||
|
||
//rgb相机
|
||
m_RgbCameraThread = new QThread();
|
||
m_RgbCamera = new RgbCameraOperation();
|
||
m_RgbCamera->moveToThread(m_RgbCameraThread);
|
||
m_RgbCameraThread->start();
|
||
connect(this->ui.open_rgb_camera_btn, SIGNAL(clicked()), m_RgbCamera, SLOT(OpenCamera()));//使用信号通知主线程(ui线程)刷新视频 → 成功,但是界面卡顿
|
||
connect(m_RgbCamera, SIGNAL(PlotSignal()), this, SLOT(onPlotRgbImage()));
|
||
|
||
//m_RgbCamera->setCallback(onPlotRgbImage);
|
||
//connect(this->ui.open_rgb_camera_btn, SIGNAL(clicked()), m_RgbCamera, SLOT(OpenCamera_callback()));//使用回调函数来刷新主线程(ui线程)上的视频 → 失败
|
||
|
||
connect(this->ui.close_rgb_camera_btn, SIGNAL(clicked()), this, SLOT(onCloseRgbCamera()));//关闭相机
|
||
connect(m_RgbCamera, SIGNAL(CamClosed()), this, SLOT(onClearLabel()));
|
||
|
||
|
||
//设置相机可用帧率范围:这些设置必须在slider的信号和槽连接connect前,否则setMinimum会改变slider的值
|
||
ui.FramerateSlider->setMinimum(1);
|
||
ui.FramerateSlider->setMaximum(250);
|
||
ui.GainSlider->setMinimum(0);
|
||
ui.GainSlider->setMaximum(24);
|
||
//相机参数控件设置为不可用
|
||
frame_number->setEnabled(false);
|
||
|
||
ui.framerate_lineEdit->setEnabled(false);
|
||
ui.integratioin_time_lineEdit->setEnabled(false);
|
||
ui.gain_lineEdit->setEnabled(false);
|
||
|
||
ui.FramerateSlider->setEnabled(false);
|
||
ui.IntegratioinTimeSlider->setEnabled(false);
|
||
ui.GainSlider->setEnabled(false);
|
||
|
||
|
||
|
||
|
||
m_xMotor = nullptr;
|
||
m_yMotor = nullptr;
|
||
|
||
|
||
|
||
//m_TestXmotorStausThread = new MotorWorkerThread(m_xMotor);
|
||
//m_TestXmotorStausThread->start();
|
||
|
||
startTimer(1000);
|
||
|
||
|
||
m_lManualSpeedOfXMotor = 6000 * 4 * 2;
|
||
m_lManualSpeedOfYMotor = 6000 * 4;//上海农科院:20000
|
||
|
||
connect(this->ui.motor_reset_btn, SIGNAL(clicked()), this, SLOT(onMotorReset()));
|
||
|
||
connect(this->ui.xmotor_left_btn, SIGNAL(pressed()), this, SLOT(onxMotorLeft()));
|
||
connect(this->ui.xmotor_left_btn, SIGNAL(released()), this, SLOT(onxMotorStop()));
|
||
connect(this->ui.xmotor_right_btn, SIGNAL(pressed()), this, SLOT(onxMotorRight()));
|
||
connect(this->ui.xmotor_right_btn, SIGNAL(released()), this, SLOT(onxMotorStop()));
|
||
|
||
connect(this->ui.ymotor_forward_btn, SIGNAL(pressed()), this, SLOT(onyMotorForward()));
|
||
connect(this->ui.ymotor_forward_btn, SIGNAL(released()), this, SLOT(onyMotorStop()));
|
||
connect(this->ui.ymotor_backward_btn, SIGNAL(pressed()), this, SLOT(onyMotorBackward()));
|
||
connect(this->ui.ymotor_backward_btn, SIGNAL(released()), this, SLOT(onyMotorStop()));
|
||
|
||
//速度
|
||
//QRegExp rx("\\d{0,3}.[1-9]$");
|
||
QRegExp rx("^\\d+(\\.\\d+)?$");
|
||
ui.xmotor_speed_lineEdit->setValidator(new QRegExpValidator(rx));
|
||
|
||
//读取配置文件
|
||
float lead;//导程
|
||
float stepAnglemar;//步距角
|
||
float scaleFactor;//因机械装置的原因引入的缩放因子
|
||
int subdivisionMultiples;//细分数
|
||
float maxRange;
|
||
mConfigfile.getXMotorParm(stepAnglemar, lead, subdivisionMultiples, scaleFactor, maxRange);
|
||
|
||
ui.xmotor_speed_slider->setMultiplier(lead, stepAnglemar, scaleFactor, subdivisionMultiples);
|
||
ui.xmotor_speed_slider->setRange(0, 3);//5.2734375cm/s=10000脉冲
|
||
ui.xmotor_speed_slider->setValue(1);
|
||
connect(this->ui.xmotor_speed_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnXmotorSpeedLineeditEditingFinished()));
|
||
//connect(this->ui.xmotor_speed_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnXmotorSpeedEditingFinished()));//不通过此方式为马达设置速度,每次点击采集后,都会读取界面的速度,然后设置
|
||
connect(this->ui.xmotor_speed_slider, SIGNAL(valueChanged(double)), this, SLOT(OnXmotorSpeedSliderChanged(double)));
|
||
|
||
connect(this->ui.xmotor_location_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnXmotorLocationLineeditEditingFinished()));
|
||
connect(this->ui.xmotor_location_slider, SIGNAL(valueChanged(double)), this, SLOT(OnXmotorLocationSliderChanged(double)));
|
||
connect(this->ui.xmotor_location_slider, SIGNAL(sliderReleased()), this, SLOT(OnXmotorLocationSliderReleased()));
|
||
ui.xmotor_location_slider->setMultiplier(lead, stepAnglemar, scaleFactor, subdivisionMultiples);
|
||
ui.xmotor_location_slider->setValue(0);
|
||
|
||
mConfigfile.getYMotorParm(stepAnglemar, lead, subdivisionMultiples, scaleFactor, maxRange);
|
||
connect(this->ui.ymotor_location_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnYmotorLocationLineeditEditingFinished()));
|
||
connect(this->ui.ymotor_location_slider, SIGNAL(valueChanged(double)), this, SLOT(OnYmotorLocationSliderChanged(double)));
|
||
connect(this->ui.ymotor_location_slider, SIGNAL(sliderReleased()), this, SLOT(OnYmotorLocationSliderReleased()));
|
||
ui.ymotor_location_slider->setMultiplier(lead, stepAnglemar, scaleFactor, subdivisionMultiples);
|
||
ui.ymotor_location_slider->setValue(0);
|
||
|
||
|
||
|
||
m_timerLocationFeedBackOfMotor_x_y = new QTimer();
|
||
connect(m_timerLocationFeedBackOfMotor_x_y, SIGNAL(timeout()), this, SLOT(ontimerLocationFeedBackOfMotor_x_y()));
|
||
|
||
m_timerYmotorLocationFeedBackAfterRecord = new QTimer();
|
||
connect(m_timerYmotorLocationFeedBackAfterRecord, SIGNAL(timeout()), this, SLOT(ontimerYmotorLocationFeedBackAfterRecord()));
|
||
|
||
//马达量程测量
|
||
connect(this->ui.test_range_btn, SIGNAL(clicked()), this, SLOT(ontestRangeOfMotor_x_y()));
|
||
m_timerTestRangeOfxMotor = new QTimer();
|
||
connect(m_timerTestRangeOfxMotor, SIGNAL(timeout()), this, SLOT(ontimerTestRangeOfxMotor()));
|
||
m_timerTestRangeOfyMotor = new QTimer();
|
||
connect(m_timerTestRangeOfyMotor, SIGNAL(timeout()), this, SLOT(ontimerTestRangeOfyMotor()));
|
||
|
||
widthScale = 1;
|
||
heightScale = 1;
|
||
|
||
//马达位置模拟
|
||
connect(ui.graphicsView->imager, SIGNAL(leftMouseButtonPressed(int, int)), this, SLOT(onimagerSimulatorMove(int, int)));
|
||
|
||
//
|
||
m_ForLoopControlThread = new QThread();
|
||
m_ForLoopControl = new ForLoopControl();
|
||
m_ForLoopControl->moveToThread(m_ForLoopControlThread);
|
||
m_ForLoopControlThread->start();
|
||
|
||
|
||
//connect(this->ui.action_start_recording, SIGNAL(triggered()), m_ForLoopControl, SLOT(startLoop()));//放在函数onconnect中
|
||
connect(m_ForLoopControl, SIGNAL(recordSignal(int)), this, SLOT(onStartRecordStep2(int)));
|
||
|
||
|
||
|
||
m_timerMoveXmotor = new QTimer();
|
||
connect(m_timerMoveXmotor, SIGNAL(timeout()), this, SLOT(ontimerMoveXmotor()));
|
||
m_timerMoveYmotor = new QTimer();
|
||
connect(m_timerMoveYmotor, SIGNAL(timeout()), this, SLOT(ontimerMoveYmotor()));
|
||
|
||
|
||
//
|
||
ui.ImageViewerTabWidget->clear();//必须放在最前面,首先删除所有的tab
|
||
//ui.ImageViewerTabWidget->setTabsClosable(true);//这样每页都会有关闭按钮
|
||
connect(m_ForLoopControl, SIGNAL(recordSignal(int)), this, SLOT(onCreateTab(int)));//在tabWidget中新建一个tab,用于显示图像
|
||
connect(ui.ImageViewerTabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabWidgetCurrentChanged(int)));
|
||
|
||
//
|
||
connect(this->ui.action_about, SIGNAL(triggered()), this, SLOT(onAbout()));
|
||
|
||
initPanelToolbar();
|
||
|
||
//光谱显示
|
||
QWidget* widget = new QWidget();
|
||
QGridLayout* grid = new QGridLayout(widget);
|
||
|
||
m_chartView = new QChartView(ui.mDockWidgetSpectralViewer);
|
||
m_chartView->setRenderHint(QPainter::Antialiasing);
|
||
|
||
grid->addWidget(m_chartView);
|
||
//grid->setMargin(0);
|
||
grid->setContentsMargins(0, 0, 0, 0);
|
||
//grid->SetMaximumSize(0);
|
||
ui.mDockWidgetSpectralViewer->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
|
||
ui.mDockWidgetSpectralViewer->setWidget(widget);
|
||
//QLineSeries *series = new QLineSeries();
|
||
//QChart *chart = new QChart();
|
||
mPanelMenu->addAction(ui.mDockWidgetSpectralViewer->toggleViewAction());
|
||
|
||
//轨迹规划
|
||
m_pathPlan = new PathPlan(m_xMotor, m_yMotor, ui.xmotor_location_slider, ui.ymotor_location_slider);
|
||
QDockWidget* dock_pathPlan = new QDockWidget(QString::fromLocal8Bit("轨迹规划"), this);
|
||
dock_pathPlan->setObjectName("mDockPathPlan");
|
||
dock_pathPlan->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
|
||
dock_pathPlan->setWidget(m_pathPlan);
|
||
tabifyDockWidget(ui.mDockWidgetLinearStage, dock_pathPlan);
|
||
mPanelMenu->addAction(dock_pathPlan->toggleViewAction());
|
||
|
||
//升降桌dock
|
||
adjustTable* adt = new adjustTable();
|
||
|
||
QDockWidget* dock_adt = new QDockWidget(QString::fromLocal8Bit("升降桌"), this);
|
||
dock_adt->setObjectName("mDockAdjustTable");
|
||
dock_adt->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||
dock_adt->setWidget(adt);
|
||
tabifyDockWidget(dock_pathPlan, dock_adt);
|
||
mPanelMenu->addAction(dock_adt->toggleViewAction());
|
||
|
||
//电源控制
|
||
PowerControl* pc = new PowerControl();
|
||
|
||
QDockWidget* dock_pc = new QDockWidget(QString::fromLocal8Bit("电源控制"), this);
|
||
dock_pc->setObjectName("mDockPowerControl");
|
||
dock_pc->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||
dock_pc->setWidget(pc);
|
||
tabifyDockWidget(dock_adt, dock_pc);
|
||
mPanelMenu->addAction(dock_pc->toggleViewAction());
|
||
connect(pc, &PowerControl::powerOpened, this, &HPPA::newMotor);
|
||
connect(pc, &PowerControl::powerClosed, this, &HPPA::deleteMotor);
|
||
|
||
//机械臂控制
|
||
rac = new RobotArmControl();
|
||
connect(rac->robotController, SIGNAL(hsiRecordSignal(int)), this, SLOT(recordFromRobotArm(int)));
|
||
QDockWidget* dock_rac = new QDockWidget(QString::fromLocal8Bit("机械臂控制"), this);
|
||
dock_rac->setObjectName("mDockRobotArmControl");
|
||
dock_rac->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||
dock_rac->setWidget(rac);
|
||
tabifyDockWidget(dock_adt, dock_rac);
|
||
mPanelMenu->addAction(dock_rac->toggleViewAction());
|
||
|
||
createActionGroups();
|
||
connect(mImagerGroup, &QActionGroup::triggered, this, &HPPA::selectingImager);
|
||
|
||
createMoveplatformActionGroup();
|
||
connect(moveplatformActionGroup, &QActionGroup::triggered, this, &HPPA::selectingMoveplatform);
|
||
|
||
QString strPath = QCoreApplication::applicationDirPath() + "/UILayout.ini";
|
||
QFile file(strPath);
|
||
if (file.open(QIODevice::ReadOnly))
|
||
{
|
||
QByteArray ba;
|
||
QDataStream in(&file);
|
||
in >> ba;
|
||
file.close();
|
||
this->restoreState(ba);
|
||
}
|
||
}
|
||
|
||
void HPPA::recordFromRobotArm(int fileCounter)
|
||
{
|
||
//qDebug() << "recordFromRobotArm" << fileCounter;
|
||
|
||
if (fileCounter == -1)
|
||
{
|
||
m_Imager->setRecordControlState(false);
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
//qDebug() << "recordFromRobotArm: 1111111111111111111111";
|
||
|
||
return;
|
||
}
|
||
|
||
if (fileCounter - 1 == 0)
|
||
{
|
||
ui.ImageViewerTabWidget->clear();
|
||
}
|
||
|
||
onCreateTab(fileCounter-1);
|
||
m_numberOfRecording = fileCounter - 1;
|
||
emit StartRecordSignal();
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集中"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(255,0,0);}");
|
||
//qDebug() << "recordFromRobotArm: 2222222222222222222222";
|
||
}
|
||
|
||
void HPPA::createActionGroups()
|
||
{
|
||
// Imager Tool Group
|
||
mImagerGroup = new QActionGroup(this);
|
||
mImagerGroup->addAction(ui.mActionPica_L);
|
||
mImagerGroup->addAction(ui.mActionPika_XC2);
|
||
mImagerGroup->addAction(ui.mActionCorning_410);
|
||
mImagerGroup->addAction(ui.mActionPica_NIR);
|
||
|
||
|
||
// 读取上次选择的结果
|
||
QSettings settings;
|
||
QString lastSelectedAction = settings.value("LastSelectedImagerAction").toString();
|
||
|
||
// 恢复上次选择的结果
|
||
if (lastSelectedAction == "mActionPica_L")
|
||
{
|
||
ui.mActionPica_L->setChecked(true);
|
||
}
|
||
else if (lastSelectedAction == "mActionPica_NIR")
|
||
{
|
||
ui.mActionPica_NIR->setChecked(true);
|
||
}
|
||
else if (lastSelectedAction == "mActionPika_XC2")
|
||
{
|
||
ui.mActionPika_XC2->setChecked(true);
|
||
}
|
||
else if (lastSelectedAction == "mActionCorning_410")
|
||
{
|
||
ui.mActionCorning_410->setChecked(true);
|
||
}
|
||
|
||
}
|
||
|
||
void HPPA::selectingImager(QAction* selectedAction)
|
||
{
|
||
QSettings settings;
|
||
settings.setValue("LastSelectedImagerAction", selectedAction->objectName());
|
||
settings.sync();
|
||
}
|
||
|
||
void HPPA::createMoveplatformActionGroup()
|
||
{
|
||
moveplatformActionGroup = new QActionGroup(this);
|
||
moveplatformActionGroup->addAction(ui.mAction_is_no_motor);
|
||
moveplatformActionGroup->addAction(ui.mAction_2AxisMotor);
|
||
moveplatformActionGroup->addAction(ui.mAction_RobotArm);
|
||
|
||
// 读取上次选择的结果
|
||
QSettings settings;
|
||
QString lastSelectedAction = settings.value("LastSelectedMoveplatform").toString();
|
||
|
||
// 恢复上次选择的结果
|
||
if (lastSelectedAction == "mAction_is_no_motor")
|
||
{
|
||
ui.mAction_is_no_motor->setChecked(true);
|
||
}
|
||
else if (lastSelectedAction == "mAction_2AxisMotor")
|
||
{
|
||
ui.mAction_2AxisMotor->setChecked(true);
|
||
}
|
||
else if (lastSelectedAction == "mAction_RobotArm")
|
||
{
|
||
ui.mAction_RobotArm->setChecked(true);
|
||
}
|
||
}
|
||
|
||
void HPPA::selectingMoveplatform(QAction* selectedAction)
|
||
{
|
||
QSettings settings;
|
||
settings.setValue("LastSelectedMoveplatform", selectedAction->objectName());
|
||
settings.sync();
|
||
}
|
||
|
||
HPPA::~HPPA()
|
||
{
|
||
QString strPath = QCoreApplication::applicationDirPath() + "/UILayout.ini";
|
||
QFile file(strPath);
|
||
if (file.open(QIODevice::WriteOnly)) {
|
||
QDataStream outfile(&file);
|
||
QByteArray ba = this->saveState();
|
||
outfile << ba;
|
||
file.close();
|
||
}
|
||
|
||
if (m_Imager != nullptr)
|
||
{
|
||
//m_Imager->~ResononNirImager();//释放资源
|
||
delete m_Imager;
|
||
}
|
||
|
||
if (m_xMotor != nullptr && m_yMotor != nullptr)
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
m_xMotor->StopMotormove();
|
||
}
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
m_yMotor->StopMotormove();
|
||
}
|
||
}
|
||
}
|
||
|
||
void HPPA::initPanelToolbar()
|
||
{
|
||
tabifyDockWidget(ui.mDockWidgetSpectrometer, ui.mDockWidgetLinearStage);
|
||
|
||
mPanelMenu = new QMenu(QString::fromLocal8Bit("面板"), this);//create panel menu
|
||
mPanelMenu->setObjectName(QStringLiteral("mPanelMenu"));
|
||
mToolbarMenu = new QMenu(QString::fromLocal8Bit("工具栏"), this);//create toolbar menu
|
||
mToolbarMenu->setObjectName(QStringLiteral("mToolbarMenu"));
|
||
|
||
ui.mWindowsMenu->addSeparator();
|
||
ui.mWindowsMenu->addMenu(mPanelMenu);
|
||
ui.mWindowsMenu->addMenu(mToolbarMenu);
|
||
|
||
mPanelMenu->addAction(ui.mDockWidgetSpectrometer->toggleViewAction());
|
||
mPanelMenu->addAction(ui.mDockWidgetLinearStage->toggleViewAction());
|
||
|
||
mPanelMenu->addAction(ui.mDockWidgetRGBCamera->toggleViewAction());
|
||
mPanelMenu->addAction(ui.mDockWidgetSimulator->toggleViewAction());
|
||
|
||
mToolbarMenu->addAction(ui.mainToolBar->toggleViewAction());
|
||
}
|
||
|
||
void HPPA::CalculateIntegratioinTimeRange()
|
||
{
|
||
double range = 1 / m_Imager->getFramerate() * 1000;//毫秒
|
||
|
||
ui.IntegratioinTimeSlider->blockSignals(true);//因为setMaximum会触发valueChanged信号,所以调用setMaximum前需要阻断信号
|
||
ui.IntegratioinTimeSlider->setMaximum(range);
|
||
ui.IntegratioinTimeSlider->blockSignals(false);
|
||
}
|
||
|
||
void HPPA::onStartRecordStep1()
|
||
{
|
||
QAction* checked = moveplatformActionGroup->checkedAction();
|
||
if (!checked)
|
||
{
|
||
QMessageBox msgBox;
|
||
msgBox.setText(QString::fromLocal8Bit("请选择扫描平台!"));
|
||
msgBox.exec();
|
||
return;
|
||
}
|
||
|
||
//判断是否覆盖存在的文件
|
||
FileOperation* fileOperation = new FileOperation();
|
||
string directory = fileOperation->getDirectoryFromString();
|
||
//string imgPath = directory + "\\tmp_image";
|
||
string imgPath = directory + "\\" + m_FilenameLineEdit->text().toStdString();
|
||
int x = _access(imgPath.c_str(), 0);
|
||
if (!x)//如果文件存在就执行此if的代码
|
||
{
|
||
enum QMessageBox::StandardButton response = QMessageBox::question(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("文件存在!是否覆盖?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);;
|
||
if (response == QMessageBox::Yes)//
|
||
{
|
||
//std::cout << "覆盖" << std::endl;
|
||
}
|
||
else
|
||
{
|
||
//std::cout << "不覆盖" << std::endl;
|
||
//m_RecordState -= 1;//不覆盖的话就需要还原这个参数,并停止采集
|
||
return;
|
||
}
|
||
}
|
||
|
||
m_Imager->setFrameNumber(this->frame_number->text().toInt());
|
||
m_Imager->setFileName2Save(imgPath);
|
||
|
||
QString checkedName = checked->objectName();
|
||
|
||
if (checkedName == "mAction_is_no_motor")
|
||
{
|
||
m_RecordState += 1;
|
||
|
||
if (m_RecordState % 2 == 1)
|
||
{
|
||
ui.ImageViewerTabWidget->clear();
|
||
|
||
onCreateTab(0);
|
||
m_numberOfRecording = 0;
|
||
|
||
emit StartRecordSignal();//发射开始采集信号
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("停止采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(255,0,0);}");
|
||
}
|
||
else
|
||
{
|
||
m_Imager->setRecordControlState(false);//光谱仪停止采集
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
}
|
||
return;
|
||
}
|
||
else if (checkedName == "mAction_2AxisMotor")
|
||
{
|
||
//确保x马达所在位置 小于 x马达最大采集限制位置
|
||
int validLineCount = 0;
|
||
for (size_t i = 0; i < m_pathPlan->getRecordLineTableWidget()->rowCount(); i++)
|
||
{
|
||
//xx = xx + ui.xmotor_location_slider->value() < m_pathPlan->getRecordLineTableWidget()->item(i, 1)->text().toDouble();
|
||
|
||
if (ui.xmotor_location_slider->value() < m_pathPlan->getRecordLineTableWidget()->item(i, 1)->text().toDouble())
|
||
{
|
||
validLineCount++;
|
||
}
|
||
|
||
}
|
||
|
||
if (validLineCount < m_pathPlan->getRecordLineTableWidget()->rowCount())
|
||
{
|
||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("轨迹x马达限位错误!"));
|
||
return;
|
||
}
|
||
|
||
//确保采集线存在
|
||
if (m_pathPlan->getRecordLineTableWidget()->rowCount() <= 0)
|
||
{
|
||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请先生成轨迹!"));
|
||
return;
|
||
}
|
||
|
||
//开始采集
|
||
m_RecordState += 1;
|
||
|
||
if (m_RecordState % 2 == 1)
|
||
{
|
||
//
|
||
operateWidget = QObject::sender()->objectName();
|
||
|
||
//删除所有tab
|
||
ui.ImageViewerTabWidget->clear();
|
||
|
||
//创建记录x马达位置的文件
|
||
string x_location = removeFileExtension(imgPath) + "x_location.pos";
|
||
m_hTimesFile = fopen(x_location.c_str(), "w+");
|
||
|
||
//开始循环
|
||
m_ForLoopControl->setLoopCount(m_pathPlan->getRecordLineTableWidget()->rowCount());//为循环控制线程设置循环次数
|
||
emit StartLoopSignal();
|
||
|
||
|
||
//所有行设置为灰色
|
||
for (size_t i = 0; i < m_pathPlan->getRecordLineTableWidget()->rowCount(); i++)
|
||
{
|
||
for (size_t j = 0; j < m_pathPlan->getRecordLineTableWidget()->columnCount(); j++)
|
||
{
|
||
m_pathPlan->getRecordLineTableWidget()->item(i, j)->setBackgroundColor(QColor(240, 240, 240));
|
||
}
|
||
}
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("停止采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(255,0,0);}");
|
||
}
|
||
else
|
||
{
|
||
m_Imager->setRecordControlState(false);//光谱仪停止采集
|
||
|
||
m_ForLoopControl->m_boolQuitLoop = true;//循环停止
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
}
|
||
|
||
return;
|
||
}
|
||
else if (checkedName == "mAction_RobotArm")
|
||
{
|
||
//先判断是否选择了任务,执行函数RobotArmControl::executeTask,修复界面显示bug
|
||
rac->executeTaskWithHyperImager();
|
||
|
||
return;
|
||
}
|
||
}
|
||
|
||
void HPPA::onStartRecordStep2(int lineNumber)
|
||
{
|
||
if (m_xMotor == nullptr && m_yMotor == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (lineNumber >= 0)
|
||
{
|
||
m_numberOfRecording = lineNumber;
|
||
}
|
||
|
||
if (lineNumber >= 0)
|
||
{
|
||
//开始移动y马达,控制x马达移动和光谱仪采集的代码也在这里面
|
||
double pos = m_pathPlan->getRecordLineTableWidget()->item(lineNumber, 0)->text().toDouble();
|
||
m_yMotor->SettingSpeed(m_lManualSpeedOfYMotor);
|
||
m_yMotor->MoveToLocation(ui.ymotor_location_slider->getPositionPulse(pos));
|
||
m_timerMoveYmotor->start(500);
|
||
|
||
//将正在采集的行设置为红色
|
||
for (size_t i = 0; i < m_pathPlan->getRecordLineTableWidget()->columnCount(); i++)
|
||
{
|
||
m_pathPlan->getRecordLineTableWidget()->item(lineNumber, i)->setBackgroundColor(QColor(255, 0, 0));
|
||
}
|
||
}
|
||
else if (lineNumber == -1)
|
||
{
|
||
std::cout << "软件自动终止采集。" << std::endl;
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
|
||
//将y马达移动到第一条采集线的位置
|
||
double ymotorPositionOfLine1Tmp = m_pathPlan->getRecordLineTableWidget()->item(0, 0)->text().toDouble();
|
||
long ymotorPositionOfLine1 = ui.ymotor_location_slider->getPositionPulse(ymotorPositionOfLine1Tmp);
|
||
m_yMotor->SettingSpeed(m_lManualSpeedOfYMotor);
|
||
m_yMotor->MoveToLocation(ymotorPositionOfLine1);
|
||
m_timerYmotorLocationFeedBackAfterRecord->start(500);
|
||
|
||
fclose(m_hTimesFile);
|
||
}
|
||
else if (lineNumber == -2)
|
||
{
|
||
std::cout << "手动终止采集。" << std::endl;
|
||
|
||
//停止y马达运动
|
||
m_yMotor->StopMotormove();
|
||
|
||
fclose(m_hTimesFile);
|
||
}
|
||
}
|
||
|
||
void HPPA::onCreateTab(int trackNumber)
|
||
{
|
||
if (trackNumber >= 0)
|
||
{
|
||
QWidget * tabTmp = new QWidget();
|
||
|
||
QGridLayout *GridLayout = new QGridLayout();
|
||
GridLayout->addWidget(new ImageViewer(tabTmp));
|
||
|
||
tabTmp->setLayout(GridLayout);
|
||
|
||
ui.ImageViewerTabWidget->addTab(tabTmp, QString::number(trackNumber + 1));
|
||
|
||
ui.ImageViewerTabWidget->setCurrentIndex(trackNumber);
|
||
}
|
||
|
||
}
|
||
|
||
void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab,会调用onTabWidgetCurrentChanged函数!
|
||
{
|
||
if (index < 0)//当删除所有tab时,index=-1
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
//记录当前
|
||
m_TabWidgetCurrentIndex = index;
|
||
|
||
//获取绘图控件
|
||
QWidget* currentWidget = ui.ImageViewerTabWidget->widget(index);
|
||
QList<ImageViewer *> currentImageViewer = currentWidget->findChildren<ImageViewer *>();
|
||
|
||
//先disconnect然后再connect,否则每次切换一次都会connect一次,会累积connect很多次!
|
||
disconnect(currentImageViewer[0], SIGNAL(leftMouseButtonPressed(int, int)), this, SLOT(onLeftMouseButtonPressed(int, int)));
|
||
connect(currentImageViewer[0], SIGNAL(leftMouseButtonPressed(int, int)), this, SLOT(onLeftMouseButtonPressed(int, int)));
|
||
}
|
||
|
||
void HPPA::onActionOpenDirectory()
|
||
{
|
||
FileOperation * fileOperation = new FileOperation();
|
||
string directory = fileOperation->getDirectoryFromString();
|
||
|
||
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(directory)));
|
||
|
||
//QDesktopServices::openUrl(QUrl("file:C:\ASD", QUrl::TolerantMode));
|
||
|
||
|
||
////std::cout << "保存影像文件!" << std::endl;
|
||
//
|
||
//FileOperation * fileOperation = new FileOperation();
|
||
//string directory = fileOperation->getDirectoryFromString();
|
||
|
||
//string sourceImg = directory + "\\tmp_image";
|
||
//string sourceHdr = sourceImg + ".hdr";
|
||
//
|
||
|
||
//QString FileName2Save = QFileDialog::getSaveFileName(this,tr("save image"));
|
||
|
||
//if (FileName2Save.length()>0)
|
||
//{
|
||
// string targetImg = FileName2Save.toStdString();
|
||
// string targetHdr = targetImg + ".hdr";
|
||
|
||
// emit CopyFileThreadSignal(QString::fromStdString(sourceHdr), QString::fromStdString(targetHdr));
|
||
// emit CopyFileThreadSignal(QString::fromStdString(sourceImg), QString::fromStdString(targetImg));
|
||
|
||
// this->setEnabled(false);
|
||
//}
|
||
//else
|
||
//{
|
||
// std::cout << "文件名长度:" << FileName2Save.length() << std::endl;
|
||
//}
|
||
|
||
}
|
||
|
||
void HPPA::OnFramerateLineeditEditingFinished()
|
||
{
|
||
std::cout << "Lineedit设置帧率------------------------------------------" << std::endl;
|
||
m_Imager->setFramerate(this->ui.framerate_lineEdit->text().toDouble());
|
||
ui.FramerateSlider->setValue(ui.framerate_lineEdit->text().toDouble());
|
||
|
||
CalculateIntegratioinTimeRange();
|
||
}
|
||
|
||
void HPPA::OnFramerateSliderChanged(double framerate)
|
||
{
|
||
std::cout << "Slider设置帧率------------------------------------------" << std::endl;
|
||
m_Imager->setFramerate(this->ui.framerate_lineEdit->text().toDouble());
|
||
ui.framerate_lineEdit->setText(QString::number(framerate));
|
||
|
||
CalculateIntegratioinTimeRange();
|
||
}
|
||
|
||
void HPPA::OnIntegratioinTimeEditingFinished()
|
||
{
|
||
std::cout << "Lineedit设置积分时间------------------------------------------" << std::endl;
|
||
m_Imager->setIntegrationTime(this->ui.integratioin_time_lineEdit->text().toDouble());
|
||
ui.IntegratioinTimeSlider->setValue(ui.integratioin_time_lineEdit->text().toDouble());
|
||
}
|
||
|
||
void HPPA::OnIntegratioinTimeSliderChanged(double IntegratioinTime)
|
||
{
|
||
std::cout << "Slider设置积分时间------------------------------------------" << std::endl;
|
||
m_Imager->setIntegrationTime(IntegratioinTime);
|
||
ui.integratioin_time_lineEdit->setText(QString::number(IntegratioinTime));
|
||
}
|
||
|
||
void HPPA::OnGainEditingFinished()
|
||
{
|
||
m_Imager->setGain(this->ui.gain_lineEdit->text().toDouble());
|
||
ui.GainSlider->setValue(ui.gain_lineEdit->text().toDouble());
|
||
}
|
||
|
||
void HPPA::OnGainSliderChanged(double Gain)
|
||
{
|
||
m_Imager->setGain(this->ui.gain_lineEdit->text().toDouble());
|
||
ui.gain_lineEdit->setText(QString::number(Gain));
|
||
}
|
||
|
||
void HPPA::onLeftMouseButtonPressed(int x, int y)
|
||
{
|
||
try
|
||
{
|
||
//正在采集时,不能显示光谱曲线
|
||
if (m_RecordState % 2 == 1)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
FileOperation * fileOperation = new FileOperation();
|
||
string directory = fileOperation->getDirectoryFromString();
|
||
string imgPath = directory + "\\" + m_FilenameLineEdit->text().toStdString() + "_" + std::to_string(m_TabWidgetCurrentIndex + 1) + ".bil";
|
||
|
||
ImageReaderWriter *ImageReader = new ImageReaderWriter(imgPath.c_str());
|
||
|
||
|
||
if (x < 0 || x>ImageReader->getXCount() || y<0 || y>ImageReader->getyCount() - 1)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
float *data = ImageReader->ReadImage(x, y, 1, 1);
|
||
|
||
|
||
QLineSeries *series = new QLineSeries();
|
||
//series->clear();//////////////////////////////
|
||
|
||
for (size_t i = 0; i < m_Imager->getBandCount(); i++)
|
||
{
|
||
//malloc申请的内存用法1:可以当做数组用
|
||
series->append(m_Imager->getWavelengthAtBand(i), data[i]);
|
||
|
||
////malloc申请的内存用法2:指针存取
|
||
//series->append(m_Imager->getWavelengthAtBand(i), *data);
|
||
//data++;
|
||
}
|
||
|
||
QChart *chart = new QChart();
|
||
chart->legend()->hide();
|
||
chart->addSeries(series);
|
||
chart->createDefaultAxes();
|
||
//chart->setTitle("Simple line chart example");
|
||
|
||
m_chartView->setChart(chart);
|
||
//m_chartView->update();//////////////////////////////
|
||
|
||
|
||
/*std::cout << "x坐标:" << x << std::endl;
|
||
std::cout << "y坐标:" << y << std::endl;
|
||
std::cout << "文件名:" << imgPath << std::endl;*/
|
||
|
||
}
|
||
catch (const std::exception&)
|
||
{
|
||
std::cout << "显示光谱有错误!" << std::endl;
|
||
}
|
||
|
||
}
|
||
|
||
void HPPA::timerEvent(QTimerEvent *event)
|
||
{
|
||
try
|
||
{
|
||
if (m_xMotor == nullptr || m_yMotor == nullptr)
|
||
{
|
||
//qDebug() << "Motor pointer is null!!!!!";
|
||
|
||
xmotor_state_label1->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||
SetXMotorWidgetEnable(false);
|
||
|
||
ymotor_state_label1->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||
SetYMotorWidgetEnable(false);
|
||
|
||
return;
|
||
}
|
||
|
||
if (!m_xMotor->IsMotorInit)
|
||
{
|
||
//return;
|
||
|
||
}
|
||
ByteBack xMotorState = m_xMotor->GetState();//执行有问题
|
||
|
||
//std::cout << "------------------------------------------x马达速度:" << xMotorState.Speed << std::endl;
|
||
|
||
if (xMotorState.Speed == -1000000)
|
||
{
|
||
xmotor_state_label1->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||
SetXMotorWidgetEnable(false);
|
||
//std::cout << "xMotor: false!" << std::endl;
|
||
}
|
||
else
|
||
{
|
||
m_xConnectCount++;
|
||
if (m_xConnectCount == 1)//第一次连接马达,设置电流
|
||
{
|
||
m_xMotor->SendCommandtoMotor("cfg crn=3\n");
|
||
}
|
||
|
||
xmotor_state_label1->setStyleSheet("QLabel{background-color:rgb(0,255,0);}");
|
||
SetXMotorWidgetEnable(true);
|
||
//std::cout << "xMotor: ok!" << std::endl;
|
||
}
|
||
|
||
|
||
ByteBack yMotorState = m_yMotor->GetState();
|
||
|
||
//std::cout << "------------------------------------------马达速度:" << x.Speed << std::endl;
|
||
|
||
if (yMotorState.Speed == -1000000)
|
||
{
|
||
ymotor_state_label1->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||
SetYMotorWidgetEnable(false);
|
||
//std::cout << "yMotor: false!" << std::endl;
|
||
}
|
||
else
|
||
{
|
||
m_yConnectCount++;
|
||
if (m_yConnectCount == 1)//第一次连接马达,设置电流
|
||
{
|
||
m_yMotor->SendCommandtoMotor("cfg crn=2\n");
|
||
}
|
||
|
||
ymotor_state_label1->setStyleSheet("QLabel{background-color:rgb(0,255,0);}");
|
||
SetYMotorWidgetEnable(true);
|
||
//std::cout << "yMotor: ok!" << std::endl;
|
||
}
|
||
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
void HPPA::onxMotorLeft()
|
||
{
|
||
m_timerLocationFeedBackOfMotor_x_y->start(500);
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_xMotor->EnableMotro();
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
//m_xMotor->SettingSpeed(ui.xmotor_speed_lineEdit->text().toLong());
|
||
m_xMotor->MoveMotar(false);
|
||
}
|
||
|
||
void HPPA::onxMotorRight()
|
||
{
|
||
m_timerLocationFeedBackOfMotor_x_y->start(500);
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_xMotor->EnableMotro();
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
//m_xMotor->SettingSpeed(ui.xmotor_speed_lineEdit->text().toLong());
|
||
m_xMotor->MoveMotar(true);
|
||
}
|
||
|
||
void HPPA::onxMotorStop()
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_timerLocationFeedBackOfMotor_x_y->stop();
|
||
m_xMotor->StopMotormove();
|
||
}
|
||
|
||
void HPPA::onyMotorForward()
|
||
{
|
||
operateWidget = QObject::sender()->objectName();
|
||
|
||
m_timerLocationFeedBackOfMotor_x_y->start(500);
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_yMotor->EnableMotro();
|
||
m_yMotor->SettingSpeed(m_lManualSpeedOfYMotor);
|
||
//m_yMotor->SettingSpeed(ui.xmotor_speed_lineEdit->text().toLong());
|
||
m_yMotor->MoveMotar(true);
|
||
}
|
||
|
||
void HPPA::onyMotorBackward()
|
||
{
|
||
operateWidget = QObject::sender()->objectName();
|
||
|
||
m_timerLocationFeedBackOfMotor_x_y->start(500);
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_yMotor->EnableMotro();
|
||
m_yMotor->SettingSpeed(m_lManualSpeedOfYMotor);
|
||
//m_yMotor->SettingSpeed(ui.xmotor_speed_lineEdit->text().toLong());
|
||
m_yMotor->MoveMotar(false);
|
||
}
|
||
|
||
void HPPA::onyMotorStop()
|
||
{
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_timerLocationFeedBackOfMotor_x_y->stop();
|
||
m_yMotor->StopMotormove();
|
||
}
|
||
|
||
void HPPA::onMotorReset()
|
||
{
|
||
setMotorRange();
|
||
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_xMotor->SettingZeroLocation();
|
||
m_yMotor->SettingZeroLocation();
|
||
|
||
|
||
}
|
||
|
||
void HPPA::OnXmotorSpeedEditingFinished()
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_xMotor->SettingSpeed(ui.xmotor_speed_lineEdit->text().toLong());
|
||
}
|
||
|
||
|
||
bool HPPA::isMotorConnected(VinceControl *motor)
|
||
{
|
||
ByteBack x = motor->GetState();
|
||
|
||
//std::cout << "------------------------------------------马达速度:" << x.Speed << std::endl;
|
||
|
||
if (x.Speed == -1000000)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
void HPPA::SetXMotorWidgetEnable(bool enable)
|
||
{
|
||
ui.test_range_btn->setEnabled(enable);
|
||
ui.motor_reset_btn->setEnabled(enable);
|
||
|
||
ui.xmotor_left_btn->setEnabled(enable);
|
||
ui.xmotor_right_btn->setEnabled(enable);
|
||
ui.xmotor_speed_lineEdit->setEnabled(enable);
|
||
ui.xmotor_speed_slider->setEnabled(enable);
|
||
ui.xmotor_location_lineEdit->setEnabled(enable);
|
||
ui.xmotor_location_slider->setEnabled(enable);
|
||
}
|
||
|
||
void HPPA::SetYMotorWidgetEnable(bool enable)
|
||
{
|
||
ui.test_range_btn->setEnabled(enable);
|
||
ui.motor_reset_btn->setEnabled(enable);
|
||
|
||
ui.ymotor_forward_btn->setEnabled(enable);
|
||
ui.ymotor_backward_btn->setEnabled(enable);
|
||
ui.ymotor_location_lineEdit->setEnabled(enable);
|
||
ui.ymotor_location_slider->setEnabled(enable);
|
||
}
|
||
|
||
void HPPA::setMotorRange()
|
||
{
|
||
try
|
||
{
|
||
//将x马达量程记录到文件,以便后面使用 → 不用每次都测试量程,这样很浪费时间
|
||
float xMotorRange;
|
||
float yMotorRange;
|
||
|
||
float lead;//导程
|
||
float stepAnglemar;//步距角
|
||
float scaleFactor;//因机械装置的原因引入的缩放因子
|
||
int subdivisionMultiples;//细分数
|
||
|
||
mConfigfile.getXMotorParm(stepAnglemar, lead, subdivisionMultiples, scaleFactor, xMotorRange);
|
||
mConfigfile.getYMotorParm(stepAnglemar, lead, subdivisionMultiples, scaleFactor, yMotorRange);
|
||
|
||
|
||
//std::cout << "xMotorRange:" << xMotorRange << std::endl;
|
||
//std::cout << "yMotorRange:" << yMotorRange << std::endl;
|
||
|
||
|
||
//设置x马达范围
|
||
ui.xmotor_location_slider->setMaximum(xMotorRange);
|
||
ui.xmotor_max_location_label->setText(QString::number(ui.xmotor_location_slider->maximum()));
|
||
//设置y马达范围
|
||
ui.ymotor_location_slider->setMaximum(yMotorRange);
|
||
ui.ymotor_max_location_label->setText(QString::number(ui.ymotor_location_slider->maximum()));
|
||
|
||
|
||
QRectF rect = ui.graphicsView->viewport()->rect();
|
||
widthScale = rect.width() / xMotorRange;//重新设置sceneRect的宽度缩放系数(x)
|
||
heightScale = rect.height() / yMotorRange;//重新设置sceneRect的高度缩放系数(y)
|
||
|
||
|
||
ui.graphicsView->setSceneRect();
|
||
}
|
||
catch (...)
|
||
{
|
||
QMessageBox msgBox;
|
||
msgBox.setText(QString::fromLocal8Bit("请进行马达量程测量!"));
|
||
msgBox.exec();
|
||
}
|
||
}
|
||
|
||
void HPPA::setImagerSimulationPos(double x, double y)
|
||
{
|
||
x = widthScale * x;
|
||
y = heightScale * y;
|
||
ui.graphicsView->imager->setPos(x, y);
|
||
}
|
||
|
||
void HPPA::ontimerLocationFeedBackOfMotor_x_y()
|
||
{
|
||
//std::cout << "------------------------------------------" << std::endl;
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ByteBack xMotorState = m_xMotor->GetState();
|
||
|
||
//作用1:当手动控制/采集控制x马达运动时(左/右),将自动的调整马达位置slider
|
||
if (xMotorState.Speed != 0)
|
||
{
|
||
double newPos = ui.xmotor_location_slider->getDistanceFromPulse(xMotorState.Location);
|
||
|
||
ui.xmotor_location_slider->setValue(newPos, false);
|
||
setImagerSimulationPos(newPos, ui.ymotor_location_slider->value());
|
||
|
||
|
||
QApplication::processEvents();
|
||
}
|
||
|
||
|
||
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ByteBack yMotorState = m_yMotor->GetState();
|
||
|
||
//作用2:当手动控制y马达运动时(前/后),将自动的调整马达位置slider
|
||
if (yMotorState.Speed != 0)
|
||
{
|
||
double newPos = ui.ymotor_location_slider->getDistanceFromPulse(yMotorState.Location);
|
||
|
||
ui.ymotor_location_slider->setValue(newPos, false);
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), newPos);
|
||
|
||
QApplication::processEvents();
|
||
}
|
||
|
||
}
|
||
|
||
void HPPA::ontimerYmotorLocationFeedBackAfterRecord()
|
||
{
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ByteBack yMotorState = m_yMotor->GetState();
|
||
|
||
//将马达位置反馈到slider
|
||
if (yMotorState.Speed != 0)
|
||
{
|
||
double newPos = ui.ymotor_location_slider->getDistanceFromPulse(yMotorState.Location);
|
||
|
||
ui.ymotor_location_slider->setValue(newPos, false);
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), newPos);
|
||
|
||
QApplication::processEvents();
|
||
}
|
||
else//调用此函数不能精确的返回采集前的位置;需要通过采集前记录的精确位置来设置
|
||
{
|
||
m_timerYmotorLocationFeedBackAfterRecord->stop();
|
||
|
||
double ymotorPositionOfLine1Tmp = m_pathPlan->getRecordLineTableWidget()->item(0, 0)->text().toDouble();//ymotorPositionOfLine1
|
||
|
||
ui.ymotor_location_slider->setValue(ymotorPositionOfLine1Tmp, false);
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), ymotorPositionOfLine1Tmp);
|
||
}
|
||
}
|
||
|
||
void HPPA::OnXmotorSpeedLineeditEditingFinished()
|
||
{
|
||
ui.xmotor_speed_slider->setValue(ui.xmotor_speed_lineEdit->text().toDouble());
|
||
}
|
||
|
||
void HPPA::OnXmotorSpeedSliderChanged(double speed)
|
||
{
|
||
ui.xmotor_speed_lineEdit->setText(QString::number(speed));
|
||
}
|
||
|
||
void HPPA::OnXmotorLocationLineeditEditingFinished()
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ui.xmotor_location_slider->setValue(ui.xmotor_location_lineEdit->text().toDouble());
|
||
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), ui.ymotor_location_slider->value());
|
||
|
||
m_xMotor->MoveToLocation(ui.xmotor_location_slider->OriginalValue());
|
||
}
|
||
|
||
void HPPA::OnXmotorLocationSliderChanged(double location)
|
||
{
|
||
ui.xmotor_location_lineEdit->setText(QString::number(location));
|
||
}
|
||
|
||
void HPPA::OnXmotorLocationSliderReleased()
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
m_xMotor->MoveToLocation(ui.xmotor_location_slider->OriginalValue());
|
||
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), ui.ymotor_location_slider->value());
|
||
}
|
||
|
||
void HPPA::OnYmotorLocationLineeditEditingFinished()
|
||
{
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ui.ymotor_location_slider->setValue(ui.ymotor_location_lineEdit->text().toDouble());
|
||
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), ui.ymotor_location_slider->value());
|
||
|
||
m_yMotor->MoveToLocation(ui.ymotor_location_slider->OriginalValue());
|
||
}
|
||
|
||
void HPPA::OnYmotorLocationSliderChanged(double location)
|
||
{
|
||
ui.ymotor_location_lineEdit->setText(QString::number(location));
|
||
}
|
||
|
||
void HPPA::OnYmotorLocationSliderReleased()
|
||
{
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_yMotor->SettingSpeed(m_lManualSpeedOfYMotor);
|
||
m_yMotor->MoveToLocation(ui.ymotor_location_slider->OriginalValue());
|
||
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), ui.ymotor_location_slider->value());
|
||
}
|
||
|
||
void HPPA::ontestRangeOfMotor_x_y()
|
||
{
|
||
//测量x马达量程
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_xMotor->SettingZeroLocation();//先移动到0位置的接近开关,并设置位置为0
|
||
m_timerTestRangeOfxMotor->start(500);
|
||
|
||
//测量y马达量程
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_yMotor->SettingZeroLocation();
|
||
m_timerTestRangeOfyMotor->start(500);
|
||
}
|
||
|
||
void HPPA::ontimerTestRangeOfxMotor()
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
qDebug() << "x TestRangeOfxMotor: x motor is bad+++++++++++++++++++++++++++++++++++++++++++";
|
||
return;
|
||
}
|
||
//qDebug() << "x TestRangeOfxMoto: start+++++++++++++++++++++++++++++++++++++++++++";
|
||
|
||
ByteBack MotorState = m_xMotor->GetState();
|
||
//std::cout << "x马达速度:" << MotorState.Speed << std::endl;
|
||
|
||
|
||
if (MotorState.Speed == 0 && MotorState.Location == 0)//处于位置为0的地方
|
||
{
|
||
qDebug() << "x TestRangeOfxMotor: speed is 0,reach to original point+++++++++++++++++++++++++++++++++++++++++++";
|
||
|
||
m_xMotor->EnableMotro();
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
m_xMotor->MoveMotar(true);//向左移动
|
||
}
|
||
|
||
if (MotorState.Speed == 0 && MotorState.Location != 0)//处于位置最大的地方
|
||
{
|
||
qDebug() << "x TestRangeOfxMotor: speed is 0, reach to most far point, completed+++++++++++++++++++++++++++++++++++++++++++";
|
||
|
||
double maxDistance = ui.xmotor_location_slider->getDistanceFromPulse(MotorState.Location);
|
||
|
||
m_xMotor->MoveToLocation(0);
|
||
m_timerTestRangeOfxMotor->stop();
|
||
|
||
mConfigfile.setMaxRange(maxDistance, "x");
|
||
|
||
ui.xmotor_location_slider->setMaximum(maxDistance);
|
||
ui.xmotor_max_location_label->setText(QString::number(ui.xmotor_location_slider->maximum()));
|
||
|
||
//重新设置sceneRect的宽度缩放系数(x)
|
||
QRectF rect = ui.graphicsView->viewport()->rect();
|
||
widthScale = rect.width() / maxDistance;
|
||
ui.graphicsView->setSceneRect();
|
||
}
|
||
}
|
||
|
||
void HPPA::ontimerTestRangeOfyMotor()
|
||
{
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
qDebug() << "y TestRangeOfxMotor: y motor is bad+++++++++++++++++++++++++++++++++++++++++++";
|
||
return;
|
||
}
|
||
|
||
ByteBack MotorState = m_yMotor->GetState();
|
||
int a = 1;
|
||
//qDebug() << "y TestRangeOfyMoto: start";
|
||
|
||
if (MotorState.Speed == 0 && MotorState.Location == 0)//处于位置为0的地方
|
||
{
|
||
qDebug() << "y TestRangeOfyMotor: speed is 0,reach to original point+++++++++++++++++++++++++++++++++++++++++++";
|
||
|
||
m_yMotor->EnableMotro();
|
||
m_yMotor->SettingSpeed(m_lManualSpeedOfYMotor);
|
||
m_yMotor->MoveMotar(true);//向前移动
|
||
}
|
||
|
||
if (MotorState.Speed == 0 && MotorState.Location != 0)//处于位置最大的地方
|
||
{
|
||
qDebug() << "y TestRangeOfyMotor: speed is 0, reach to most far point, completed+++++++++++++++++++++++++++++++++++++++++++";
|
||
|
||
double maxDistance = ui.ymotor_location_slider->getDistanceFromPulse(MotorState.Location);
|
||
|
||
m_yMotor->MoveToLocation(0);
|
||
m_timerTestRangeOfyMotor->stop();
|
||
|
||
//将y马达量程记录到文件,以便后面使用 → 不用每次都测试量程,这样很浪费时间
|
||
mConfigfile.setMaxRange(maxDistance, "y");
|
||
|
||
ui.ymotor_location_slider->setMaximum(maxDistance);
|
||
ui.ymotor_max_location_label->setText(QString::number(ui.ymotor_location_slider->maximum()));
|
||
|
||
//重新设置sceneRect的高度缩放系数(y)
|
||
QRectF rect = ui.graphicsView->viewport()->rect();
|
||
heightScale = rect.height() / maxDistance;
|
||
ui.graphicsView->setSceneRect();
|
||
}
|
||
}
|
||
|
||
void HPPA::ontimerMoveXmotor()
|
||
{
|
||
//std::cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << std::endl;
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ByteBack MotorState = m_xMotor->GetState();
|
||
//获取系统时间和x马达的位置,并发送
|
||
long long timeOs = getNanosecondsSinceMidnight();
|
||
BroadcastXMotorPosSignal(timeOs, MotorState.Location);
|
||
fprintf(m_hTimesFile, "%lld,%d\n", timeOs, MotorState.Location);
|
||
|
||
//将x马达的位置反馈到slider上
|
||
if (MotorState.Speed != 0)
|
||
{
|
||
double newPos = ui.xmotor_location_slider->getDistanceFromPulse(MotorState.Location);
|
||
|
||
ui.xmotor_location_slider->setValue(newPos, false);
|
||
setImagerSimulationPos(newPos, ui.ymotor_location_slider->value());
|
||
|
||
QApplication::processEvents();
|
||
}
|
||
|
||
//采集结束,x马达返回初始位置(开始采集前记录的位置:m_lXmotorLocationOfStartRecord)
|
||
if (MotorState.Speed == 0 && MotorState.Location != m_lXmotorLocationOfStartRecord)//x马达位置处于最大值(接近开关),帧数没有采集完
|
||
{
|
||
//光谱仪停止采集
|
||
m_Imager->setRecordControlState(false);
|
||
|
||
//x马达返回采集前的位置
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
m_xMotor->MoveToLocation(m_lXmotorLocationOfStartRecord);
|
||
|
||
//qDebug() << "x马达位置还原:x马达位置处于最大值(接近开关),帧数没有采集完,相机停止采集。";
|
||
qDebug() << "11111111111111111111111111111111111111111111111111";
|
||
}
|
||
if (!m_Imager->getRecordControlState())//当相机停止采集,需要马达配合回到初始位置:(1)点击停止采集;(2)帧数采集完了,马达还在运动
|
||
{
|
||
//x马达返回采集前的位置
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
m_xMotor->MoveToLocation(m_lXmotorLocationOfStartRecord);
|
||
|
||
//qDebug() << "x马达位置还原:(1)点击停止相机采集;(2)帧数采集完了,马达还在运动。";
|
||
qDebug() << "222222222222222222222222222222222222222222222222222222";
|
||
}
|
||
|
||
|
||
|
||
//进行下一条采集线的采集过程
|
||
if (MotorState.Speed == 0 && MotorState.Location == m_lXmotorLocationOfStartRecord//当x马达返回初始位置
|
||
|| MotorState.Location - m_lXmotorLocationOfStartRecord < 300)//当采集前位置为0时,就需要这个条件
|
||
{
|
||
//停止
|
||
m_timerMoveXmotor->stop();
|
||
|
||
//将采集完成的行设置为绿色
|
||
for (size_t j = 0; j < m_pathPlan->getRecordLineTableWidget()->columnCount(); j++)
|
||
{
|
||
m_pathPlan->getRecordLineTableWidget()->item(m_numberOfRecording, j)->setBackgroundColor(QColor(0, 255, 0));
|
||
}
|
||
|
||
//准确设置x马达slider的位置
|
||
double pos = ui.xmotor_location_slider->getDistanceFromPulse(m_lXmotorLocationOfStartRecord);
|
||
ui.xmotor_location_slider->setValue(pos, false);
|
||
setImagerSimulationPos(pos, ui.ymotor_location_slider->value());
|
||
|
||
//执行下一条航线
|
||
m_ForLoopControl->m_boolRecordNextLine = true;
|
||
}
|
||
|
||
//std::cout << "初始位置为:" << m_lXmotorLocationOfStartRecord << std::endl;
|
||
//std::cout << "差距为:" << MotorState.Location - m_lXmotorLocationOfStartRecord << std::endl;
|
||
}
|
||
|
||
void HPPA::ontimerMoveYmotor()
|
||
{
|
||
//std::cout << "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" << std::endl;
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
ByteBack MotorState = m_yMotor->GetState();
|
||
|
||
//将y马达的位置反馈到slider上
|
||
if (MotorState.Speed != 0)
|
||
{
|
||
double newPos = ui.ymotor_location_slider->getDistanceFromPulse(MotorState.Location);
|
||
//std::cout << "y马达位置:" << newPos << std::endl;
|
||
|
||
ui.ymotor_location_slider->setValue(newPos, false);
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), newPos);
|
||
|
||
QApplication::processEvents();
|
||
}
|
||
else if (MotorState.Speed == 0)
|
||
{
|
||
//停止调用本函数
|
||
m_timerMoveYmotor->stop();
|
||
|
||
//准确设置y马达slider的位置
|
||
double pos = m_pathPlan->getRecordLineTableWidget()->item(m_numberOfRecording, 0)->text().toDouble();
|
||
ui.ymotor_location_slider->setValue(pos, false);
|
||
setImagerSimulationPos(ui.xmotor_location_slider->value(), pos);
|
||
|
||
//当点击开始采集后,当y马达前往第一条采集线的途中,点击了停止采集
|
||
if (m_RecordState % 2 == 0)
|
||
{
|
||
//
|
||
for (size_t j = 0; j < m_pathPlan->getRecordLineTableWidget()->columnCount(); j++)
|
||
{
|
||
m_pathPlan->getRecordLineTableWidget()->item(m_numberOfRecording, j)->setBackgroundColor(QColor(240, 240, 240));
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
//移动x马达
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
m_xMotor->EnableMotro();
|
||
m_lXmotorLocationOfStartRecord = m_xMotor->GetLocationNow();//记录当前马达位置
|
||
m_xMotor->SettingSpeed(ui.xmotor_speed_slider->OriginalValue());//开始采集时才设置光谱仪速度 → 优点:隔离了采集时速度和其他速度
|
||
|
||
|
||
double xMaxPositionTmp = m_pathPlan->getRecordLineTableWidget()->item(m_numberOfRecording, 1)->text().toDouble();
|
||
long xMaxPosition = ui.xmotor_location_slider->getPositionPulse(xMaxPositionTmp);
|
||
m_xMotor->MoveToLocation(xMaxPosition);
|
||
m_timerMoveXmotor->start(500);
|
||
|
||
|
||
//开始采集影像
|
||
m_Imager->setFrameNumber(this->frame_number->text().toInt());
|
||
|
||
emit StartRecordSignal();//发射开始采集信号
|
||
}
|
||
}
|
||
|
||
void HPPA::onimagerSimulatorMove(int x, int y)
|
||
{
|
||
if (isMotorConnected(m_xMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
//std::cout << "x马达断电后还能正常发送命令+++++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||
|
||
double xLocatioin = abs(x) / widthScale;//单位为cm的真实距离
|
||
ui.xmotor_location_slider->setValue(xLocatioin, false);
|
||
|
||
double xx = ui.xmotor_location_slider->OriginalValue();//单位为脉冲的真实距离
|
||
m_xMotor->MoveToLocation(xx);
|
||
|
||
|
||
if (isMotorConnected(m_yMotor))
|
||
{
|
||
return;
|
||
}
|
||
|
||
//std::cout << "y马达断电后还能正常发送命令+++++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||
|
||
double yLocatioin = abs(y) / heightScale;//单位为cm的真实距离
|
||
ui.ymotor_location_slider->setValue(yLocatioin, false);
|
||
|
||
double yy = ui.ymotor_location_slider->OriginalValue();//单位为脉冲的真实距离
|
||
|
||
//std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" << std::endl;
|
||
m_yMotor->MoveToLocation(yy);
|
||
//std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" << std::endl;
|
||
|
||
}
|
||
|
||
void HPPA::OnSendLogToCallClass(QString str)
|
||
{
|
||
qDebug() << str;
|
||
}
|
||
|
||
void HPPA::onPlotRgbImage()
|
||
{
|
||
//std::cout << "显示视频+++++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||
QPixmap pixmap = QPixmap::fromImage(m_RgbCamera->m_qImage);
|
||
|
||
int width = ui.cam_label->width();
|
||
int height = ui.cam_label->height();
|
||
QPixmap fitpixmap = pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); //按比例缩放
|
||
|
||
|
||
ui.cam_label->setPixmap(fitpixmap);
|
||
}
|
||
|
||
void HPPA::onCloseRgbCamera()
|
||
{
|
||
//std::cout << "关闭视频+++++++++++++++++++++++++++++++++++++++++++" << std::endl;
|
||
m_RgbCamera->CloseCamera();
|
||
}
|
||
|
||
void HPPA::onClearLabel()
|
||
{
|
||
ui.cam_label->clear();
|
||
ui.cam_label->setText("closed");
|
||
}
|
||
|
||
void HPPA::onCopyFinished()
|
||
{
|
||
this->setEnabled(true);
|
||
}
|
||
|
||
void HPPA::getRequest(QString str)
|
||
{
|
||
QNetworkRequest request;
|
||
QNetworkAccessManager* naManager = new QNetworkAccessManager(this);
|
||
QMetaObject::Connection connRet = QObject::connect(naManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*)));
|
||
Q_ASSERT(connRet);
|
||
|
||
request.setUrl(QUrl(str));
|
||
QNetworkReply* reply = naManager->get(request);
|
||
}
|
||
|
||
void HPPA::newMotor()
|
||
{
|
||
if (m_xMotor != nullptr && m_yMotor != nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
//马达
|
||
m_xMotor = new VinceControl(NETTCP, 6002);//相机轴
|
||
m_yMotor = new VinceControl(NETTCP, 6001);//原本:6001;韩工测试:6003
|
||
|
||
m_pathPlan->setMotor(m_xMotor, m_yMotor);
|
||
QString imagerSelected = mImagerGroup->checkedAction()->objectName();
|
||
if (imagerSelected == "mActionPica_NIR")
|
||
{
|
||
connect(m_xMotor, SIGNAL(newTCPConnection(VinceControl*)), this, SLOT(setMotorParamMicroscope(VinceControl*)));
|
||
connect(m_yMotor, SIGNAL(newTCPConnection(VinceControl*)), this, SLOT(setMotorParamMicroscope(VinceControl*)));
|
||
}
|
||
|
||
connect(m_xMotor, SIGNAL(newTCPConnection(VinceControl*)), this, SLOT(setXMotorParamFromCfgFile(VinceControl*)));
|
||
connect(m_yMotor, SIGNAL(newTCPConnection(VinceControl*)), this, SLOT(setYMotorParamFromCfgFile(VinceControl*)));
|
||
|
||
m_xConnectCount = 0;
|
||
m_yConnectCount = 0;
|
||
|
||
|
||
//connect(m_xMotor, SIGNAL(SendLogToCallClass(QString)), this, SLOT(OnSendLogToCallClass(QString)));
|
||
//connect(m_yMotor, SIGNAL(SendLogToCallClass(QString)), this, SLOT(OnSendLogToCallClass(QString)));
|
||
}
|
||
|
||
void HPPA::setMotorParamMicroscope(VinceControl* motor)
|
||
{
|
||
//显微镜nir的特殊配置
|
||
QString commonstr;
|
||
QByteArray buf;
|
||
|
||
commonstr = "cfg msr=2\n";
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
commonstr = "cfg msv=1\n";
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
|
||
commonstr = "cfg psr=1\n";
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
commonstr = "cfg psv=1\n";
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
|
||
commonstr = "cfg zsd=-3000\n";//设置归零速度和方向
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
|
||
commonstr = "cfg snr=1\n";//设置归零传感器
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
}
|
||
|
||
void HPPA::setXMotorParamFromCfgFile(VinceControl* motor)
|
||
{
|
||
float lead;
|
||
float stepAnglemar;
|
||
float scaleFactor;
|
||
int subdivisionMultiples;
|
||
float maxRange;
|
||
mConfigfile.getXMotorParm(stepAnglemar, lead, subdivisionMultiples, scaleFactor, maxRange);
|
||
|
||
QString commonstr;
|
||
QByteArray buf;
|
||
|
||
commonstr = "cfg mcs=" + QString::number(subdivisionMultiples) + "\n";
|
||
std::string tmp = commonstr.toStdString();
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
}
|
||
|
||
void HPPA::setYMotorParamFromCfgFile(VinceControl* motor)
|
||
{
|
||
float lead;
|
||
float stepAnglemar;
|
||
float scaleFactor;
|
||
int subdivisionMultiples;
|
||
float maxRange;
|
||
mConfigfile.getYMotorParm(stepAnglemar, lead, subdivisionMultiples, scaleFactor, maxRange);
|
||
|
||
QString commonstr;
|
||
QByteArray buf;
|
||
|
||
commonstr = "cfg mcs=" + QString::number(subdivisionMultiples) + "\n";
|
||
motor->SendCommandtoMotor(commonstr, "non");
|
||
motor->GetCommonRetrun(buf);
|
||
}
|
||
|
||
void HPPA::deleteMotor()
|
||
{
|
||
disconnect(m_xMotor, SIGNAL(SendLogToCallClass(QString)), this, SLOT(OnSendLogToCallClass(QString)));
|
||
disconnect(m_yMotor, SIGNAL(SendLogToCallClass(QString)), this, SLOT(OnSendLogToCallClass(QString)));
|
||
|
||
delete m_xMotor;
|
||
delete m_yMotor;
|
||
|
||
m_xMotor = nullptr;
|
||
m_yMotor = nullptr;
|
||
|
||
xmotor_state_label1->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||
ymotor_state_label1->setStyleSheet("QLabel{background-color:rgb(255,0,0);}");
|
||
}
|
||
|
||
void HPPA::requestFinished(QNetworkReply* reply) {
|
||
// 获取http状态码
|
||
QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||
if (statusCode.isValid())
|
||
qDebug() << "status code=" << statusCode.toInt();
|
||
|
||
QVariant reason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
|
||
if (reason.isValid())
|
||
qDebug() << "reason=" << reason.toString();
|
||
|
||
QNetworkReply::NetworkError err = reply->error();
|
||
if (err != QNetworkReply::NoError) {
|
||
qDebug() << "Failed: " << reply->errorString();
|
||
}
|
||
else {
|
||
// 获取返回内容
|
||
qDebug() << reply->readAll();
|
||
}
|
||
}
|
||
|
||
void HPPA::onExit()
|
||
{
|
||
this->close();
|
||
}
|
||
|
||
void HPPA::onconnect()
|
||
{
|
||
if (m_Imager != nullptr)
|
||
{
|
||
//std::cout << "相机已经连接!" << std::endl;
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
//采集影像线程:放入新线程中采集以免在采集过程中界面卡死:https://www.cnblogs.com/xia-weiwen/p/10306089.html
|
||
m_RecordThread = new QThread();
|
||
|
||
//根据选择的相机类型创建对象mImagerGroup
|
||
QString imagerSelected = mImagerGroup->checkedAction()->objectName();
|
||
if (imagerSelected == "mActionPica_L")
|
||
{
|
||
m_Imager = new ResononPicaLImager();
|
||
}
|
||
else if (imagerSelected == "mActionPica_NIR")
|
||
{
|
||
m_Imager = new ResononNirImager();
|
||
}
|
||
else if (imagerSelected == "mActionPika_XC2")
|
||
{
|
||
m_Imager = new ResononPicaLImager();
|
||
}
|
||
else if (imagerSelected == "mActionCorning_410")
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
QMessageBox msgBox;
|
||
msgBox.setText(QString::fromLocal8Bit("请选择相机!"));
|
||
msgBox.exec();
|
||
|
||
return;
|
||
}
|
||
|
||
m_Imager->moveToThread(m_RecordThread);
|
||
m_RecordThread->start();
|
||
|
||
m_Imager->connect_imager(frame_number->text().toInt());
|
||
m_Imager->setFileName2Save(m_FilenameLineEdit->text().toStdString());
|
||
connect(m_Imager, SIGNAL(PlotSignal()), this, SLOT(onPlotHyperspectralImageRgbImage()));
|
||
connect(m_Imager, SIGNAL(RecordFinishedSignal_WhenFrameNumberMeet()), this, SLOT(onRecordFinishedSignal_WhenFrameNumberMeet()));
|
||
connect(m_Imager, SIGNAL(RecordFinishedSignal_WhenFrameNumberNotMeet()), this, SLOT(onRecordFinishedSignal_WhenFrameNumberNotMeet()));
|
||
connect(m_Imager, SIGNAL(SpectralSignal(int)), this, SLOT(PlotSpectral(int)));
|
||
//connect(m_Imager, SIGNAL(testImagerStatus()), this, SLOT(testImagerStatus()));
|
||
|
||
newMotor();//会根据不同的相机类型,为线性平台设置不同的参数,所以在连接相机后创建马达;
|
||
|
||
|
||
//文件拷贝
|
||
m_CopyFileThread = new QThread();
|
||
m_FileOperation = new FileOperation();
|
||
m_FileOperation->moveToThread(m_CopyFileThread);
|
||
m_CopyFileThread->start();
|
||
connect(this, SIGNAL(CopyFileThreadSignal(QString, QString)), m_FileOperation, SLOT(copyFile(QString, QString)));
|
||
connect(m_FileOperation, SIGNAL(CopyFinishedSignal()), this, SLOT(onCopyFinished()));
|
||
|
||
//检测光谱仪连接状态
|
||
m_TestImagerStausThread = new WorkerThread(m_Imager);
|
||
|
||
|
||
|
||
connect(this->ui.action_auto_exposure, SIGNAL(triggered()), this, SLOT(onAutoExposure()));
|
||
connect(this->ui.action_focus, SIGNAL(triggered()), this, SLOT(onFocus1()));
|
||
connect(this, SIGNAL(StartFocusSignal()), m_Imager, SLOT(focus()));
|
||
connect(this->ui.action_dark, SIGNAL(triggered()), this, SLOT(onDark()));
|
||
connect(this->ui.action_reference, SIGNAL(triggered()), this, SLOT(onReference()));
|
||
|
||
connect(this->ui.action_start_recording, SIGNAL(triggered()), this, SLOT(onStartRecordStep1()));
|
||
connect(this, SIGNAL(StartLoopSignal()), m_ForLoopControl, SLOT(startLoop()));
|
||
connect(this, SIGNAL(StartRecordSignal()), m_Imager, SLOT(start_record()));
|
||
connect(this, SIGNAL(RecordWhiteSignal()), m_Imager, SLOT(record_white()));
|
||
connect(this, SIGNAL(RecordDarlSignal()), m_Imager, SLOT(record_dark()));
|
||
connect(m_Imager, SIGNAL(RecordWhiteFinishSignal()), this, SLOT(recordWhiteFinish()));
|
||
connect(m_Imager, SIGNAL(RecordDarlFinishSignal()), this, SLOT(recordDarkFinish()));
|
||
|
||
connect(this->ui.actionOpenDirectory, SIGNAL(triggered()), this, SLOT(onActionOpenDirectory()));
|
||
|
||
|
||
|
||
|
||
connect(this->ui.framerate_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnFramerateLineeditEditingFinished()));
|
||
connect(this->ui.FramerateSlider, SIGNAL(valueChanged(double)), this, SLOT(OnFramerateSliderChanged(double)));
|
||
connect(this->ui.integratioin_time_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnIntegratioinTimeEditingFinished()));
|
||
connect(this->ui.IntegratioinTimeSlider, SIGNAL(valueChanged(double)), this, SLOT(OnIntegratioinTimeSliderChanged(double)));
|
||
connect(this->ui.gain_lineEdit, SIGNAL(editingFinished()), this, SLOT(OnGainEditingFinished()));
|
||
connect(this->ui.GainSlider, SIGNAL(valueChanged(double)), this, SLOT(OnGainSliderChanged(double)));
|
||
|
||
|
||
//相机参数控件设置为可用 + 输入控制
|
||
frame_number->setEnabled(true);
|
||
|
||
ui.framerate_lineEdit->setEnabled(true);
|
||
ui.integratioin_time_lineEdit->setEnabled(true);
|
||
ui.gain_lineEdit->setEnabled(true);
|
||
|
||
ui.FramerateSlider->setEnabled(true);
|
||
ui.IntegratioinTimeSlider->setEnabled(true);
|
||
ui.GainSlider->setEnabled(true);
|
||
|
||
/*QRegExp rx("\\d{0,3}[1-9]$");
|
||
ui.framerate_lineEdit->setValidator(new QRegExpValidator(rx));
|
||
frame_number->setValidator(new QRegExpValidator(rx));
|
||
|
||
ui.integratioin_time_lineEdit->setValidator(new QRegExpValidator(rx));
|
||
ui.gain_lineEdit->setValidator(new QRegExpValidator(rx));*/
|
||
|
||
//获取相机参数并显示到界面中
|
||
ui.framerate_lineEdit->setText(QString::number(m_Imager->getFramerate(), 10, 2));
|
||
ui.FramerateSlider->setValue(m_Imager->getFramerate(), true);
|
||
CalculateIntegratioinTimeRange();
|
||
|
||
ui.integratioin_time_lineEdit->setText(QString::number(m_Imager->getIntegrationTime(), 10, 2));
|
||
ui.IntegratioinTimeSlider->setValue(m_Imager->getIntegrationTime());
|
||
|
||
ui.gain_lineEdit->setText(QString::number(m_Imager->getGain(), 10, 2));
|
||
ui.GainSlider->setValue(m_Imager->getGain());
|
||
}
|
||
catch (std::exception const& e)
|
||
{
|
||
std::cerr << "Error: " << e.what() << std::endl;
|
||
|
||
delete m_Imager;
|
||
m_Imager = nullptr;
|
||
|
||
QMessageBox msgBox;
|
||
msgBox.setText(QString::fromLocal8Bit("请连接相机!"));
|
||
msgBox.exec();
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
void HPPA::testImagerStatus()
|
||
{
|
||
m_TestImagerStausThread->start();
|
||
}
|
||
|
||
void HPPA::onAutoExposure()
|
||
{
|
||
double ReturnedExposureTime = m_Imager->auto_exposure();
|
||
|
||
//将自动曝光所得的值显示到界面
|
||
ui.IntegratioinTimeSlider->setValue(ReturnedExposureTime, false);
|
||
|
||
|
||
ui.mainToolBar->widgetForAction(ui.action_auto_exposure)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
//ui.mainToolBar->widgetForAction(ui.action_auto_exposure)->setStyleSheet("QLineEdit{background-color:rgb(255,255,255);}");
|
||
}
|
||
|
||
void HPPA::onFocus1()
|
||
{
|
||
focusWindow* w = new focusWindow(this, m_Imager);
|
||
connect(w, SIGNAL(StartManualFocusSignal(int)), this, SLOT(onFocus2(int)));
|
||
|
||
//w->setModal(true);//设置窗口为模态:只能操作当前窗口
|
||
w->show();
|
||
w->exec();
|
||
|
||
//disconnect(w, SIGNAL(StartManualFocusSignal(int)), this, SLOT(onFocus2(int)));
|
||
}
|
||
|
||
void HPPA::onFocus2(int command)
|
||
{
|
||
if (command == 1)
|
||
{
|
||
//创建影像显示窗口
|
||
QWidget * tabTmp = new QWidget();
|
||
|
||
QGridLayout *GridLayout = new QGridLayout();
|
||
GridLayout->addWidget(new ImageViewer(tabTmp));
|
||
|
||
tabTmp->setLayout(GridLayout);
|
||
|
||
ui.ImageViewerTabWidget->addTab(tabTmp, QString::fromLocal8Bit("调焦"));
|
||
|
||
//ui.ImageViewerTabWidget->setCurrentIndex(trackNumber);
|
||
ui.ImageViewerTabWidget->setCurrentWidget(tabTmp);
|
||
|
||
|
||
//开始调焦
|
||
emit StartFocusSignal();
|
||
}
|
||
else if (command == 0)
|
||
{
|
||
m_Imager->setFocusControlState(false);
|
||
}
|
||
}
|
||
|
||
void HPPA::onAbout()
|
||
{
|
||
aboutWindow about;
|
||
about.show();
|
||
about.exec();
|
||
}
|
||
|
||
void HPPA::onDark()
|
||
{
|
||
QMessageBox msgBox;
|
||
msgBox.setText(QString::fromLocal8Bit("采集暗电流,请确保镜头盖盖上!"));
|
||
msgBox.exec();
|
||
|
||
bool isMotorEnable = this->ui.mAction_2AxisMotor->isChecked();
|
||
if (isMotorEnable)
|
||
{
|
||
//移动x马达
|
||
if (!isMotorConnected(m_xMotor))
|
||
{
|
||
m_xMotor->EnableMotro();
|
||
m_lXmotorLocationOfStartRecord = m_xMotor->GetLocationNow();
|
||
m_xMotor->SettingSpeed(ui.xmotor_speed_slider->OriginalValue());
|
||
//m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
|
||
m_xMotor->MoveMotar(true);
|
||
}
|
||
}
|
||
|
||
emit RecordDarlSignal();
|
||
}
|
||
|
||
void HPPA::recordDarkFinish()
|
||
{
|
||
ui.mainToolBar->widgetForAction(ui.action_dark)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
|
||
bool isMotorEnable = this->ui.mAction_2AxisMotor->isChecked();
|
||
if (isMotorEnable)
|
||
{
|
||
//移动x马达
|
||
if (!isMotorConnected(m_xMotor))
|
||
{
|
||
//x马达返回采集前的位置
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
m_xMotor->MoveToLocation(m_lXmotorLocationOfStartRecord);
|
||
}
|
||
}
|
||
}
|
||
|
||
void HPPA::onReference()
|
||
{
|
||
QMessageBox msgBox;
|
||
msgBox.setText(QString::fromLocal8Bit("请确保白板放置正确!"));
|
||
msgBox.exec();
|
||
|
||
bool isMotorEnable = this->ui.mAction_2AxisMotor->isChecked();
|
||
if (isMotorEnable)
|
||
{
|
||
//移动x马达
|
||
if (!isMotorConnected(m_xMotor))
|
||
{
|
||
m_xMotor->EnableMotro();
|
||
m_lXmotorLocationOfStartRecord = m_xMotor->GetLocationNow();
|
||
m_xMotor->SettingSpeed(ui.xmotor_speed_slider->OriginalValue());
|
||
//m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
|
||
m_xMotor->MoveMotar(true);
|
||
}
|
||
}
|
||
|
||
emit RecordWhiteSignal();
|
||
}
|
||
|
||
void HPPA::recordWhiteFinish()
|
||
{
|
||
ui.mainToolBar->widgetForAction(ui.action_reference)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
|
||
bool isMotorEnable = this->ui.mAction_2AxisMotor->isChecked();
|
||
if (isMotorEnable)
|
||
{
|
||
//移动x马达
|
||
if (!isMotorConnected(m_xMotor))
|
||
{
|
||
//x马达返回采集前的位置
|
||
m_xMotor->SettingSpeed(m_lManualSpeedOfXMotor);
|
||
m_xMotor->MoveToLocation(m_lXmotorLocationOfStartRecord);
|
||
}
|
||
}
|
||
}
|
||
|
||
void HPPA::onPlotHyperspectralImageRgbImage()
|
||
{
|
||
//return;
|
||
//获取绘图控件
|
||
QWidget* currentWidget = ui.ImageViewerTabWidget->widget(m_numberOfRecording);
|
||
QList<ImageViewer *> currentImageViewer = currentWidget->findChildren<ImageViewer *>();
|
||
currentImageViewer[0]->DisplayFrameNumber(m_Imager->getFrameCounter());//界面中显示已经采集的帧数
|
||
|
||
//创建需要显示的图像--opencv版本
|
||
ImageProcessor imageProcessor;
|
||
//cv::Mat rgbImage(*m_Imager->getRgbImage()->m_matRgbImage, cv::Range(0, m_Imager->getFrameCounter()), cv::Range::all());//2022.3.18重构的
|
||
cv::Mat rgbImage(*m_Imager->getMatRgbImage(), cv::Range(0, m_Imager->getFrameCounter()), cv::Range::all());
|
||
cv::Mat rgbImageStretched = imageProcessor.CStretch(rgbImage, 0.02);
|
||
|
||
//在界面中显示图像
|
||
currentImageViewer[0]->SetImage(&QPixmap::fromImage(imageProcessor.Mat2QImage(rgbImageStretched)));//绘制图像
|
||
|
||
//20241225
|
||
//保存拉伸后的rgb
|
||
FileOperation* fileOperation = new FileOperation();
|
||
string directory = fileOperation->getDirectoryOfExe();
|
||
string rgbFilePathNoStrech = directory + "\\tmp_image_no_strech2.png";//拉伸图片
|
||
cv::imwrite(rgbFilePathNoStrech, rgbImageStretched);
|
||
|
||
//创建需要显示的图像--qt版本
|
||
//QRect CuttedRect = m_Imager->getRgbImage()->m_QRgbImage->rect();//先获取image整个rect
|
||
//CuttedRect.setHeight(m_Imager->getFrameCounter() - 1);//裁剪rect
|
||
//QImage CuttedImage = m_Imager->getRgbImage()->m_QRgbImage->copy(CuttedRect);
|
||
|
||
//currentImageViewer[0]->SetImage(&QPixmap::fromImage(CuttedImage));//绘制图像
|
||
}
|
||
|
||
void HPPA::PlotSpectral(int state)
|
||
{
|
||
if (state == 1)
|
||
{
|
||
//显示影像
|
||
QWidget* currentWidget = ui.ImageViewerTabWidget->currentWidget();
|
||
QList<ImageViewer *> currentImageViewer = currentWidget->findChildren<ImageViewer *>();
|
||
currentImageViewer[0]->DisplayFrameNumber(m_Imager->getFocusFrameCounter());//界面中显示已经采集的帧数
|
||
|
||
ImageProcessor imageProcessor;
|
||
//cv::Mat grayImage(*m_Imager->getRgbImage()->m_matFocusGrayImage, cv::Range::all(), cv::Range::all());//2022.3.18重构的
|
||
cv::Mat grayImage(*m_Imager->getMatFocusGrayImage(), cv::Range::all(), cv::Range::all());
|
||
//currentImageViewer[0]->SetImage(&QPixmap::fromImage(imageProcessor.Mat2QImage(grayImage)));//绘制图像
|
||
|
||
currentImageViewer[0]->SetImage(&QPixmap::fromImage(m_Imager->getQImageFocusGrayImage()));//绘制图像
|
||
|
||
//绘制光谱
|
||
QLineSeries *series = new QLineSeries();
|
||
//series->clear();//////////////////////////////
|
||
int sampleCount = m_Imager->getSampleCount();
|
||
for (size_t i = 0; i < sampleCount; i++)
|
||
{
|
||
//malloc申请的内存用法1:可以当做数组用
|
||
//series->append(i, m_Imager->buffer[i + 5 * 900]);
|
||
series->append(i, m_Imager->buffer[900 * 150 + i]);
|
||
}
|
||
|
||
QChart *chart = new QChart();
|
||
chart->legend()->hide();
|
||
chart->addSeries(series);
|
||
chart->createDefaultAxes();
|
||
//chart->setTitle("Simple line chart example");
|
||
|
||
m_chartView->setChart(chart);
|
||
}
|
||
else
|
||
{
|
||
//改变界面上的按钮文字
|
||
}
|
||
|
||
|
||
|
||
////显示影像
|
||
//QWidget* currentWidget = ui.ImageViewerTabWidget->currentWidget();
|
||
//QList<ImageViewer *> currentImageViewer = currentWidget->findChildren<ImageViewer *>();
|
||
//
|
||
|
||
//ImageProcessor imageProcessor;
|
||
//
|
||
|
||
////绘制光谱
|
||
//QLineSeries *series = new QLineSeries();
|
||
////series->clear();//////////////////////////////
|
||
//int sampleCount = m_Imager->getSampleCount();
|
||
//
|
||
|
||
//QChart *chart = new QChart();
|
||
//chart->legend()->hide();
|
||
//chart->addSeries(series);
|
||
//chart->createDefaultAxes();
|
||
////chart->setTitle("Simple line chart example");
|
||
|
||
//m_chartView->setChart(chart);
|
||
|
||
//while (state)
|
||
//{
|
||
// currentImageViewer[0]->DisplayFrameNumber(m_Imager->getFocusFrameCounter());//界面中显示已经采集的帧数
|
||
// cv::Mat grayImage(*m_Imager->getMatFocusGrayImage(), cv::Range::all(), cv::Range::all());
|
||
// currentImageViewer[0]->SetImage(&QPixmap::fromImage(imageProcessor.Mat2QImage(grayImage)));//绘制图像
|
||
|
||
// for (size_t i = 0; i < sampleCount; i++)
|
||
// {
|
||
// //malloc申请的内存用法1:可以当做数组用
|
||
// //series->append(i, m_Imager->buffer[i + 5 * 900]);
|
||
// series->append(i, m_Imager->buffer[900 * 150 + i]);
|
||
// }
|
||
// std::cout << "-----------------------------------------------" << std::endl;
|
||
//}
|
||
|
||
}
|
||
|
||
void HPPA::onRecordFinishedSignal_WhenFrameNumberMeet()
|
||
{
|
||
std::cout << "停止采集原因:帧数采集完了。" << std::endl;
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
|
||
m_RecordState++;//当自动停止采集
|
||
}
|
||
|
||
void HPPA::onRecordFinishedSignal_WhenFrameNumberNotMeet()
|
||
{
|
||
QAction* checked = moveplatformActionGroup->checkedAction();
|
||
QString checkedName;
|
||
if (checked)
|
||
{
|
||
checkedName = checked->objectName();
|
||
}
|
||
|
||
if (checkedName == "mAction_RobotArm")//机械臂会在停止采集后的瞬间又开始采集,导致ui.action_start_recording显示异常
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
std::cout << "停止采集原因:(1)帧数没有采集够时,马达到达最大位置;(2)手动停止采集。" << std::endl;
|
||
|
||
ui.action_start_recording->setText(QString::fromLocal8Bit("采集"));
|
||
ui.mainToolBar->widgetForAction(ui.action_start_recording)->setStyleSheet("QWidget{background-color:rgb(0,255,0);}");
|
||
}
|
||
|
||
ForLoopControl::ForLoopControl()
|
||
{
|
||
|
||
}
|
||
|
||
ForLoopControl::~ForLoopControl()
|
||
{
|
||
|
||
}
|
||
|
||
void ForLoopControl::setLoopCount(int loopCount)
|
||
{
|
||
m_loopCount = loopCount;
|
||
}
|
||
|
||
int ForLoopControl::getLoopCount() const
|
||
{
|
||
return m_loopCount;
|
||
}
|
||
|
||
void ForLoopControl::startLoop()
|
||
{
|
||
//std::cout << "共有" << m_loopCount << "次循环" << std::endl;
|
||
for (size_t i = 0; i < m_loopCount; i++)
|
||
{
|
||
//std::cout << "第" << i << "次循环" << std::endl;
|
||
|
||
emit recordSignal(i);
|
||
|
||
m_boolRecordNextLine = false;
|
||
m_boolQuitLoop = false;
|
||
while (!m_boolRecordNextLine)
|
||
{
|
||
Sleep(500);
|
||
|
||
if (m_boolQuitLoop)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (m_boolQuitLoop)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (m_boolQuitLoop == false)
|
||
{
|
||
emit recordSignal(-1);//采集完所有航线,自动停止
|
||
}
|
||
else if (m_boolQuitLoop == true)
|
||
{
|
||
emit recordSignal(-2);//手动停止采集
|
||
}
|
||
|
||
//std::cout << "退出循环!" << std::endl;
|
||
}
|
||
|
||
WorkerThread3::WorkerThread3(CFocusMotorControl * ctrlFocusMotor)
|
||
{
|
||
m_ctrlFocusMotor = ctrlFocusMotor;
|
||
}
|
||
|
||
void WorkerThread3::run()
|
||
{
|
||
m_ctrlFocusMotor->StartAutoFocus(820, 910, 20, 2);
|
||
|
||
emit AutoFocusFinishedSignal();
|
||
} |