添加选择配置文件路径、选择图片保存路径功能(支持中文路径)

main
seiyu 1 year ago
parent 9fc16465ed
commit 79d7bb38c5

@ -133,7 +133,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp14</LanguageStandard> <LanguageStandard>stdcpp14</LanguageStandard>
<Optimization>MaxSpeed</Optimization> <Optimization>Disabled</Optimization>
<SupportJustMyCode>false</SupportJustMyCode> <SupportJustMyCode>false</SupportJustMyCode>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile> </ClCompile>
@ -141,7 +141,7 @@
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile> <OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries> <IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries> </IgnoreSpecificDefaultLibraries>

@ -17,18 +17,21 @@ bool AlgJd::init(QString model_path, QString model_name)
std::string classesFile; std::string classesFile;
cv::String modelConfiguration; cv::String modelConfiguration;
cv::String modelWeights; cv::String modelWeights;
QString image_path;
if (model_path.length() > 0 && model_name.length() > 0) { if (model_path.length() > 0 && model_name.length() > 0) {
// 拼凑的模型文件路径 // 拼凑的模型文件路径
modelWeights = model_path.toStdString() + "/" + model_name.toStdString(); modelWeights = model_path.toStdString() + "/" + model_name.toStdString();
modelConfiguration = model_path.toStdString() + "/jd.cfg"; modelConfiguration = model_path.toStdString() + "/jd.cfg";
classesFile = model_path.toStdString() + "/jd.names"; classesFile = model_path.toStdString() + "/jd.names";
image_path = model_path + "/" + "alg_jd.bmp";
} }
else { else {
modelWeights = "D:/model/jd.weights"; modelWeights = "D:/model/jd.weights";
classesFile = "D:/model/jd.names"; classesFile = "D:/model/jd.names";
// Give the configuration and weight files for the model // Give the configuration and weight files for the model
modelConfiguration = "D:/model/jd.cfg"; modelConfiguration = "D:/model/jd.cfg";
image_path = "D:/model/alg_jd.bmp";
} }
std::ifstream classNamesFile(classesFile.c_str()); std::ifstream classNamesFile(classesFile.c_str());
@ -49,13 +52,13 @@ bool AlgJd::init(QString model_path, QString model_name)
net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
//cv::Mat image = cv::imread("alg_jd.bmp"); //cv::Mat image = cv::imread("alg_jd.bmp");
cv::Mat image; cv::Mat image = cv::imread(image_path.toStdString());
if (g_sys_conf.model_jpg_path.length() > 0) { /*if (g_sys_conf.model_jpg_path.length() > 0) {
image = cv::imread(g_sys_conf.model_jpg_path.toStdString()); image = cv::imread(g_sys_conf.model_jpg_path.toStdString());
} }
else { else {
image = cv::imread("D:/Release/alg_jd.bmp"); image = cv::imread("D:/Release/alg_jd.bmp");
} }*/
//识别一张图测试模型是否正确并且完成GPU数据加载 //识别一张图测试模型是否正确并且完成GPU数据加载
if (!image.data) return false; //判断测试图片是否正常读取 if (!image.data) return false; //判断测试图片是否正常读取

@ -6,7 +6,6 @@
#include <PLCDevice.h> #include <PLCDevice.h>
#include <QtCore\qcryptographichash.h> #include <QtCore\qcryptographichash.h>
#include <QtCore\qprocess.h> #include <QtCore\qprocess.h>
#include <filesystem>
#include "exportData.h" #include "exportData.h"
int g_op_time; //操作员权限时长默认300秒 int g_op_time; //操作员权限时长默认300秒
@ -103,6 +102,7 @@ Cigarette::Cigarette(QWidget *parent)
ui.setupUi(this); ui.setupUi(this);
InitPtrMat(); InitPtrMat();
read_conf(g_conf_path); read_conf(g_conf_path);
if (!g_conf_path.config_path.isEmpty()) { if (!g_conf_path.config_path.isEmpty()) {
// 如果非空 // 如果非空
QDir* dirinfo = new QDir(g_conf_path.config_path); QDir* dirinfo = new QDir(g_conf_path.config_path);
@ -110,20 +110,11 @@ Cigarette::Cigarette(QWidget *parent)
// 如果文件夹信息不存在 // 如果文件夹信息不存在
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
g_conf_path.config_path = "D:/conf"; g_conf_path.config_path = "D:/conf";
g_conf_path.config_name = "conf.txt";
}
if (g_conf_path.config_name.isEmpty()) {
g_conf_path.config_name = "conf.txt";
} }
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
} }
else { else
// Èç¹û·¾¶¿Õ
g_conf_path.config_path = "D:/conf"; g_conf_path.config_path = "D:/conf";
if (g_conf_path.config_name.isEmpty())
g_conf_path.config_name = "conf.txt";
}
bool update_rotate = false; bool update_rotate = false;
if (!read_rotate_message()) { if (!read_rotate_message()) {
@ -227,12 +218,7 @@ Cigarette::Cigarette(QWidget *parent)
quantity_stop_count = 0; quantity_stop_count = 0;
g_seconds = 0; g_seconds = 0;
QString config_path; QString config_path = g_conf_path.config_path + "/conf.txt";
if (g_conf_path.config_path.isEmpty() || g_conf_path.config_name.isEmpty()) {
g_conf_path.config_path = "D:/conf";
g_conf_path.config_name = "conf.txt";
}
config_path = g_conf_path.config_path + "/" + g_conf_path.config_name;
read_sys_config(g_sys_conf, config_path); //初始化系统配置 read_sys_config(g_sys_conf, config_path); //初始化系统配置
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>0) #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>0)
@ -1016,7 +1002,8 @@ void Cigarette::OnKey(QKeyEvent* event)
char buf[256]; char buf[256];
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, SELECT_RECTS_FILE, Num,Cnt); sprintf(buf, SELECT_RECTS_FILE, Num,Cnt);
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + buf, ios::trunc | ofstream::out); QString rects_file = g_conf_path.config_path + "/" + buf;
cfg_file.open(rects_file.toLocal8Bit().constData(), ios::trunc | ofstream::out);
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file SelectRects.txt" << std::endl; std::cout << "Error: Open config file SelectRects.txt" << std::endl;
@ -1163,7 +1150,8 @@ void Cigarette::DrawRect_init(int Num_Cnt) {
char buf[256]; char buf[256];
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, SELECT_RECTS_FILE, Num, Cnt); sprintf(buf, SELECT_RECTS_FILE, Num, Cnt);
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + buf); QString rects_file = g_conf_path.config_path + "/" + buf;
cfg_file.open(rects_file.toLocal8Bit().constData());
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file SelectRects"<<Num<<Cnt<<".txt" << std::endl; std::cout << "Error: Open config file SelectRects"<<Num<<Cnt<<".txt" << std::endl;
@ -1209,7 +1197,8 @@ void Cigarette::OnTPClickHub(int Num_Cnt)
char buf[256]; char buf[256];
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, SELECT_RECTS_FILE, Num, Cnt); sprintf(buf, SELECT_RECTS_FILE, Num, Cnt);
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + buf); QString rects_file = g_conf_path.config_path + "/" + buf;
cfg_file.open(rects_file.toLocal8Bit().constData());
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file SelectRects.txt" << std::endl; std::cout << "Error: Open config file SelectRects.txt" << std::endl;
@ -1238,11 +1227,12 @@ void Cigarette::OnDBClickNGHub(int Num)
emit sengMsgToClog("Double click NG."); emit sengMsgToClog("Double click NG.");
QDateTime now_ts = QDateTime::currentDateTime(); QDateTime now_ts = QDateTime::currentDateTime();
std::ostringstream ostr; std::ostringstream ostr;
std::string file_path = g_conf_path.save_pics_path.toStdString(); QString file_path = g_conf_path.save_pics_path;
std::replace(file_path.begin(), file_path.end(), '/', '\\'); std::replace(file_path.begin(), file_path.end(), '/', '\\');
ostr << "explorer "<< file_path << "\\ng\\" << (now_ts.toString("yyyy-MM-dd")).toStdString()<< "\\" << Num+1 << "\\" << 1; ostr << "explorer "<< file_path.toLocal8Bit().constData() << "\\ng\\" << (now_ts.toString("yyyy-MM-dd")).toStdString()<< "\\" << Num+1 << "\\" << 1;
std::string str = ostr.str(); std::string str = ostr.str();
std::cout << "===>" << str << std::endl; //std::cout << "===>" << str << std::endl;
system(str.c_str()); system(str.c_str());
} }
@ -2332,13 +2322,17 @@ bool Cigarette::read_conf(ConfPath &conf_path) {
size_t pos = line.find('='); size_t pos = line.find('=');
std::string tmp_key = line.substr(0, pos); std::string tmp_key = line.substr(0, pos);
if (tmp_key == "CONF_PATH") { if (tmp_key == "CONF_PATH") {
conf_path.config_path = line.substr(pos + 1).c_str(); std::string str = line.substr(pos + 1).c_str();
} std::wstring w_str = String2WString(str);
else if (tmp_key == "CONF_NAME") { conf_path.config_path = QString::fromStdWString(w_str);
conf_path.config_name = line.substr(pos + 1).c_str();
} }
//else if (tmp_key == "CONF_NAME") {
// conf_path.config_name = line.substr(pos + 1).c_str();
//}
else if (tmp_key == "SAVE_PICS_PATH") { else if (tmp_key == "SAVE_PICS_PATH") {
conf_path.save_pics_path = line.substr(pos + 1).c_str(); std::string str = line.substr(pos + 1).c_str();
std::wstring w_str = String2WString(str);
conf_path.save_pics_path = QString::fromStdWString(w_str);
} }
} }
} }
@ -2349,7 +2343,7 @@ bool Cigarette::read_conf(ConfPath &conf_path) {
bool Cigarette::read_sys_config(SysConf &conf, QString conf_path) bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
{ {
std::fstream cfg_file; std::fstream cfg_file;
cfg_file.open(conf_path.toStdString()); cfg_file.open(conf_path.toLocal8Bit().constData());
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file " << conf_path.toStdString() << std::endl; std::cout << "Error: Open config file " << conf_path.toStdString() << std::endl;
@ -2735,7 +2729,8 @@ bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
bool Cigarette::read_modbus_config(ModbusConf &conf) bool Cigarette::read_modbus_config(ModbusConf &conf)
{ {
std::fstream cfg_file; std::fstream cfg_file;
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + MODBUS_CONFIGURE_FILE); QString modbus_file = g_conf_path.config_path + "/" + MODBUS_CONFIGURE_FILE;
cfg_file.open(modbus_file.toLocal8Bit().constData());
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file " << MODBUS_CONFIGURE_FILE << std::endl; std::cout << "Error: Open config file " << MODBUS_CONFIGURE_FILE << std::endl;
@ -2841,7 +2836,7 @@ bool Cigarette::read_rotate_message()
{ {
std::fstream cfg_file; std::fstream cfg_file;
QString rotate_file = g_conf_path.config_path + "/" + ROTATE_FILE; QString rotate_file = g_conf_path.config_path + "/" + ROTATE_FILE;
cfg_file.open(rotate_file.toStdString()); cfg_file.open(rotate_file.toLocal8Bit().constData());
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file rotate.txt" << std::endl; std::cout << "Error: Open config file rotate.txt" << std::endl;
@ -2878,7 +2873,7 @@ bool Cigarette::save_rotate_message()
{ {
std::fstream cfg_file; std::fstream cfg_file;
QString rotate_file = g_conf_path.config_path + "/" + ROTATE_FILE; QString rotate_file = g_conf_path.config_path + "/" + ROTATE_FILE;
cfg_file.open(rotate_file.toStdString(), ios::trunc | ofstream::out); cfg_file.open(rotate_file.toLocal8Bit().constData(), ios::trunc | ofstream::out);
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open config file rotate.txt" << std::endl; std::cout << "Error: Open config file rotate.txt" << std::endl;
@ -2960,7 +2955,8 @@ QImage Cigarette::cvMatToQImage(const cv::Mat& mat)
void Cigarette::read_plc_items() void Cigarette::read_plc_items()
{ {
std::fstream cfg_file; std::fstream cfg_file;
cfg_file.open(g_conf_path.config_path.toStdString() + "/" + PLC_CONFIG_FILE); QString plc_file = g_conf_path.config_path + "/" + PLC_CONFIG_FILE;
cfg_file.open(plc_file.toLocal8Bit().constData());
if (!cfg_file.is_open()) if (!cfg_file.is_open())
{ {
std::cout << "Error: Open production file " << PLC_CONFIG_FILE << std::endl; std::cout << "Error: Open production file " << PLC_CONFIG_FILE << std::endl;
@ -3808,9 +3804,9 @@ void Cigarette::record_output_statistic(qint64 quantity, int Kick[NumberOfSuppor
sprintf(str, STATISTIC_FILE, i); sprintf(str, STATISTIC_FILE, i);
char buf[256]; char buf[256];
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "%s/%s", g_conf_path.config_path, str); sprintf(buf, "%s/%s", g_conf_path.config_path.toLocal8Bit().constData(), str);
std::cout<<"===buf>"<<buf<<std::endl; //std::cout<<"===buf>"<<buf<<std::endl;
cfg_file.open(buf, std::ios::app); cfg_file.open(buf, std::ios::app);
if (cfg_file.good()) if (cfg_file.good())
{ {
@ -4020,7 +4016,7 @@ void Cigarette::recMsgFromUdp(QString data)
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, STATISTIC_FILE, i); sprintf(buf, STATISTIC_FILE, i);
QString str(buf); QString str(buf);
sThread.sendFile(str, g_sys_conf.FilePort); sThread.sendFile(str.toLocal8Bit().constData(), g_sys_conf.FilePort);
} }
} }

@ -362,4 +362,64 @@ std::string SelectDirIFD()
pfd->Release(); pfd->Release();
} }
return folderpath; return folderpath;
}
std::string UTF8ToGBK(std::string utf8_str) {
// 获得临时变量的大小
int wchar_len = MultiByteToWideChar(CP_UTF8, 0, utf8_str.c_str(), -1, NULL, 0);
wchar_t *wchar_buf = new wchar_t[wchar_len];
MultiByteToWideChar(CP_UTF8, 0, utf8_str.c_str(), -1, wchar_buf, wchar_len);
// 获得临时变量的大小
int char_len = WideCharToMultiByte(CP_ACP, 0, wchar_buf, -1, NULL, 0, NULL, NULL);
char* char_buf = new char[char_len];
WideCharToMultiByte(CP_ACP, 0, wchar_buf, -1, char_buf, char_len, NULL, NULL);
std::string gbk_str(char_buf);
delete[] wchar_buf;
delete[] char_buf;
return gbk_str;
}
void stdString2QString(std::string str, QString& qs) {
qs = QString::fromLocal8Bit(QByteArray::fromRawData(str.c_str(), str.size()));
}
void QString2stdString(QString qs, std::string& str) {
str = qs.toLocal8Bit().constData();
}
std::string WString2String(const std::wstring& ws) {
// 进行地域设置,"" 表示当前OS默认的地域设置成功则返回当前地域设置的名称
std::string strLocate = setlocale(LC_ALL, "");
const wchar_t* wchSrc = ws.c_str();
size_t nDestSize = wcstombs(NULL, wchSrc, 0) + 1;
char* chDest = new char[nDestSize];
memset(chDest, 0, nDestSize);
wcstombs(chDest, wchSrc, nDestSize);
std::string strResult = chDest;
delete[] chDest;
setlocale(LC_ALL, strLocate.c_str());
return strResult;
}
std::wstring String2WString(const std::string& str) {
std::wstring wContext = L"";
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
WCHAR* buffer = new WCHAR[len + 1];
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
buffer[len] = '\0';
wContext.append(buffer);
delete[] buffer;
return wContext;
}
std::vector<std::string> SpiteStringCharacter(std::string context) {
std::vector<std::string> res;
std::wstring wContext = String2WString(context);
for (int i = 0; i < wContext.length(); i++) {
std::wstring tmp = wContext.substr(i, 1);
res.push_back(WString2String(tmp));
}
return res;
} }

@ -58,15 +58,20 @@ void getFiles(std::string path, std::vector<std::string>& files);
std::string SelectDirBRI(); std::string SelectDirBRI();
std::string SelectFileOFN(); std::string SelectFileOFN();
std::string SelectDirIFD(); std::string SelectDirIFD();
std::string UTF8ToGBK(std::string utf8_str);
std::string WString2String(const std::wstring& ws);
std::wstring String2WString(const std::string& str);
std::vector<std::string> SpiteStringCharacter(std::string context);
class ConfPath { class ConfPath {
public: public:
QString config_path; // 配置文件路径 QString config_path; // 配置文件路径
QString config_name; // 配置文件名 //QString config_name; // 配置文件名
QString save_pics_path; // 保存图片存储路径 QString save_pics_path; // 保存图片存储路径
ConfPath(){ ConfPath(){
config_path = ""; config_path = "";
config_name = ""; //config_name = "";
save_pics_path = ""; save_pics_path = "";
} }
}; };

@ -57,37 +57,26 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
} }
if (!g_conf_path.config_path.isEmpty()) { if (!g_conf_path.config_path.isEmpty()) {
// 如果配置文件存储路径非空
QDir* dirinfo = new QDir(g_conf_path.config_path); QDir* dirinfo = new QDir(g_conf_path.config_path);
if (!dirinfo->exists()) if (!dirinfo->exists()) {
// 如果文件夹信息不存在
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
dirinfo->setNameFilters(QStringList("*.txt")); g_conf_path.config_path = "D:/conf";
}
dirinfo->setNameFilters(QStringList("conf.txt"));
QStringList fileList = dirinfo->entryList(QDir::Files); QStringList fileList = dirinfo->entryList(QDir::Files);
fileList.removeOne("."); fileList.removeOne(".");
fileList.removeOne(".."); fileList.removeOne("..");
ui.comboBox_config_path->clear();
ui.comboBox_config_path->addItems(fileList);
if (!g_conf_path.config_name.isEmpty())
ui.comboBox_config_path->setCurrentText(g_conf_path.config_name);
else {
g_conf_path.config_name = "conf.txt";
ui.comboBox_config_path->setCurrentText(g_conf_path.config_name);
}
// 更换选择文件
connect(ui.comboBox_config_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxConfSelect(int)));
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
} }
else { else {
// 如果路径空 // 如果路径空
g_conf_path.config_path = "D:/conf"; g_conf_path.config_path = "D:/conf";
if (!g_conf_path.config_name.isEmpty()) {
ui.comboBox_model_path->setCurrentText(g_conf_path.config_name);
}
else {
g_conf_path.config_name = "conf.txt";
ui.comboBox_model_path->addItem(g_conf_path.config_name);
}
} }
ui.comboBox_config_path->addItem(g_conf_path.config_path);
// 更换选择文件
connect(ui.comboBox_config_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxConfSelect(int)));
if (!g_sys_conf.model_path.isEmpty()) { if (!g_sys_conf.model_path.isEmpty()) {
// 如果曾经选择过模型文件夹 // 如果曾经选择过模型文件夹
@ -105,8 +94,6 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
// 如果曾选择过模型则在comboBox显示选择模型的文件名 // 如果曾选择过模型则在comboBox显示选择模型的文件名
ui.comboBox_model_path->setCurrentText(g_sys_conf.model_name); ui.comboBox_model_path->setCurrentText(g_sys_conf.model_name);
} }
// 更换模型事件
connect(ui.comboBox_model_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxSelect(int)));
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
} }
else { else {
@ -116,6 +103,8 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
ui.comboBox_model_path->addItem(g_sys_conf.model_name); ui.comboBox_model_path->addItem(g_sys_conf.model_name);
} }
} }
// 更换模型事件
connect(ui.comboBox_model_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxSelect(int)));
if (!g_conf_path.save_pics_path.isEmpty()) { if (!g_conf_path.save_pics_path.isEmpty()) {
// 如果配置文件里保存图片路径非空 // 如果配置文件里保存图片路径非空
@ -128,8 +117,6 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
ui.comboBox_save_pics_path->clear(); ui.comboBox_save_pics_path->clear();
ui.comboBox_save_pics_path->addItem(g_conf_path.save_pics_path); ui.comboBox_save_pics_path->addItem(g_conf_path.save_pics_path);
// 更换选择文件
connect(ui.comboBox_save_pics_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPicsPathSelect(int)));
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
} }
else { else {
@ -141,6 +128,9 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) {
ui.comboBox_save_pics_path->setCurrentText(dirPath); ui.comboBox_save_pics_path->setCurrentText(dirPath);
g_conf_path.save_pics_path = dirPath; g_conf_path.save_pics_path = dirPath;
} }
// 更换选择文件
connect(ui.comboBox_save_pics_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPicsPathSelect(int)));
switch (g_sys_conf.save) switch (g_sys_conf.save)
{ {
@ -171,12 +161,14 @@ void DialogSetup::onComboBoxPicsPathSelect(int index) {
QString cp = ui.comboBox_save_pics_path->currentText(); QString cp = ui.comboBox_save_pics_path->currentText();
//QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("您选择的项为") + cp, NULL); //QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("您选择的项为") + cp, NULL);
g_conf_path.save_pics_path = cp; g_conf_path.save_pics_path = cp;
write_conf_path();
} }
void DialogSetup::onComboBoxConfSelect(int index) { void DialogSetup::onComboBoxConfSelect(int index) {
QString cp = ui.comboBox_config_path->currentText(); QString cp = ui.comboBox_config_path->currentText();
//QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("您选择的项为") + cp, NULL); //QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("您选择的项为") + cp, NULL);
g_conf_path.config_name = cp; g_conf_path.config_path = cp;
write_conf_path();
} }
void DialogSetup::onComboBoxSelect(int index) { void DialogSetup::onComboBoxSelect(int index) {
@ -334,7 +326,6 @@ void DialogSetup::on_pushButton_save_released()
g_sys_conf.filter[i] = (lineEdit_filter_mat[i]->text()).toInt(); g_sys_conf.filter[i] = (lineEdit_filter_mat[i]->text()).toInt();
} }
write_conf_path();
write_config(); write_config();
QMessageBox::information(NULL, QStringLiteral("提示"), QStringLiteral("保存参数成功,部分配置需要重启程序后生效"), QMessageBox::Ok); QMessageBox::information(NULL, QStringLiteral("提示"), QStringLiteral("保存参数成功,部分配置需要重启程序后生效"), QMessageBox::Ok);
} }
@ -367,35 +358,32 @@ void DialogSetup::on_toolButton_choose_config_path_released() {
dirName = "D:/conf"; dirName = "D:/conf";
else else
dirName = g_conf_path.config_path; dirName = g_conf_path.config_path;
ui.comboBox_config_path->addItem(dirName);
g_conf_path.config_path = dirName;
g_conf_path.config_name = "conf.txt";
} }
QDir* dirinfo = new QDir(dirName); QDir* dirinfo = new QDir(dirName);
if (!dirinfo->exists()) if (!dirinfo->exists())
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
dirinfo->setNameFilters(QStringList("*.txt"));
dirinfo->setNameFilters(QStringList("conf.txt"));
QStringList fileList = dirinfo->entryList(QDir::Files); QStringList fileList = dirinfo->entryList(QDir::Files);
if (fileList.count() == 0) { if (fileList.count() == 0) {
g_conf_path.config_path = "D:/conf"; dirName = "D:/conf";
g_conf_path.config_name = "conf.txt";
} }
else {
g_conf_path.config_path = dirName;
g_conf_path.config_name = ui.comboBox_config_path->currentText();
}
fileList.removeOne("."); //fileList.removeOne(".");
fileList.removeOne(".."); //fileList.removeOne("..");
ui.comboBox_config_path->clear(); QFileInfo fileInfo(dirName);
ui.comboBox_config_path->addItems(fileList);
connect(ui.comboBox_config_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxConfSelect(int)));
if (fileInfo.isDir() && ui.comboBox_config_path->findText(fileInfo.absoluteFilePath())) {
ui.comboBox_config_path->addItem(fileInfo.absoluteFilePath());
ui.comboBox_config_path->setCurrentText(fileInfo.absoluteFilePath());
}
g_conf_path.config_path = dirName;
connect(ui.comboBox_config_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxConfSelect(int)));
write_conf_path();
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
} }
@ -463,6 +451,7 @@ void DialogSetup::on_toolButton_choose_save_pics_path_released() {
connect(ui.comboBox_save_pics_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPicsPathSelect(int))); connect(ui.comboBox_save_pics_path, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPicsPathSelect(int)));
delete dirinfo, dirinfo = nullptr; delete dirinfo, dirinfo = nullptr;
write_conf_path();
} }
void DialogSetup::on_toolButton_choose_path_jpg_released() { void DialogSetup::on_toolButton_choose_path_jpg_released() {
@ -510,13 +499,13 @@ void DialogSetup::write_conf_path() {
if (cfg_file.good()) { if (cfg_file.good()) {
char buf[256]; char buf[256];
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "CONF_PATH=%s\n", g_conf_path.config_path.toStdString().c_str()); sprintf(buf, "CONF_PATH=%s\n", g_conf_path.config_path.toLocal8Bit().constData());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "CONF_NAME=%s\n", g_conf_path.config_name.toStdString().c_str());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
//memset(buf, 0, 256);
//sprintf(buf, "CONF_NAME=%s\n", g_conf_path.config_name.toStdString().c_str());
//cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "SAVE_PICS_PATH=%s\n", g_conf_path.save_pics_path.toStdString().c_str()); sprintf(buf, "SAVE_PICS_PATH=%s\n", g_conf_path.save_pics_path.toLocal8Bit().constData());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
} }
cfg_file.close(); cfg_file.close();
@ -524,8 +513,8 @@ void DialogSetup::write_conf_path() {
void DialogSetup::write_config() void DialogSetup::write_config()
{ {
std::fstream cfg_file; std::fstream cfg_file;
QString cfg_path = g_conf_path.config_path + "/" + g_conf_path.config_name; QString cfg_path = g_conf_path.config_path + "/conf.txt";
cfg_file.open(cfg_path.toStdString().c_str(), std::ios::out | std::ios::trunc); cfg_file.open(cfg_path.toLocal8Bit().constData(), std::ios::out | std::ios::trunc);
if (cfg_file.good()) if (cfg_file.good())
{ {
char buf[256]; char buf[256];
@ -578,7 +567,7 @@ void DialogSetup::write_config()
sprintf(buf, "MODELPATH=%s\n", g_sys_conf.model_path.toStdString().c_str()); sprintf(buf, "MODELPATH=%s\n", g_sys_conf.model_path.toStdString().c_str());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "MODELNAME=%s\n", g_sys_conf.model_name.toStdString().c_str()); sprintf(buf, "MODELNAME=%s\n", g_sys_conf.model1_name.toStdString().c_str());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "JPGPATH=%s\n", g_sys_conf.model_jpg_path.toStdString().c_str()); sprintf(buf, "JPGPATH=%s\n", g_sys_conf.model_jpg_path.toStdString().c_str());

@ -2,6 +2,7 @@
#include <QDialog> #include <QDialog>
#include "ui_dialogsetup.h" #include "ui_dialogsetup.h"
#include "basecamera.h" #include "basecamera.h"
#include <qdebug.h>
#include <common.h> #include <common.h>
#include <camera_glue.h> #include <camera_glue.h>
#include <output_statistic.h> #include <output_statistic.h>

File diff suppressed because it is too large Load Diff

@ -21,8 +21,8 @@ int main(int argc, char *argv[])
splash.show(); splash.show();
a.processEvents(); a.processEvents();
Cigarette w; Cigarette w;
//w.show(); w.show();
w.showFullScreen(); //w.showFullScreen();
splash.finish(&w); splash.finish(&w);
return a.exec(); return a.exec();
} }

@ -82,13 +82,16 @@ void output_statistic::recMsgFromDialogSetup()
for (int i = 0; i < NumberOfSupportedCameras; i++) { for (int i = 0; i < NumberOfSupportedCameras; i++) {
file_name = QString(STATISTIC_FILE).arg(i); file_name = QString(STATISTIC_FILE).arg(i);
file_path = g_conf_path.config_path + "/" + file_name; file_path = g_conf_path.config_path + "/" + file_name;
//std::cout << "===>" << file_path.toStdString() << std::endl;
file.setFileName(file_path); file.setFileName(file_path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
QTextStream in(&file); QTextStream in(&file);
//in.setCodec("UTF-8");
textBrowser_mat[i]->setText(in.readAll()); textBrowser_mat[i]->setText(in.readAll());
} }
else {
std::cout << "can not open statistic file" << std::endl;
}
file.close(); file.close();
this->show(); this->show();
} }

Loading…
Cancel
Save