Files
handleaiuinew/HanddleAI/HandleAiUi-new/appConfig/appconfigStruct.h
T
2024-08-13 18:07:24 +08:00

227 lines
5.8 KiB
C++

#include <opencv.hpp>
#include <string>
#include <vector>
#include <appConfig/json/generalJsonParsing.hpp>
#include <simpleTools/stringAlgo.h>
#include <uiModule/components/fancyDialog.h>
#include <simpleTools/fileManager.h>
#include <sqlManager/sqlManager.h>
#include <writeExcel.h>
struct productSignStruct
{
cv::Rect posRect;
std::string sign;
};
struct productDataStruct
{
std::string name;
std::string customerPartNumber;
std::string foxconnPartNumber;
int indexOfArm = 0;
cv::Vec3d basePos;
cv::Vec3d baseRad;
std::string imgPosPath;
int connectorAmout = 0;
int halconAlgoIndex = -1;
bool isBackExist = false;
int backArmIndex = 0;
//int为步骤数 std::string为指令
std::unordered_map <int, std::vector<std::string>>cameraSetting;
//int为步骤数 第二个int为光源亮度 max255
std::unordered_map<int, int>lightSetting;
//这两个bool值为true时根据codedAlgoIndex的值进到写死的检测代码中
//启用之后下面的handleAiSimpleDet只会用于初始化模型!
bool disableHandleAiConfig = false;
bool enableCodedAlgo = false;
int codedAlgoIndex = -1;
std::unordered_map<int, productSignStruct> productSign;
};
struct perConnector
{
bool aiOk = false,halconOk = false;
double maxPinDetValue = -1;
std::string name;
std::string resultStr;
std::string showStr;
std::string timeStr;
};
class productCacheBase
{
public:
productCacheBase()
{
startTimePoint = std::chrono::high_resolution_clock::now();
creatTime = getCurrentDateTime();
}
void writeProductData(std::string SNin, productDataStruct&_productDataStructIn)
{
endTimePoint = std::chrono::high_resolution_clock::now();
SN = SNin;
connectorAmount = _productDataStructIn.connectorAmout;
partNumber = _productDataStructIn.foxconnPartNumber;
}
void saveData(std::string path)
{
endTimePoint = std::chrono::high_resolution_clock::now();
//测试时间
customExcelStruct dataSave(creatTime);
//"耗时"
dataSave.nexCols.push_back(customExcelStruct(calculateDuration(startTimePoint, endTimePoint)));
//"SN"
dataSave.nexCols[0]
.nexCols.push_back(customExcelStruct(SN));
//"机种槽数"
dataSave.nexCols[0]
.nexCols[0]
.nexCols.push_back(customExcelStruct(std::to_string(connectorAmount)));
//"Part Number"
dataSave.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols.push_back(customExcelStruct(partNumber));
//"连接器编号"
dataSave.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols.push_back(customExcelStruct(connectorCode));
//"不良点数"
dataSave.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols.push_back(customExcelStruct(std::to_string(ngCount)));
for (auto connectorResult : connectorResults)
{
//"Pin编号"
customExcelStruct connector(connectorResult.name);
//"Pin结果"
std::string pinResult;
if (connectorResult.aiOk == true && connectorResult.halconOk == true)
pinResult = "OK";
else
{
if (connectorResult.aiOk == false)
pinResult += "aiNG;";
if (connectorResult.halconOk == false)
pinResult += "halconNG";
}
connector.nexCols.push_back(customExcelStruct(pinResult));
//"Pin测试值"
connector.nexCols[0]
.nexCols.push_back(customExcelStruct(std::to_string(connectorResult.maxPinDetValue)));
//测试结果
connector.nexCols[0]
.nexCols[0]
.nexCols.push_back(customExcelStruct(connectorResult.resultStr));
//汇总
dataSave.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols[0]
.nexCols.push_back(connector);
}
writeExcel(path, "Sheet1", titles, dataSave);
}
std::vector<perConnector> connectorResults;
std::string creatTime;
std::chrono::steady_clock::time_point startTimePoint;
std::chrono::steady_clock::time_point endTimePoint;
std::string SN = "NULL";
int ngCount = -1;
int ngPinCount = -1;
//从配置文件获取
int connectorAmount = -1;
std::string partNumber = "NULL";
std::string connectorCode = "NULL";
private:
std::string calculateDuration(const std::chrono::steady_clock::time_point& start, const std::chrono::steady_clock::time_point& end) {
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration);
auto seconds = duration - minutes;
std::ostringstream oss;
oss << minutes.count() << "分:" << std::setw(2) << std::setfill('0') << seconds.count() << "秒";
return oss.str();
}
std::vector<std::string> titles = {
"测试时间", "耗时", "SN",
"机种槽数", "Part Number",
"连接器编号", "不良点数", "Pin编号",
"Pin结果", "Pin测试值", "测试结果" };
};
class switchProductWidgetDataPtr
{
public:
productDataStruct getCurrentProductData() {
productDataStruct result;
if (mutex == nullptr)
return result;
if (productDatasPtr == nullptr)
return result;
mutex->lock();
result = productDatasPtr->at(currentProductIndex);
mutex->unlock();
return result;
}
std::vector<productDataStruct> getAllProductData() {
std::vector<productDataStruct> result;
if (mutex == nullptr)
return result;
if (productDatasPtr == nullptr)
return result;
mutex->lock();
result = *productDatasPtr;
mutex->unlock();
return result;
}
int currentProductIndex = 0;//switchProductWidget
std::vector<productDataStruct>* productDatasPtr = nullptr;//appConfig
std::mutex* mutex = nullptr;//appConfig
};
struct lightSourceStruct
{
std::string deviceName;
std::string comName;
int baudRate;
std::string initStr;
};
struct triggerStruct
{
std::string key;
std::string initStr;
std::string heartCmd;
std::string readAllCmd;
std::string modelName;
int sleepTime;
int readNum;
std::string writeType;
int startPos;
};
struct cameraStruct
{
std::string key;
std::string connectionName;//per Sec
std::string serialNum;
std::string triggerMode;
std::string moduleName;
};
struct sqlConfigStruct
{
std::unordered_map<std::string, std::string>datas;
};
#pragma once