阶段性备份

This commit is contained in:
2024-07-24 14:32:11 +08:00
parent 879404c808
commit c506af234d
48 changed files with 589 additions and 309 deletions
+83
View File
@@ -0,0 +1,83 @@
{
"files.associations": {
"algorithm": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"resumable": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"random": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"xthread": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"valarray": "cpp",
"variant": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
@@ -302,11 +302,8 @@ double doubleLmit(double input, int num)
}
void ALGO_Correction(std::shared_ptr <detData> data)
{
if (data->correctionData == nullptr)
return;
CorrectionPoints resultPoints;
if (HalconCorrection(data->correctionData, resultPoints) == false)
if (HalconCorrection(&data->laserData, resultPoints) == false)
{
data->writeBack("short", 274, "1");
return;
@@ -14,11 +14,13 @@ void appConfig::parsingTriggerData()
{
nlohmann::json triggerJson = readJsonFromPath("./config/triggerSetting.json");
_triggerStruct.key = triggerJson["key"];
_triggerStruct.frequency = triggerJson["frequency"];
_triggerStruct.sleepTime = triggerJson["sleepTime"];
_triggerStruct.initStr = triggerJson["initStr"];
_triggerStruct.heartCmd = triggerJson["heartCmd"];
_triggerStruct.readAllCmd = triggerJson["readAllCmd"];
_triggerStruct.modelName = triggerJson["modelName"];
_triggerStruct.readNum = triggerJson["readNum"];
_triggerStruct.writeType = triggerJson["writeType"];
_triggerStruct.startPos = QString::fromStdString(_triggerStruct.readAllCmd).split("_")[2].toInt();;
}
void appConfig::parsingCameraData()
@@ -193,11 +193,13 @@ struct lightSourceStruct
struct triggerStruct
{
std::string key;
std::string frequency;//per Sec
std::string initStr;
std::string heartCmd;
std::string readAllCmd;
std::string modelName;
int sleepTime;
int readNum;
std::string writeType;
int startPos;
};
struct cameraStruct
+5 -1
View File
@@ -18,6 +18,10 @@ signals:
void addShowPerformanceWidgetData(int index, int timeCost);
void addCtData(int index, int value);//增加ct数据
void resetShowPerformanceWidget();
void setProductSignStatus(int pos, int status);//设置产品示意图指定位置的状态
void uiModuleLocationMapResetToDefault();
void uiModuleLocationMapSetProductSignStatus(int pos, int status);//设置产品示意图指定位置的状态
void uiModuleImageDoubleCheckQdialogShowWindows(QPixmap);
};
#pragma once
+2 -1
View File
@@ -29,7 +29,7 @@ public:
int algoThreadIndex = -1;
//检测参数
correctionStruct* correctionData = nullptr;
correctionStruct laserData;
int armPos = -1;
int productType = -1;
@@ -71,6 +71,7 @@ public:
//结果
bool aiDetOK = true;
bool halconOK = true;
int aiNgCount = 0, aiOkCount = 0, halconOkCount = 0, halconNgCount = 0;
//存图相关
QMutex resultMutex;//结果图锁
std::vector<cv::Mat> resultImgs;//结果图
@@ -17,6 +17,7 @@ public:
//检测参数
std::string imgPathStr = "";
int algoIndex = 0;
int Pos = 0;
manualDetThread()
{
_appConfig = &_core._appConfig;
@@ -31,12 +32,16 @@ public:
{
std::shared_ptr <detData> data = _detDataManager->insertDetData("Manual", "Manual", 0, 1);
data->productType = algoIndex;
data->armPos = Pos;
data->resShowIndex = 0;
data->oriImgMutex.lock();
data->oriImgs.push_back(cv::imread(file, -1));
data->oriImgMutex.unlock();
data->_productDataStruct = _appConfig->productDatas[algoIndex];
_threadManager->addTask(data);//添加任务
emit _core._qtFunc.uiModuleLocationMapSetProductSignStatus(Pos, 1);
Pos++;
//QThread::msleep(3000);
}
files.clear();
fileManager::getAllFiles(imgPathStr, files, "bmp");
@@ -44,17 +49,23 @@ public:
{
std::shared_ptr <detData> data = _detDataManager->insertDetData("Manual", "Manual", 0, 1);
data->productType = algoIndex;
data->armPos = Pos;
data->resShowIndex = 0;
data->oriImgMutex.lock();
data->oriImgs.push_back(cv::imread(file, -1));
data->oriImgMutex.unlock();
data->_productDataStruct = _appConfig->productDatas[algoIndex];
_threadManager->addTask(data);//添加任务
emit _core._qtFunc.uiModuleLocationMapSetProductSignStatus(Pos, 1);
Pos++;
//QThread::msleep(3000);
}
emit finishImgReadSignal();
}
void startDet(std::string path,int index)
{
Pos = 0;
emit _core._qtFunc.uiModuleLocationMapResetToDefault();
imgPathStr = path;
algoIndex = index;
this->start();
@@ -66,61 +66,8 @@ void detThreadManager::process()
}
void detThreadManager::resultHandle(std::shared_ptr <detData> data)
{
//发送图片
if (data->resultImgs.size() > 0)
{
int cnt = 0;
for(auto showMat: data->resultImgs)
{
//打包发送
QPixmap pixmap;
cvMatToQPixMap(showMat, pixmap);
showImgPack* pack = new showImgPack();
pack->img = pixmap;
pack->type = imgWidgetRes;
pack->index = data->resShowIndex+ cnt;
emit _core._qtFunc.sendPixmapImageWidget(pack);
historyPack _historyPack;
_historyPack.img = pixmap;
_historyPack.filePath = std::shared_ptr<std::string>(new std::string);
data->resImgSavePath.push_back(_historyPack.filePath);
emit _core._qtFunc.addHistoryDataSignal((data->aiDetOK == true && data->halconOK == true), _historyPack);
cnt++;
}
}
if(data->armPos != -1)
{
emit _core._qtFunc.addDashBoardData(0, data->halconOK);
emit _core._qtFunc.addDashBoardData(1, data->aiDetOK);
}
auto totalCt = std::chrono::duration_cast<std::chrono::milliseconds>(data->halconEndTime - data->algoStartTime);
auto aiCt = std::chrono::duration_cast<std::chrono::milliseconds>(data->handleAiEndTime - data->algoStartTime);
auto halconCt = std::chrono::duration_cast<std::chrono::milliseconds>(data->halconEndTime - data->handleAiEndTime);
if (totalCt.count() > 0)
emit _core._qtFunc.addCtData(0, totalCt.count());
if (aiCt.count() > 0)
emit _core._qtFunc.addCtData(1, aiCt.count());
if (halconCt.count() > 0)
emit _core._qtFunc.addCtData(2, halconCt.count());
//SQL
std::vector<sqlData> sqlDatas;
for (auto sqlData : data->sqlVec)
sqlDatas.push_back({ sqlData.first, std::to_string(sqlData.second) });
_core._appConfig._sqlManager.addData(data->SNcode, sqlDatas);
//写入plc
for (auto writeBackStr : data->writeBackData)
_triggerManager->sendFinsMsg(writeBackStr);
//储存结果图
std::async(std::launch::async, &imgSaveThreadManager::saveRes, _imgSaveThreadManager, data);
//删除 不再持有
detDataManager* dManager = data->dManager;
data->dManager->deleteDetData(data->timeCode);
for (auto func : resultHandleCallbacks)
func(data);
}
void detThreadManager::run()
{
@@ -54,11 +54,12 @@ class detThreadManager : public QThread
Q_OBJECT
public:
using resultHandleCallback = std::function<void(std::shared_ptr <detData>)>;
bool initFlag = false;
detThreadManager();
~detThreadManager();
QQueue<std::shared_ptr <detData>> detDataQueue;
autoDelete* autoDeleteThread;
void initialization(detProcess* appCore);
void run();
void stop()
@@ -66,18 +67,19 @@ public:
runFlag = false;
this->terminate();
}
void resultHandle(std::shared_ptr <detData>);
void addTask(std::shared_ptr <detData>);
sncodeCls snDatas;
~detThreadManager();
QMutex queueMutex;
QMutex insertQueueMutex;
QQueue<std::shared_ptr <detData>>insertQueue;
void process();
void registerCallback(resultHandleCallback func)
{
resultHandleCallbacks.push_back(func);
}
private:
std::vector< resultHandleCallback>resultHandleCallbacks;
handleAiModelManager* _handleAiModelManager;
triggerManager* _triggerManager;
imgSaveThreadManager* _imgSaveThreadManager;
@@ -90,7 +92,8 @@ private:
std::chrono::seconds zeroSec = std::chrono::seconds(0);
std::unordered_map<unsigned long long, std::future<bool>>::iterator futrueIte;
void resultHandle(std::shared_ptr <detData>);
bool runFlag = true;
QList<std::shared_ptr <detData>>imgWaitList;
std::vector<std::shared_ptr <detData>>deleteVec;
+11 -184
View File
@@ -7,7 +7,6 @@
#include <detProcess.hpp>
#include <lightSource.hpp>
#define debugTesting 0
static correctionStruct* correctionData;
void triggerManager::initialization(detProcess* _detProcessIn)
{
_detProcess = _detProcessIn;
@@ -20,6 +19,10 @@ void triggerManager::initialization(detProcess* _detProcessIn)
triggerFileName = QString::fromStdString(_core._appConfig._triggerStruct.modelName);
IpAndPort = QString::fromStdString(_core._appConfig._triggerStruct.initStr);
readAllCmd = QByteArray::fromStdString(_core._appConfig._triggerStruct.readAllCmd);
triggerFileName = QString::fromStdString(_core._appConfig._triggerStruct.modelName);
sleepTime = _core._appConfig._triggerStruct.sleepTime;
readNum = _core._appConfig._triggerStruct.readNum;
writeType = _core._appConfig._triggerStruct.writeType;
m_lib = new QLibrary(triggerFileName);
libLoadedflag = m_lib->load();
if (!m_lib->isLoaded())
@@ -44,10 +47,15 @@ void triggerManager::connectHost()
{
trigger = createFun();
destory_finstcp = releaseFun;
QByteArray initByte = QByteArray::fromStdString("sleeptime_20_readnum_300_writetype_ushort");
QByteArray initByte =
QByteArray::fromStdString
("sleeptime_"+std::to_string(sleepTime)
+ "_readnum_" + std::to_string(readNum)
+ "_writetype_" + writeType);
trigger->reciveData(vec_mat, QByteArray(IpAndPort.toUtf8()));
emit _core._qtFunc.sendInitString(triggerFileName + "连接到" + IpAndPort);
initFailure = trigger->initParas(initByte);
this->start();
}
if (initFailure == false)
@@ -198,190 +206,9 @@ void triggerManager::decodeCameraCMD(QByteArray byte)
}
#endif
//相机测试
#if 0
if (checkTrigger(1, 2, byte) == true)
{
std::shared_ptr <detData> data = dManager->insertDetData("Camera1", "TEST",0, 0);
data->correctionData = correctionData;
_threadManager->addTask(data);//添加任务
auto camera = _cameraManager->getCamera("123");
if (camera != nullptr)
camera->captureImage(data);
}
if (checkTrigger(2, 2, byte) == true)
{
std::shared_ptr <detData> data = dManager->insertDetData("Camera1", "TEST", 0, 0);
data->correctionData = correctionData;
_threadManager->addTask(data);//添加任务
auto camera = _cameraManager->getCamera("456");
if (camera != nullptr)
camera->captureImage(data);
}
#endif
//总流程开始,机器人发送1至寄存器259
//上位机确认OK之后,清零寄存器259,并发送1至寄存器260
//如产品型号为Product_1且为正面,则上位机发送1至寄存器256,发送0至寄存器257
//之后机器人确认之后需发送测量点位总数具体值至寄存器258
if (checkTrigger(259, 1, byte) == true)
{
sendFinsMsg("write_short_259_0");//触发信号清零
sendFinsMsg("write_short_260_1");//开始检测信号
}
//机器人激光当前点位 264 1...9
//机器人到达激光点位1时,寄存器261至1,264至1,并将机器人在激光点位1坐标XYZ按照定义规则,保存进寄存器265~270
//上位机确认机器人到达点位1(264)时,确认OK后,寄存器262至1,261至0,取点完成后,发送寄存器263至1
if (checkTrigger(261, 1, byte) == true)//读取请求地址
{
QThread::msleep(3000);
int armPos = getValue(264, byte);
int xValue1 = getValue(265, byte);
int xValue2 = getValue(266, byte);
int xValue3 = getValue(267, byte);
int yValue1 = getValue(268, byte);
int yValue2 = getValue(269, byte);
int yValue3 = getValue(270, byte);
int zValue1 = getValue(271, byte);
int zValue2 = getValue(272, byte);
int zValue3 = getValue(273, byte);
double xValue = (xValue1 == 1 ? 1 : -1) * ((double)xValue2 + ((double)xValue3) / (std::pow(10, std::to_string(xValue3).length())));
double yValue = (yValue1 == 1 ? 1 : -1) * ((double)yValue2 + ((double)yValue3) / (std::pow(10, std::to_string(yValue3).length())));
double zValue = (zValue1 == 1 ? 1 : -1) * ((double)zValue2 + ((double)zValue3) / (std::pow(10, std::to_string(zValue3).length())));
auto cameraPtr = _cameraManager->getCamera("181964");
if (cameraPtr == nullptr)
return;
std::vector<double> values;
for (int i = 0;i < 10;i++)//弃用
{
cameraPtr->trigger();
double rangeData1 = cameraPtr->getCameraValue();
}
for (int i = 0;i < 100;i++)
{
cameraPtr->trigger();
double rangeData1 = cameraPtr->getCameraValue();
values.push_back(rangeData1);
}
double avgData = 0;
for (auto data : values)
{
avgData += data;
}
avgData /= values.size();
double maxData = *std::max_element(values.begin(), values.end());
double minData = *std::min_element(values.begin(), values.end());
double rangeData = avgData;
qDebug() << " max:" << maxData << " min:" << minData << " avg:" << avgData;
std::cout << " max:" << maxData << " min:" << minData << " avg:" << avgData<<std::endl;
qDebug() << "jiaozhun xValue:" << xValue << " yValue:" << yValue << " zValue:" << zValue <<" rangeData:"<< rangeData;
std::cout << "jiaozhun xValue:" << xValue << " yValue:" << yValue << " zValue:" << zValue << " rangeData:" << rangeData<<std::endl;
if (rangeData == 0)
{
std::cout << "激光取图错误" << std::endl;
return;
}
if (armPos == 1)//第一次
correctionData = new correctionStruct();
if (correctionData == nullptr)
return;
if (armPos <= 3)
{
correctionData->in_X_X0Y.push_back(xValue);
correctionData->in_Y_X0Y.push_back(yValue);
correctionData->in_Z_X0Y.push_back(zValue);
correctionData->in_Z_X0Y_Value.push_back(rangeData);
}
else if (armPos <= 6)
{
correctionData->in_X_X0Z.push_back(xValue);
correctionData->in_Y_X0Z.push_back(yValue);
correctionData->in_Z_X0Z.push_back(zValue);
correctionData->in_Y_X0Z_Value.push_back(rangeData);
}
else if (armPos <= 9)
{
correctionData->in_X_Y0Z.push_back(xValue);
correctionData->in_Y_Y0Z.push_back(yValue);
correctionData->in_Z_Y0Z.push_back(zValue);
correctionData->in_X_Y0Z_Value.push_back(rangeData);
}
sendFinsMsg("write_short_261_0");//清零
sendFinsMsg("write_short_262_1");
sendFinsMsg("write_short_263_1");
//上位机校正完成,将寄存器274置为1,并将结果按照定义XYZ规则放入310~336中
if (armPos == 9)
{
std::shared_ptr <detData> data = dManager->insertDetData("181964", "TEST", 0 , 0);
data->productType = _core._detGlobalData.productType;
data->_productDataStruct = _core._appConfig.productDatas[_core._detGlobalData.productType];
data->imgAmountMin = 0;
data->correctionData = correctionData;
_threadManager->addTask(data);//添加任务
correctionData = nullptr;
}
}
//机器人到达激光点位9时,寄存器261至1,264至9,并将机器人在激光点位9坐标XYZ按照定义规则,保存进寄存器265~270
if (checkTrigger(300, 1, byte) == true)
{
_lightSourceManager->getLightSourcePtr("COM8")->setValue(lightSourceChannel::DChannel, 255);
QThread::msleep(2000);//延时等待机械臂停稳
sendFinsMsg("write_short_300_0");//触发信号清零
sendFinsMsg("write_short_301_1");//开始检测信号
int Pos = getValue(303, byte);
std::cout << "arm @Pos:" << Pos;
std::shared_ptr <detData> data = dManager->insertDetData("Camera1", "TEST", 1, 1);
data->oriShowIndex = 0;
data->resShowIndex = 0;
data->armPos = Pos;
data->productType = _core._detGlobalData.productType;
data->_productDataStruct = _core._appConfig.productDatas[_core._detGlobalData.productType];
auto camera = _cameraManager->getCamera("Camera1");//查找相机
if (camera != nullptr)
camera->captureImage(data);//拍照
data->imgSaveFileParameter.push_back(_core._detGlobalData.productTypeStr);//设置部分文件名
data->imgSaveFileParameter.push_back("Pos" + std::to_string(Pos));//设置部分文件名
data->correctionData = correctionData;
_threadManager->addTask(data);//添加任务
QThread::msleep(1000);//延时一秒完成拍照,后续改成拍完直接发送
sendFinsMsg("write_short_302_1");//开始检测信号
_lightSourceManager->getLightSourcePtr("COM8")->setValue(lightSourceChannel::DChannel, 0);
}
if (checkTrigger(361, 1, byte) == true && armIsRunning == false)
{
armIsRunning = true;
emit _core._qtFunc.switchStartBtnStatusSignal(false);
}
if (checkTrigger(362, 1, byte) == true && armIsRunning == true)
{
armIsRunning = false;
sendFinsMsg("write_short_361_0");//清零
sendFinsMsg("write_short_362_0");
emit _core._qtFunc.switchStartBtnStatusSignal(true);
}
if (checkTrigger(361, 0, byte) == true && armIsRunning == true)
{
armIsRunning = false;
sendFinsMsg("write_short_361_0");//清零
sendFinsMsg("write_short_362_0");
emit _core._qtFunc.switchStartBtnStatusSignal(true);
}
#endif
checkCallbackAndTrigger(byte);
}
int triggerManager::getValue(int dmPos, QByteArray byte)
{
+38 -3
View File
@@ -6,8 +6,9 @@
#include <qlibrary.h>
#include <globalStruct.h>
#include <backStruct.h>
#include <functional>
#include <appConfig/appConfig.h>
using triggerCallback = std::function<void(QByteArray& byte)>;
class cameraManager;
class detThreadManager;
class detDataManager;
@@ -64,7 +65,6 @@ private:
class triggerManager : public QThread
{
public:
bool armIsRunning = false;
QByteArray readAllCmd;
QString triggerFileName;
QString IpAndPort;
@@ -126,10 +126,43 @@ public:
}
int getValue(int dmPos, QByteArray byte);
//CALL BACK
struct triggerCallbackStruct
{
int triggerAddress;
int triggerValue;
triggerCallback func;
std::string funcName;
};
std::vector<triggerCallbackStruct> triggerCallbackFunc;
bool registerCallback(int triggerAddress, int triggerValue, triggerCallback func, std::string funcName ="")
{
triggerCallbackStruct _triggerCallbackStruct;
_triggerCallbackStruct.triggerAddress = triggerAddress;
_triggerCallbackStruct.triggerValue = triggerValue;
_triggerCallbackStruct.func = func;
_triggerCallbackStruct.funcName = funcName;
triggerCallbackFunc.push_back(_triggerCallbackStruct);
return true;
}
void checkCallbackAndTrigger(QByteArray &byte)//检查是否符合回调函数的触发条件
{
for (auto callback : triggerCallbackFunc)
{
if (checkTrigger(callback.triggerAddress, 1, byte) == true)
{
callback.func(byte);
std::cout << "func:" << callback.funcName << "->triggered" << std::endl;
}
}
}
private:
std::string writeType;
bool libLoadedflag = false;
QLibrary* m_lib = nullptr;
detProcess* _detProcess;
detProcess* _detProcess;
lightSourceManager* _lightSourceManager;
detThreadManager* _threadManager;
detDataManager* dManager;
@@ -172,6 +205,8 @@ private:
void decodeCameraCMD(QByteArray byte);
//触发器的配置
int startPos=-1;//数据读取的起始位
int sleepTime = -1;//间隔
int readNum = -1;//范围
int interval = 50;//间隔
ReleaseFunction destory_finstcp; //释放
+266 -8
View File
@@ -16,30 +16,288 @@ public:
_cameraManager.initialization();
_handleAiModelManager.initialization();
_triggerManager.initialization(this);
detProcessCallbackRegister();
}
void run()
{
/*std::vector<std::future<void>> futures;
futures.push_back(std::async(std::launch::async, &handleAiModelManager::start, &_handleAiModelManager));
futures.push_back(std::async(std::launch::async, &cameraManager::start, &_cameraManager));
futures.push_back(std::async(std::launch::async, &lightSourceManager::start, &_lightSourceManager));
futures.push_back(std::async(std::launch::async, &triggerManager::connectHost, &_triggerManager));*/
std::async(std::launch::async, &handleAiModelManager::start, &_handleAiModelManager);
std::async(std::launch::async, &cameraManager::start, &_cameraManager);
std::async(std::launch::async, &lightSourceManager::start, &_lightSourceManager);
std::async(std::launch::async, &triggerManager::connectHost, &_triggerManager);
}
//
detDataManager _detDataManager;//检测中的数据 不需要初始化
imgSaveThreadManager _imgSaveThreadManager;//存图线程 不需要初始化
detThreadManager _threadManager;//异步检测线程 不需要初始化
//
handleAiModelManager _handleAiModelManager;//模型
cameraManager _cameraManager;//相机
lightSourceManager _lightSourceManager;//光源
triggerManager _triggerManager;//触发器
triggerManager _triggerManager;//MODBUS触发器
manualDetThread _manualDetThread;//手动触发线程
///////////////////////////////
void detProcessCallbackRegister()
{
_triggerManager.registerCallback(259, 1, [this](QByteArray& byteArray) {startDetection(byteArray); }, "检测启动");
_triggerManager.registerCallback(261, 1, [this](QByteArray& byteArray) {calibrationFunc(byteArray); }, "激光校准");
_triggerManager.registerCallback(300, 1, [this](QByteArray& byteArray) {captureImageAndDetection(byteArray); }, "拍照并检测");
_triggerManager.registerCallback(361, 1, [this](QByteArray& byteArray) {detectionStart(byteArray); }, "检测开始");
_triggerManager.registerCallback(361, 0, [this](QByteArray& byteArray) {detectionEnd1(byteArray); }, "检测结束1");
_triggerManager.registerCallback(362, 1, [this](QByteArray& byteArray) {detectionEnd2(byteArray); }, "检测结束2");
_threadManager.registerCallback([this](std::shared_ptr<detData>data) {detectionResultHandle(data); });
}
//检测程序是否在运行
bool armIsRunning = false;
//激光校准数据缓存 //SN 数据
correctionStruct laserDataCache;
//总流程开始,机器人发送1至寄存器259
//上位机确认OK之后,清零寄存器259,并发送1至寄存器260
//如产品型号为Product_1且为正面,则上位机发送1至寄存器256,发送0至寄存器257
//之后机器人确认之后需发送测量点位总数具体值至寄存器258
//检测启动 259
void startDetection(QByteArray& byteArray)
{
_triggerManager.sendFinsMsg("write_short_259_0");//触发信号清零
_triggerManager.sendFinsMsg("write_short_260_1");//开始检测信号
emit _core._qtFunc.uiModuleLocationMapResetToDefault();
}
//机器人激光当前点位 264 1...9
//机器人到达激光点位1时,寄存器261至1,264至1,并将机器人在激光点位1坐标XYZ按照定义规则,保存进寄存器265~270
//上位机确认机器人到达点位1(264)时,确认OK后,寄存器262至1,261至0,取点完成后,发送寄存器263至1
//校准函数 261
void calibrationFunc(QByteArray& byteArray)
{
QThread::msleep(3000);
int armPos = _triggerManager.getValue(264, byteArray);
int xValue1 = _triggerManager.getValue(265, byteArray);
int xValue2 = _triggerManager.getValue(266, byteArray);
int xValue3 = _triggerManager.getValue(267, byteArray);
int yValue1 = _triggerManager.getValue(268, byteArray);
int yValue2 = _triggerManager.getValue(269, byteArray);
int yValue3 = _triggerManager.getValue(270, byteArray);
int zValue1 = _triggerManager.getValue(271, byteArray);
int zValue2 = _triggerManager.getValue(272, byteArray);
int zValue3 = _triggerManager.getValue(273, byteArray);
double xValue = (xValue1 == 1 ? 1 : -1) * ((double)xValue2 + ((double)xValue3) / (std::pow(10, std::to_string(xValue3).length())));
double yValue = (yValue1 == 1 ? 1 : -1) * ((double)yValue2 + ((double)yValue3) / (std::pow(10, std::to_string(yValue3).length())));
double zValue = (zValue1 == 1 ? 1 : -1) * ((double)zValue2 + ((double)zValue3) / (std::pow(10, std::to_string(zValue3).length())));
auto cameraPtr = _cameraManager.getCamera("181964");
if (cameraPtr == nullptr)
return;
std::vector<double> values;
for (int i = 0; i < 10; i++)//弃用
{
cameraPtr->trigger();
double rangeData1 = cameraPtr->getCameraValue();
}
for (int i = 0; i < 100; i++)
{
cameraPtr->trigger();
double rangeData1 = cameraPtr->getCameraValue();
values.push_back(rangeData1);
}
double avgData = 0;
for (auto data : values)
{
avgData += data;
}
avgData /= values.size();
double maxData = *std::max_element(values.begin(), values.end());
double minData = *std::min_element(values.begin(), values.end());
double rangeData = avgData;
qDebug() << " max:" << maxData << " min:" << minData << " avg:" << avgData;
std::cout << " max:" << maxData << " min:" << minData << " avg:" << avgData << std::endl;
qDebug() << "jiaozhun xValue:" << xValue << " yValue:" << yValue << " zValue:" << zValue << " rangeData:" << rangeData;
std::cout << "jiaozhun xValue:" << xValue << " yValue:" << yValue << " zValue:" << zValue << " rangeData:" << rangeData << std::endl;
if (rangeData == 0)
{
std::cout << "激光取图错误" << std::endl;
return;
}
if (armPos == 1)//第一次
laserDataCache = correctionStruct();
if (armPos <= 3)
{
laserDataCache.in_X_X0Y.push_back(xValue);
laserDataCache.in_Y_X0Y.push_back(yValue);
laserDataCache.in_Z_X0Y.push_back(zValue);
laserDataCache.in_Z_X0Y_Value.push_back(rangeData);
}
else if (armPos <= 6)
{
laserDataCache.in_X_X0Z.push_back(xValue);
laserDataCache.in_Y_X0Z.push_back(yValue);
laserDataCache.in_Z_X0Z.push_back(zValue);
laserDataCache.in_Y_X0Z_Value.push_back(rangeData);
}
else if (armPos <= 9)
{
laserDataCache.in_X_Y0Z.push_back(xValue);
laserDataCache.in_Y_Y0Z.push_back(yValue);
laserDataCache.in_Z_Y0Z.push_back(zValue);
laserDataCache.in_X_Y0Z_Value.push_back(rangeData);
}
_triggerManager.sendFinsMsg("write_short_261_0");//清零
_triggerManager.sendFinsMsg("write_short_262_1");
_triggerManager.sendFinsMsg("write_short_263_1");
//上位机校正完成,将寄存器274置为1,并将结果按照定义XYZ规则放入310~336中
if (armPos == 9)
{
std::shared_ptr <detData> data = _detDataManager.insertDetData("181964", "TEST", 0, 0);
data->productType = _core._detGlobalData.productType;
data->_productDataStruct = _core._appConfig.productDatas[_core._detGlobalData.productType];
data->imgAmountMin = 0;
data->laserData = laserDataCache;
_threadManager.addTask(data);//添加任务
laserDataCache = correctionStruct();
}
}
//拍照并检测 300
void captureImageAndDetection(QByteArray& byteArray)
{
_lightSourceManager.getLightSourcePtr("COM8")->setValue(lightSourceChannel::DChannel, 255);
QThread::msleep(2000);//延时等待机械臂停稳
_triggerManager.sendFinsMsg("write_short_300_0");//触发信号清零
_triggerManager.sendFinsMsg("write_short_301_1");//开始检测信号
int Pos = _triggerManager.getValue(303, byteArray);
emit _core._qtFunc.uiModuleLocationMapSetProductSignStatus(Pos,1);
std::cout << "arm @Pos:" << Pos;
std::shared_ptr <detData> data = _detDataManager.insertDetData("Camera1", "TEST", 1, 1);
data->oriShowIndex = 0;
data->resShowIndex = 0;
data->armPos = Pos;
data->productType = _core._detGlobalData.productType;
data->_productDataStruct = _core._appConfig.productDatas[_core._detGlobalData.productType];
auto camera = _cameraManager.getCamera("Camera1");//查找相机
if (camera != nullptr)
camera->captureImage(data);//拍照
data->imgSaveFileParameter.push_back(_core._detGlobalData.productTypeStr);//设置部分文件名
data->imgSaveFileParameter.push_back("Pos" + std::to_string(Pos));//设置部分文件名
_threadManager.addTask(data);//添加任务
QThread::msleep(1000);//延时一秒完成拍照,后续改成拍完直接发送
_triggerManager.sendFinsMsg("write_short_302_1");//开始检测信号
_lightSourceManager.getLightSourcePtr("COM8")->setValue(lightSourceChannel::DChannel, 0);
}
//机械臂状态切换 361 1
void detectionStart(QByteArray& byteArray)
{
if (armIsRunning == false)
{
armIsRunning = true;
emit _core._qtFunc.switchStartBtnStatusSignal(false);
}
}
//机械臂状态切换 361 0
void detectionEnd1(QByteArray& byteArray)
{
if(armIsRunning == true)
{
armIsRunning = false;
_triggerManager.sendFinsMsg("write_short_361_0");//清零
_triggerManager.sendFinsMsg("write_short_362_0");
emit _core._qtFunc.switchStartBtnStatusSignal(true);
}
}
//机械臂状态切换 362 1
void detectionEnd2(QByteArray& byteArray)
{
if (armIsRunning == true)
{
armIsRunning = false;
_triggerManager.sendFinsMsg("write_short_361_0");//清零
_triggerManager.sendFinsMsg("write_short_362_0");
emit _core._qtFunc.switchStartBtnStatusSignal(true);
}
}
//////////////////////////////////////////////////
//检测结果处理
void detectionResultHandle(std::shared_ptr<detData>data)
{
//发送图片
if (data->resultImgs.size() > 0)
{
int cnt = 0;
for (auto showMat : data->resultImgs)
{
//打包发送
QPixmap pixmap;
cvMatToQPixMap(showMat, pixmap);
showImgPack* pack = new showImgPack();
pack->img = pixmap;
pack->type = imgWidgetRes;
pack->index = data->resShowIndex + cnt;
emit _core._qtFunc.sendPixmapImageWidget(pack);
historyPack _historyPack;
_historyPack.img = pixmap;
_historyPack.filePath = std::shared_ptr<std::string>(new std::string);
data->resImgSavePath.push_back(_historyPack.filePath);
emit _core._qtFunc.addHistoryDataSignal((data->aiDetOK == true && data->halconOK == true), _historyPack);
cnt++;
}
}
//发送检测结果发送到界面
if (data->armPos != -1)
{
emit _core._qtFunc.addDashBoardData(0, data->halconOK);
emit _core._qtFunc.addDashBoardData(1, data->aiDetOK);
emit _core._qtFunc.uiModuleLocationMapSetProductSignStatus(data->armPos,
(data->halconOK==true&& data->aiDetOK==true)?2:3);
if(data->halconOK == false || data->aiDetOK == false)
{
for (auto showMat : data->resultImgs)
{
QPixmap pixmap;
cvMatToQPixMap(showMat, pixmap);
showImgPack* pack = new showImgPack();
emit _core._qtFunc.uiModuleImageDoubleCheckQdialogShowWindows(pixmap);
}
}
}
//ct计算以及发送到界面
auto totalCt = std::chrono::duration_cast<std::chrono::milliseconds>(data->halconEndTime - data->algoStartTime);
auto aiCt = std::chrono::duration_cast<std::chrono::milliseconds>(data->handleAiEndTime - data->algoStartTime);
auto halconCt = std::chrono::duration_cast<std::chrono::milliseconds>(data->halconEndTime - data->handleAiEndTime);
if (totalCt.count() > 0)
emit _core._qtFunc.addCtData(0, totalCt.count());
if (aiCt.count() > 0)
emit _core._qtFunc.addCtData(1, aiCt.count());
if (halconCt.count() > 0)
emit _core._qtFunc.addCtData(2, halconCt.count());
//SQL
std::vector<sqlData> sqlDatas;
for (auto sqlData : data->sqlVec)
sqlDatas.push_back({ sqlData.first, std::to_string(sqlData.second) });
_core._appConfig._sqlManager.addData(data->SNcode, sqlDatas);
//写入plc
for (auto writeBackStr : data->writeBackData)
_triggerManager.sendFinsMsg(writeBackStr);
//储存结果图
std::async(std::launch::async, &imgSaveThreadManager::saveRes, &_imgSaveThreadManager, data);
//删除 不再持有
detDataManager* dManager = data->dManager;
data->dManager->deleteDetData(data->timeCode);
}
public slots:
void writeArmStartSignal(int productTypeIn, QString SN)
{
@@ -20,7 +20,8 @@ public:
ImageWidgetManager _ImageWidgetManager;
summaryDataManager* _summaryDataManager;
historyShowListWidget* historyImgs = new historyShowListWidget();
uiModule_LocationMap* _uiModule_LocationMap = new uiModule_LocationMap();
uiModuleLocationMap* _uiModuleLocationMap = new uiModuleLocationMap();
LogWindow* log = new LogWindow();
displayWidget()
{
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -46,12 +47,13 @@ public:
rightItemInit1();
rightItemInit2();
QObject::connect(historyImgs, &historyShowListWidget::itemClickSignal, this, &displayWidget::historyClick);
//historyImgs->addData(true, "D:/CCD/yuantu/2024-06-04/23H/TEST/1 (1).bmp", QPixmap("D:/CCD/yuantu/2024-06-04/23H/TEST/1 (1).bmp"));
}
void rightItemInit1()
{
QVBoxLayout* hLayout = new QVBoxLayout(rightWidget1);
hLayout->addWidget(_uiModule_LocationMap);
hLayout->addWidget(_uiModuleLocationMap);
hLayout->addWidget(historyImgs);
}
void rightItemInit2()
@@ -61,8 +63,8 @@ public:
hLayout->addWidget(_summaryDataManager->widget);
_switchProductWidget = new switchProductWidget();
hLayout->addWidget(_switchProductWidget);
LogWindow* log = new LogWindow();
hLayout->addWidget(log);
log->setStyleSheet("background-color: rgb(50,50,50);");
}
void leftItemInit()
{
@@ -89,6 +91,11 @@ public:
//leftWidget->setMaximumWidth(width / 1.2);
//rightWidget->setMaximumWidth(width / 2);
}
public slots:
void recvMainWindowStdLogMsg(QString msg)
{
log->addLog(msg);
}
private slots:
void historyClick(QString path)
{
@@ -97,6 +104,7 @@ private slots:
emit historyClickSignal(path);
emit changeStackWidget(3);
}
signals:
void historyClickSignal(QString);
void changeStackWidget(int);
+10 -2
View File
@@ -14,7 +14,12 @@ public:
{
emit qtLogSignal(QString::fromStdString(str));
}
void sendMainWindowStdLogSignal(std::string str)
{
emit mainWindowStdLogSignal(QString::fromStdString(str));
}
signals:
void mainWindowStdLogSignal(QString logMsg);
void stdLogSignal(QString logMsg);
void qtLogSignal(QString logMsg);
};
@@ -27,7 +32,7 @@ public:
logService()
{
//STD日志
#if enableHideConsle 1
_stdConsoleRedirector = new stdConsoleRedirector(std::cout);
//STD日志储存到文件
@@ -39,7 +44,10 @@ public:
_stdConsoleRedirector->registerCallback([&](const std::string& output) {
_logToQtWidget.sendStdLogSignal(output);
});
#endif
//STD日志到Qt主界面
_stdConsoleRedirector->registerCallback([&](const std::string& output) {
_logToQtWidget.sendMainWindowStdLogSignal(output);
});
//QT日志
LogMsg::Create(LogMsg::LogMsgType::DebugMsg, logBasePath);
qtLogCallbacks.push_back(([&](const std::string& output) {
+9 -2
View File
@@ -89,6 +89,8 @@ void connectSignalAndSlots(MainWindow* front, appCore* _core, detProcess* _detPr
front->_logWidget, &logWidget::recvStdLogMsg);
QObject::connect(&_core->_logService._logToQtWidget, &logToQtWidget::qtLogSignal,
front->_logWidget, &logWidget::recvQtLogMsg);
QObject::connect(&_core->_logService._logToQtWidget, &logToQtWidget::mainWindowStdLogSignal,
front->_displayWidget, &displayWidget::recvMainWindowStdLogMsg);
///////////TEMP
QObject::connect(&_core->_qtFunc, &qtFunction::addCtData, front, &MainWindow::addCtData);
@@ -101,8 +103,13 @@ void connectSignalAndSlots(MainWindow* front, appCore* _core, detProcess* _detPr
QObject::connect(&_core->_qtFunc, &qtFunction::addHistoryDataSignal, front, &MainWindow::addDetHistoryData);
QObject::connect(&_core->_qtFunc, &qtFunction::switchStartBtnStatusSignal,
front->_displayWidget->_switchProductWidget, &switchProductWidget::switchStartBtnStatus);
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleLocationMapResetToDefault,
front->_displayWidget->_uiModuleLocationMap, &uiModuleLocationMap::resetToDefault);
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleLocationMapSetProductSignStatus,
front, &MainWindow::uiModuleLocationMapSetProductSignStatus);
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleImageDoubleCheckQdialogShowWindows,
front, [=](QPixmap map) {front->_imageDoubleCheckQdialog->showAndSetImg(map); });
QObject::connect(&_detProcess->_manualDetThread, &manualDetThread::finishImgReadSignal,
front->_manualDetWidget, &manualDetWidget::finishImgReadSlot);
+7 -1
View File
@@ -18,6 +18,7 @@
#include <LoginWindow.h>
#include <QPropertyAnimation>
#include <loadingWidget.h>
#include <uiModule/uiModule_imageDoubleCheckQdialog.h>
#include <pages/displayPageWidget.h>
#include <pages/configSettingWidget.h>
@@ -57,6 +58,8 @@ public:
sqlControlWidget* _sqlControlWidget;
manualDetWidget* _manualDetWidget;
historyWidget* _historyWidget;
//人工复判窗口
imageDoubleCheckQdialog* _imageDoubleCheckQdialog = new imageDoubleCheckQdialog();
private:
Ui::MainWindow* ui;
fbBridge* fbBridgePtr;
@@ -257,7 +260,10 @@ public slots:
}
}
//void resetDashBoard();//reset dashBoard
void uiModuleLocationMapSetProductSignStatus(int pos, int status)
{
_displayWidget->_uiModuleLocationMap->setProductSignStatus(pos, status);
}
//void addShowPerformanceWidgetData(int index, int timeCost);
//void resetShowPerformanceWidget();
signals:
@@ -16,10 +16,19 @@ public:
// 添加日志信息
void addLog(const QString& message) {
QString logMessage = QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss] ") + message;
logTextEdit->append(logMessage); // 追加文本到日志框
QString text = "<span style='color: yellow;'>" + getCurrentDate() + "</span> "
"<span style='color: yellow;'>" + getCurrentTime() + "</span> "
"<span style='color: white;'>" + message + "</span> ";
logTextEdit->append(text);
}
QString getCurrentTime() {
QTime currentTime = QTime::currentTime();
return currentTime.toString("HH:mm:ss.zzz");
}
QString getCurrentDate() {
QDate currentDate = QDate::currentDate();
return currentDate.toString("yyyy-MM-dd");
}
private:
QTextEdit* logTextEdit;
};
@@ -26,15 +26,15 @@ public:
}
void setYellowBord()
{
setBorder(Qt::yellow, 30);
setBorder(Qt::yellow, 20);
}
void setRedBord()
{
setBorder(Qt::red, 30);
setBorder(Qt::red, 20);
}
void setGreenBord()
{
setBorder(Qt::green, 30);
setBorder(Qt::green, 20);
}
void disableToggleVisibility()
{
@@ -65,13 +65,13 @@ private:
setBrush(QBrush(color));
}
};
class uiModule_LocationMap :
class uiModuleLocationMap :
public QGraphicsView
{
Q_OBJECT
public:
QGraphicsScene* scene;
uiModule_LocationMap()
uiModuleLocationMap()
{
//scene = new QGraphicsScene();
//this->setScene(scene);
@@ -98,13 +98,8 @@ public:
QPixmap pixmap("F:/ciscoAoiUi/bin/imgPosTip/asr1006.png");
setImg(pixmap);
auto cData = _core._appConfig._switchProductWidgetDataPtr.getCurrentProductData();
std::vector<productSignStruct> r;
for (auto it = cData.productSign.begin(); it != cData.productSign.end(); it++)
{
r.push_back(it->second);
}
loadSignRects(r);
loadSignRects(cData.productSign);
resetToDefault();
}
void setImg(QPixmap pixmap)
{
@@ -116,42 +111,58 @@ public:
scene->clear();
setEnabled(false);
}
void loadSignRects(std::vector<productSignStruct>& rects)
void loadSignRects(std::unordered_map<int, productSignStruct>&rects)
{
for (auto& rect : rects)
for (auto& data : rects)
{
FlashingRectItem* _FlashingRectItem = new FlashingRectItem(0,0, rect.posRect.width, rect.posRect.height);
FlashingRectItem* _FlashingRectItem = new FlashingRectItem(0,0, data.second.posRect.width, data.second.posRect.height);
_FlashingRectItem->enableToggleVisibility();
//_FlashingRectItem->disableToggleVisibility();
_FlashingRectItem->setYellowBord();
_FlashingRectItem->setPos(rect.posRect.x, rect.posRect.y); // 设置矩形的位置
_FlashingRectItem->setPos(data.second.posRect.x, data.second.posRect.y); // 设置矩形的位置
scene->addItem(_FlashingRectItem);
flashItems.push_back(_FlashingRectItem);
flashItems.insert(std::make_pair(data.first,_FlashingRectItem));
}
}
public slots:
void resetToDefault()
{
for (auto& item : flashItems)
{
item.second->setYellowBord();
item.second->disableToggleVisibility();
}
}
void setProductSignStatus(int pos, int status)//设置产品示意图指定位置的状态
{
if (flashItems.size() < pos)
auto item = flashItems.find(pos);
if (item == flashItems.end())
return;
mutex.lock();
switch (status)
{
case 0:
flashItems[pos]->setGreenBord();
flashItems[pos]->disableToggleVisibility();
case 0://未检测
item->second->setYellowBord();
item->second->disableToggleVisibility();
break;
case 1:
flashItems[pos]->setYellowBord();
flashItems[pos]->enableToggleVisibility();
case 1://正在检测
item->second->setYellowBord();
item->second->enableToggleVisibility();
break;
case 2:
flashItems[pos]->setRedBord();
flashItems[pos]->disableToggleVisibility();
case 2://OK
item->second->setGreenBord();
item->second->disableToggleVisibility();
item->second->setVisible(true);
break;
case 3://NG
item->second->setRedBord();
item->second->disableToggleVisibility();
item->second->setVisible(true);
break;
}
mutex.unlock();
}
protected:
virtual void keyPressEvent(QKeyEvent* event) override
@@ -207,7 +218,7 @@ protected:
vBar->setValue(vBar->value() - delta.y());
}
private:
std::vector< FlashingRectItem*>flashItems;
std::unordered_map<int, FlashingRectItem*>flashItems;
void showImg(QPixmap img)
{
mutex.lock();
@@ -161,6 +161,7 @@ public slots:
showDataListWidget->setItemWidget(item, widget);
item->setSizeHint(widget->sizeHint());
widget->show();
showDataListWidget->scrollToBottom();
}
void reset()
{
@@ -17,7 +17,7 @@ public:
QPushButton* closeBtn = new QPushButton(this);
fancyButtonText* okBtn = new fancyButtonText(120, 40, "OK", "继续");
fancyButtonText* ngBtn = new fancyButtonText(120, 40, "NG", "继续");
imageDoubleCheckQdialog(QPixmap img)
imageDoubleCheckQdialog()
{
QPalette paletteWhite, paletteRed, paletteGreen;
paletteWhite.setColor(QPalette::WindowText, Qt::white);
@@ -87,7 +87,7 @@ public:
_ImageWidgetManager->createViewer("");
_ImageWidgetManager->disableAllSwitchBtn();
_ImageWidgetManager->showImg(img, imgWidgetShowType::imgWidgetOri, 0);
QHBoxLayout* okngBtnLayout = new QHBoxLayout();
okngBtnLayout->addWidget(okBtn);
okngBtnLayout->addWidget(ngBtn);
@@ -101,6 +101,11 @@ public:
layout->addLayout(imageViewLayout, 1, 0);
layout->addLayout(okngBtnLayout, 2, 0);
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
//this->show();
}
void showAndSetImg(QPixmap img)
{
_ImageWidgetManager->showImg(img, imgWidgetShowType::imgWidgetOri, 0);
this->show();
}
signals:
@@ -47,6 +47,8 @@ public:
"background-repeat: no-repeat;"
"background-position: center center;"
"}");
rectGroup = new QGraphicsItemGroup();
scene->addItem(rectGroup);
mutex.unlock();
}
void setImg(QPixmap pixmap)
@@ -59,6 +61,18 @@ public:
setEnabled(false);
}
protected:
void deleteAllRect()
{
if (rectGroup == nullptr)
return;
QList<QGraphicsItem*> items = rectGroup->childItems();
for (QGraphicsItem* item : items) {
QGraphicsRectItem* rect = qgraphicsitem_cast<QGraphicsRectItem*>(item);
rectGroup->removeFromGroup(rect);
scene->removeItem(rect);
delete rect;
}
}
virtual void wheelEvent(QWheelEvent* event) override
{
if (scene->children().size()==0)
@@ -67,6 +81,7 @@ protected:
if (!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
zoom(numSteps);
centerOn(currentPos);
}
event->accept();
}
@@ -85,15 +100,35 @@ protected:
event->accept();
return;
}
else if (event->button() == Qt::RightButton) {
startPos = mapToScene(event->pos());
rightClicked = true;
rectItem = new QGraphicsRectItem(QRectF(startPos, QSizeF(0, 0)));
rectItem->setPen(QPen(Qt::red, 10));
rectGroup->addToGroup(rectItem);
this->update();
return;
}
event->ignore();
}
virtual void mouseMoveEvent(QMouseEvent* event) override
{
currentPos = mapToScene(event->pos());
if (rightClicked == true)
{
QPointF endPos = currentPos;
// 计算矩形的宽度和高度
qreal width = endPos.x() - startPos.x();
qreal height = endPos.y() - startPos.y();26;
rectItem->setTransformOriginPoint(startPos);
rectItem->setRect(startPos.x(), startPos.y(), width, height);
}
if (m_isPan) {
pan(event->pos());
event->accept();
return;
}
event->ignore();
}
virtual void mouseReleaseEvent(QMouseEvent* event) override
@@ -103,6 +138,19 @@ protected:
event->accept();
return;
}
else if (event->button() == Qt::RightButton) {
rightClicked = false;
deleteAllRect();
QPointF endPos = mapToScene(event->pos());
// 计算矩形的宽度和高度
qreal width = endPos.x() - startPos.x();
qreal height = endPos.y() - startPos.y(); 26;
auto rect = this->rect();
double scaleRate = std::max(rect.width() / width, rect.height() / height);
scale(scaleRate, scaleRate);
centerOn(startPos.x() + width / 2, startPos.y() + height / 2);
return;
}
event->ignore();
}
void zoom(QPoint factor)
@@ -150,6 +198,11 @@ protected:
vBar->setValue(vBar->value() - delta.y());
}
private:
bool rightClicked = false;
QPointF currentPos;
QPointF startPos;
QGraphicsItemGroup* rectGroup;
QGraphicsRectItem* rectItem;
void showImg(QPixmap img)
{
mutex.lock();
@@ -168,7 +221,6 @@ private:
bool m_isPan;
QPoint m_prevPan;
QLabel* imgLabel;
QGraphicsItemGroup* rectGroup = nullptr;
int imageWidth = 1; int imageHeight = 1;
QMutex mutex;
};
@@ -81,6 +81,7 @@ public:
connect(startBtn, &QPushButton::clicked, this, [=]()
{
emit startArmProgramSignal(productSelect->currentIndex(), snIntputLine->text());
std::cout << "按下按钮" << std::endl;
});
connect(switchBtn, &QPushButton::clicked, this, &switchProductWidget::startSwitch);
connect(productSelect, &QComboBox::currentTextChanged, this, &switchProductWidget::currentProductSwitch);
@@ -132,12 +133,14 @@ public slots:
startBtn->toDefault();
startBtn->setText("运行");
snIntputLine->setDisabled(false);
std::cout << "按下软件运行" << std::endl;
}
else
{
startBtn->toRed();
startBtn->setText("急停");
snIntputLine->setDisabled(true);
std::cout << "按下软件急停" << std::endl;
}
}
signals:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 MiB