diff --git a/HPPA/FocusDialog.ui b/HPPA/FocusDialog.ui index 22f5736..cee5f6f 100644 --- a/HPPA/FocusDialog.ui +++ b/HPPA/FocusDialog.ui @@ -6,8 +6,8 @@ 0 0 - 650 - 530 + 582 + 465 @@ -279,13 +279,28 @@ QRadioButton - 连接调焦模块 + 连接调焦线性平台 - - + + + + + 0 + 0 + + - 连接线性平台 + 新版 + + + true + + + true + + + false @@ -296,7 +311,7 @@ QRadioButton - 107 + 40 20 @@ -359,22 +374,72 @@ QRadioButton - - + + - 新版 - - - true - - - true - - - false + 连接 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + 状态 + + + Qt::AlignCenter + + + + + + + + 8 + 8 + + + + + 8 + 8 + + + + QLabel#motor_state_label +{ + background-color: red; + border-radius: 4px; +} + + + + + + + + @@ -446,7 +511,7 @@ QRadioButton - 10 + 0 Qt::AlignCenter @@ -462,7 +527,7 @@ QRadioButton - 10 + 1 Qt::AlignCenter @@ -518,7 +583,7 @@ QRadioButton - 10 + 1 Qt::AlignCenter diff --git a/HPPA/focusWindow.cpp b/HPPA/focusWindow.cpp index 693462c..56accca 100644 --- a/HPPA/focusWindow.cpp +++ b/HPPA/focusWindow.cpp @@ -78,6 +78,40 @@ focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager) m_dSpeed = 1.0; } +void focusWindow::showMessageBox(QString msg, QString title) +{ + QMessageBox msgBox(this); + msgBox.setWindowTitle(title); + msgBox.setText(msg); + msgBox.setStyleSheet(R"( + QMessageBox { + background-color: #0D1233; + } + QMessageBox QLabel { + color: #ACCDFF; + font-size: 14px; + } + QPushButton { + background-color: #142D7F; + color: #e6eeff; + border: 1px solid #2f6bff; + border-radius: 6px; + padding: 6px 20px; + min-width: 60px; + font-size: 13px; + } + QPushButton:hover { + border: 1px solid #4d8dff; + background-color: red; + } + QPushButton:pressed { + background-color: #23345c; + } + )"); + + msgBox.exec(); +} + focusWindow::~focusWindow() { printf("destroy focusWindow-------------------------\n"); @@ -163,33 +197,7 @@ void focusWindow::onConnectMotor() { if (ui.is_new_version_radioButton->isChecked()) { - FileOperation* fileOperation = new FileOperation(); - string directory = fileOperation->getDirectoryOfExe(); - QString configFilePath = QString::fromStdString(directory) + "\\oneMotorConfigFile_focus.cfg"; - - m_multiAxisController = new IrisMultiMotorController(configFilePath); - m_multiAxisController->moveToThread(&m_motorThread); - connect(&m_motorThread, SIGNAL(finished()), m_multiAxisController, SLOT(deleteLater())); - connect(this, SIGNAL(rmoveSignal(int, double, double, int)), m_multiAxisController, SLOT(rmove(int, double, double, int))); - connect(this, SIGNAL(move2LocSignal(int, double, double, int)), m_multiAxisController, SLOT(moveTo(int, double, double, int))); - connect(this, SIGNAL(rangeMeasurementSignal(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int))); - connect(this, SIGNAL(zeroStartSignal(int)), m_multiAxisController, SLOT(zeroStart(int))); - connect(this, SIGNAL(move2MaxLocSignal(int, double, int)), m_multiAxisController, SLOT(moveToMax(int, double, int))); - connect(m_multiAxisController, SIGNAL(broadcastLocationSignal(std::vector)), this, SLOT(display_x_loc(std::vector))); - connect(m_multiAxisController, SIGNAL(motorStopSignal(int, double)), this, SLOT(moveAfterAutoFocus(int, double))); - m_motorThread.start(); - - //归零 - //emit zeroStartSignal(0); - - //自动调焦逻辑 - m_coordinator = new MotionCaptureCoordinator(m_multiAxisController, m_Imager); - m_coordinator->moveToThread(&m_MotionCaptureCoordinatorThread); - connect(&m_MotionCaptureCoordinatorThread, SIGNAL(finished()), m_coordinator, SLOT(deleteLater())); - connect(this, SIGNAL(startStepMotion(double, int, double, double)), m_coordinator, SLOT(startStepMotion(double, int, double, double))); - connect(m_coordinator, SIGNAL(progressChanged(int)), this, SLOT(onAutoFocusProgress(int))); - connect(m_coordinator, SIGNAL(sequenceComplete()), this, SLOT(onAutoFocusFinished())); - m_MotionCaptureCoordinatorThread.start(); + connectMotor(true); } else { @@ -260,6 +268,131 @@ void focusWindow::onConnectMotor() disableBeforeConnect(false); } +void focusWindow::connectMotor(bool isNotification)//需要修改这个函数 +{ + if (getMotorsConnectionStatus()) + { + if (isNotification) + { + showMessageBox(QString::fromLocal8Bit("马达已连接!")); + } + return; + } + + if (m_multiAxisController) + { + disconnect(&m_motorThread, SIGNAL(finished()), m_multiAxisController, SLOT(deleteLater())); + disconnect(this, SIGNAL(rmoveSignal(int, double, double, int)), m_multiAxisController, SLOT(rmove(int, double, double, int))); + disconnect(this, SIGNAL(move2LocSignal(int, double, double, int)), m_multiAxisController, SLOT(moveTo(int, double, double, int))); + disconnect(this, SIGNAL(rangeMeasurementSignal(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int))); + disconnect(this, SIGNAL(zeroStartSignal(int)), m_multiAxisController, SLOT(zeroStart(int))); + disconnect(this, SIGNAL(move2MaxLocSignal(int, double, int)), m_multiAxisController, SLOT(moveToMax(int, double, int))); + disconnect(m_multiAxisController, SIGNAL(broadcastLocationSignal(std::vector)), this, SLOT(display_x_loc(std::vector))); + disconnect(m_multiAxisController, SIGNAL(motorStopSignal(int, double)), this, SLOT(moveAfterAutoFocus(int, double))); + disconnect(m_multiAxisController, SIGNAL(broadcastConnectivity(std::vector)), this, SLOT(display_motors_connectivity(std::vector))); + + m_motorThread.quit(); + m_motorThread.wait(); + m_multiAxisController->deleteLater(); + } + + if (m_coordinator) + { + disconnect(&m_MotionCaptureCoordinatorThread, SIGNAL(finished()), m_coordinator, SLOT(deleteLater())); + disconnect(this, SIGNAL(startStepMotion(double, int, double, double)), m_coordinator, SLOT(startStepMotion(double, int, double, double))); + disconnect(m_coordinator, SIGNAL(progressChanged(int)), this, SLOT(onAutoFocusProgress(int))); + disconnect(m_coordinator, SIGNAL(sequenceComplete()), this, SLOT(onAutoFocusFinished())); + + m_MotionCaptureCoordinatorThread.quit(); + m_MotionCaptureCoordinatorThread.wait(); + m_coordinator->deleteLater(); + } + + try + { + FileOperation* fileOperation = new FileOperation(); + string directory = fileOperation->getDirectoryOfExe(); + QString configFilePath = QString::fromStdString(directory) + "\\oneMotorConfigFile_focus.cfg"; + + m_multiAxisController = new IrisMultiMotorController(configFilePath); + } + catch (std::exception const& e) + { + showMessageBox(QString::fromLocal8Bit("请连接马达!")); + return; + } + + m_multiAxisController->moveToThread(&m_motorThread); + connect(&m_motorThread, SIGNAL(finished()), m_multiAxisController, SLOT(deleteLater())); + connect(this, SIGNAL(rmoveSignal(int, double, double, int)), m_multiAxisController, SLOT(rmove(int, double, double, int))); + connect(this, SIGNAL(move2LocSignal(int, double, double, int)), m_multiAxisController, SLOT(moveTo(int, double, double, int))); + connect(this, SIGNAL(rangeMeasurementSignal(int, double, int)), m_multiAxisController, SLOT(rangeMeasurement(int, double, int))); + connect(this, SIGNAL(zeroStartSignal(int)), m_multiAxisController, SLOT(zeroStart(int))); + connect(this, SIGNAL(move2MaxLocSignal(int, double, int)), m_multiAxisController, SLOT(moveToMax(int, double, int))); + connect(m_multiAxisController, SIGNAL(broadcastLocationSignal(std::vector)), this, SLOT(display_x_loc(std::vector))); + connect(m_multiAxisController, SIGNAL(motorStopSignal(int, double)), this, SLOT(moveAfterAutoFocus(int, double))); + connect(this, SIGNAL(testConnectivitySignal(int, int)), m_multiAxisController, SLOT(testConnectivity(int, int))); + connect(m_multiAxisController, SIGNAL(broadcastConnectivity(std::vector)), this, SLOT(display_motors_connectivity(std::vector))); + m_motorThread.start(); + emit testConnectivitySignal(0, 1000); + + //归零 + //emit zeroStartSignal(0); + + //自动调焦逻辑 + m_coordinator = new MotionCaptureCoordinator(m_multiAxisController, m_Imager); + m_coordinator->moveToThread(&m_MotionCaptureCoordinatorThread); + connect(&m_MotionCaptureCoordinatorThread, SIGNAL(finished()), m_coordinator, SLOT(deleteLater())); + connect(this, SIGNAL(startStepMotion(double, int, double, double)), m_coordinator, SLOT(startStepMotion(double, int, double, double))); + connect(m_coordinator, SIGNAL(progressChanged(int)), this, SLOT(onAutoFocusProgress(int))); + connect(m_coordinator, SIGNAL(sequenceComplete()), this, SLOT(onAutoFocusFinished())); + m_MotionCaptureCoordinatorThread.start(); + +} + +void focusWindow::display_motors_connectivity(std::vector connectivity) +{ + //std::cout << "-----------------------------------"<ui.motor_state_label->setStyleSheet(R"( + QLabel + { + background-color: #08FACE; + border-radius: 4px; + } + )"); + } + else + { + m_xMotorConnectionStatus = false; + + this->ui.motor_state_label->setStyleSheet(R"( + QLabel + { + background-color: red; + border-radius: 4px; + } + )"); + } + + if (getMotorsConnectionStatus()) + { + this->ui.connectMotor_btn->setText(QString::fromLocal8Bit("已连接")); + } + else + { + this->ui.connectMotor_btn->setText(QString::fromLocal8Bit("重新连接")); + } +} + +bool focusWindow::getMotorsConnectionStatus() +{ + return m_xMotorConnectionStatus; +} + void focusWindow::display_x_loc(std::vector loc) { double tmp = round(loc[0] * 100) / 100; @@ -517,20 +650,16 @@ void focusWindow::moveAfterAutoFocus(int motorID, double location) std::cout << "\n已经到达位置:" << location << std::endl; double tmp = abs(location - m_goodPos) / m_goodPos * 100; - if (tmp < 5) + if (tmp < 5 || m_goodPos == 0) { m_isMoveAfterAutoFocus = false; if (!m_isAutoFocusSuccess) { - QMessageBox msgBox; - msgBox.setText(QString::fromLocal8Bit("纹理较弱,自动调焦效果不佳!请使用调焦纸进行自动调焦!")); - msgBox.exec(); + showMessageBox(QString::fromLocal8Bit("纹理较弱,自动调焦效果不佳!请使用调焦纸进行自动调焦!")); } else { - QMessageBox msgBox; - msgBox.setText(QString::fromLocal8Bit("自动调焦成功!")); - msgBox.exec(); + showMessageBox(QString::fromLocal8Bit("自动调焦成功!")); } } else diff --git a/HPPA/focusWindow.h b/HPPA/focusWindow.h index f5b8d89..5893fb9 100644 --- a/HPPA/focusWindow.h +++ b/HPPA/focusWindow.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "ui_FocusDialog.h" #include "AbstractPortMiscDefines.h" @@ -123,11 +124,11 @@ private: void disableBeforeConnect(bool disable); QThread m_motorThread; - IrisMultiMotorController* m_multiAxisController; + QPointer m_multiAxisController; double m_dSpeed; QThread m_MotionCaptureCoordinatorThread; - MotionCaptureCoordinator* m_coordinator; + QPointer m_coordinator; int m_iStepSize; double m_goodPos; @@ -136,6 +137,11 @@ private: void getGaussianInitParam(const std::vector& pos, const std::vector& index, double& a_init, double& mu_init, double& sigma_init, double& c_init); void gaussian_fit(const std::vector& x_data, const std::vector& y_data, double& a, double& mu, double& sigma, double& c); + bool m_xMotorConnectionStatus = false; + bool getMotorsConnectionStatus(); + void connectMotor(bool isNotification); + + void showMessageBox(QString msg, QString title = QString::fromLocal8Bit("提示")); public Q_SLOTS: void onConnectMotor(); @@ -158,6 +164,8 @@ public Q_SLOTS: void onExit(); + void display_motors_connectivity(std::vector connectivity); + signals: void StartManualFocusSignal(int);//1:开始调焦;0:停止调焦; @@ -166,6 +174,7 @@ signals: void rmoveSignal(int, double, double, int); void rangeMeasurementSignal(int, double, int); void zeroStartSignal(int); + void testConnectivitySignal(int, int); void startStepMotion(double speed, int stepInterval = 100, double startPos = 0, double endPos = -1); void closeSignal();