123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419 |
- #include "CGH_Printer.h"
- #include <qdatetime.h>
- #include <qlabel.h>
- #include <thread>
- #include "CGH_State.h"
- #include <fstream>
- #include <map>
- #include <iostream>
- // #include "CGH_CoordinateThread.h"
- #include <math.h>
- #include <io.h>
- #include <set>
- #include <QMessageBox>
- #include <QFileDialog>
- #include <cstdio>
- #include <QButtonGroup>
- #include <stdlib.h>
- #include <time.h>
- #include <sstream>
- #define FREEBUF(x) {if(x!=NULL){delete [] x;x=NULL;}}
- CGH_Printer* gcam = NULL;// 线程函数中使用的全局变量
- #include <QDebug>
- CGH_Printer::CGH_Printer(QWidget* parent)
- : QMainWindow(parent)
- {
- ui.setupUi(this);
- //----------------------------------------修改tabwidget的颜色
- ////widget 背景色属性
- //ui.tabWidget->setAttribute(Qt::WA_StyledBackground);
- ////标题栏红色背景,tab选中蓝色,未选中灰色
- //ui.tabWidget->setStyleSheet("QTabWidget#tabWidget{background-color:rgb(255,0,0);}\
- // QTabBar::tab{background-color:rgb(220,200,180);color:rgb(0,0,0);font:10pt '新宋体'}\
- // QTabBar::tab::selected{background-color:rgb(0,100,200);color:rgb(255,0,0);font:10pt '新宋体'}");
- ////绿色背景
- //ui.tab->setStyleSheet("QWidget#tab{"
- // "background-color:#00ff00;"
- // "border:1px solid #eeeeee;}");
- //--------------------------------------------------------------------------------------------------------------
- Desktop = new QDesktopWidget();
- QRect MainWindow = Desktop->screenGeometry(0);
- this->setGeometry(MainWindow);
- this->move((MainWindow.width()-this->width())/2, (MainWindow.height()-this->height())/2);
- initVariables();
- initConfigure();
- initSlots();
- timer_calendar->start(500);// 定时器的刷新间隔
- // CheckState->start();// 线程调用
- // Coordinate->start();// 线程调用
-
- }
- void CGH_Printer::initVariables()
- {
- // 定时器对象的初始化
- timer_calendar = new QTimer();
- timer_WorkState = new QTimer();// 工作状态检测
- timer_Expose = new QTimer();
- timer_Work = new QTimer();
- timer_Work->setInterval(100);
- timer_WorkState->setInterval(100);
- // 线程对象的初始化
- // CheckState = new CGH_CheckStateThread(this);// 硬件状态检测线程的初始化
- m_Printer = new PrintThread(this);
- // Coordinate = new CGH_CoordinateThread(this);// 平移台坐标更新线程的初始化
- // 状态检测的初始化
- icon_Red = new QImage();
- icon_Green = new QImage();
- icon_Red->load(":/CGH_Printer/Configure/IMG/Redlight.png");
- icon_Green->load(":/CGH_Printer/Configure/IMG/Greenlight.png");
- curShutterState = false;
- error_messages.append(SHUTTER_ERROR_MESSAGE);
- curSLMState = false;
- error_messages.append(SLM_ERROR_MESSAGE);
- curTransTableState = false;
- error_messages.append(TRANSTABLE_ERROR_MESSAGE);
- curCCDState = false;
- error_messages.append(CCD_ERROR_MESSAGE);
- curShutterWorkState = false;
- // 快门对象的初始化
- MyShutter = new CGH_Shutter();
- // t1 = new QElapsedTimer();
- // CCD变量的初始化
- m_pCameraInfos = QCameraInfo::availableCameras();
- m_pCamera = new QCamera(this);
- m_pCameraCapture = new QCameraImageCapture(m_pCamera);
- m_pViewfinder = new QCameraViewfinder(ui.widgetCCD);
- m_pViewfinder->resize(ui.widgetCCD->size());
- m_pCameraOpen = FALSE;
- // 平移台变量的初始化
- ControllerID = -1;// 控制器ID
- DeviceNum = 0;// 设备数量
- ControllerIDN = new char[BufferSize];// 接受IDN字符的缓冲区
- sAxis = "1";// 轴标识符
- // 工程对象的初始化
- pButtonGroup = new QButtonGroup();
- pButtonGroup->setExclusive(true);
- // SLM显示弹窗对象的初始化
- // Desktop = new QDesktopWidget();
- labelPrint = new QLabel();
- PRINTSTOP = FALSE;
- }
- void CGH_Printer::initConfigure()
- {
- // 路径的初始化
- ProjectType = ".pro";
- ConfigureName = "Configure.txt";
- absPath = (QCoreApplication::applicationDirPath()).toStdString();
- relConfigurePath = "../Configure";
- relProjectPath = "../Project";
- relCapturePath = "../Capture";
- relResourcesPath = "../Resources";
- absConfigurePath = absPath + "/" + relConfigurePath;
- absProjectPath = absPath + "/" + relProjectPath;
- absCapturePath = absPath + "/" + relCapturePath;
- absResourcesPath = absPath + "/" + relResourcesPath;
- // 工作状态的初始化
- ui.labelWorkState->setText("就绪");
- // 打印进度条的初始化
- ui.progressBarPrint->setMinimum(0);
- ui.progressBarPrint->setMaximum(100);
- ui.progressBarPrint->setValue(0);
- //double dProgress = (ui.progressBarPrint->value() - ui.progressBarPrint->minimum()) * 100.0
- // / (ui.progressBarPrint->maximum() - ui.progressBarPrint->minimum());
- //ui.progressBarPrint->setFormat(QString::fromLocal8Bit("当前进度为:%1%").arg(QString::number(dProgress, 'f', 50)));
- //ui.progressBarPrint->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 对齐方式
- // Shutter状态的初始化
- // MyShutter->connect();
- curShutterState = MyShutter->isconnected();
- if (curShutterState)
- {
- error_messages.removeOne(SHUTTER_ERROR_MESSAGE);
- ui.labelShutter->clear();
- ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Green));
- }
- // SLM状态的初始化
- //int SLM_Num = Desktop->numScreens();//获取当前环境屏幕个数
- if (Desktop->numScreens() == 2)
- {
- curSLMState = true;
- error_messages.removeOne(SLM_ERROR_MESSAGE);
- ui.labelSLM->clear();
- ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Green));
- SLMDisplay();
- }
- // CCD设备的初始化
- if (m_pCameraInfos.size() > 0)
- {
- curCCDState = true;
- error_messages.removeOne(CCD_ERROR_MESSAGE);
- ui.labelCCD->clear();
- ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Green));
- ComboDevice();
- }
- // 平移台控制的初始化
- // 通讯连接
- ControllerID = PI_OpenRS232DaisyChain(8, 115200, &DeviceNum, ControllerIDN, BufferSize);
- // 如果成功打开菊花链,则开始进行通讯连接
- if (ControllerID != -1)
- {
- curTransTableState = true;
- error_messages.removeOne(TRANSTABLE_ERROR_MESSAGE);
- ui.labelStages->clear();
- ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Green));
- PITransTableInit();
- }
- for (const QString msg : error_messages) {
- ui.textEditWarning->insertPlainText(msg + '\n');
- }
- ReadConfigure();
- loadHistory();
- }
- void CGH_Printer::initSlots()
- {
- connect(timer_calendar, SIGNAL(timeout()), this, SLOT(timerUpdate()));
- connect(timer_WorkState, SIGNAL(timeout()), this, SLOT(WorkStateUpdate()));
- connect(timer_Expose, SIGNAL(timeout()), this, SLOT(ExposeUpdate()));
- connect(timer_Work, SIGNAL(timeout()), this, SLOT(WorkTimeUpdate()));
- // 作业页面
- connect(ui.pushButtonNew, SIGNAL(clicked()), this, SLOT(NewProject()));
- connect(ui.pushButtonModify, SIGNAL(clicked()), this, SLOT(ModifyProject()));
- connect(ui.pushButtonDelete, SIGNAL(clicked()), this, SLOT(DeleteProject()));
- connect(ui.pushButtonFeed, SIGNAL(clicked()), this, SLOT(Feed()));
- connect(ui.pushButtonUnderfeed, SIGNAL(clicked()), this, SLOT(Underfeed()));
- connect(ui.pushButtonPrint, SIGNAL(clicked()), this, SLOT(PrintTemp()));
- connect(ui.pushButtonPrintOK, SIGNAL(clicked()), this, SLOT(PrintProgress()));
- connect(ui.pushButtonPrintCancel, SIGNAL(clicked()), this, SLOT(PrintStop()));
- connect(ui.pushButtonPreview, SIGNAL(clicked()), this, SLOT(Preview()));
- //connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(Preview()));//添加一个槽函数,页面切换打开相机
- connect(ui.pushButtonSnapshot, SIGNAL(clicked()), this, SLOT(Snapshot()));
- connect(ui.comboBoxDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(ChangeDevice()));
- connect(ui.comboBoxFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(ChangeFormat()));
- connect(ui.pushButtonLoad, SIGNAL(clicked()), this, SLOT(CGHLoad()));
- // *** 电控平移台 *** //
- connect(ui.pushButtonUp, SIGNAL(clicked()), this, SLOT(MoveUp()));
- connect(ui.pushButtonDown, SIGNAL(clicked()), this, SLOT(MoveDown()));
- connect(ui.pushButtonLeft, SIGNAL(clicked()), this, SLOT(MoveLeft()));
- connect(ui.pushButtonRight, SIGNAL(clicked()), this, SLOT(MoveRight()));
- connect(ui.pushButtonTranstableStop, SIGNAL(clicked()), this, SLOT(TranstableStop()));
- connect(ui.pushButtonBlank, SIGNAL(clicked()), this, SLOT(MoveZero()));
- // *** 电子快门 *** //
- connect(ui.pushButtonShutterExpose, SIGNAL(clicked()), this, SLOT(Expose()));
- connect(ui.pushButtonShutterStop, SIGNAL(clicked()), this, SLOT(ShutterStop()));
- // *** 配置保存 *** //
- connect(ui.pushButtonTempSaved, SIGNAL(clicked()), this, SLOT(TempSaved()));
- connect(ui.pushButtonPermSaved, SIGNAL(clicked()), this, SLOT(PermSaved()));
-
- }
- void CGH_Printer::ReadConfigure()
- {
- // 配置文件加载
- ifstream infile;
- map<string, string> maps_Configure;
- string name_temp, value_temp;
- infile.open(absConfigurePath + "/" + ConfigureName);
- if (infile)
- {
- while (!infile.eof())
- {
- infile >> name_temp >> value_temp;
- maps_Configure[name_temp] = value_temp;
- }
- }
- infile.close();
- // 参数设置
- ui.lineEditMoveUp->setText(QString::fromStdString(maps_Configure["前"]));
- ui.lineEditMoveDown->setText(QString::fromStdString(maps_Configure["后"]));
- ui.lineEditMoveLeft->setText(QString::fromStdString(maps_Configure["左"]));
- ui.lineEditMoveRight->setText(QString::fromStdString(maps_Configure["右"]));
- ui.lineEditShutter->setText(QString::fromStdString(maps_Configure["时间"]));
- ReadTransTableConfigue();
- // 设置曝光时间输入为整数
- QIntValidator* aIntValidator;
- aIntValidator = new QIntValidator(this);
- ui.lineEditShutter->setValidator(aIntValidator);
- ui.lineEditPrinted->setText("00:00:00");
- ui.lineEditStart->setText("00:00:00");
- }
- void CGH_Printer::loadHistory()
- {
- _finddata_t data;
- auto handle = _findfirst((absProjectPath + "/*.*").c_str(), &data);// 读取第一文件或文件夹
- do
- {
- string fullname = data.name;// 文件名
- // 去掉文件名后缀
- int length = strlen(fullname.c_str()) - strlen(ProjectType.c_str());
- string name = fullname.substr(0, length);
- if (fullname.rfind(ProjectType) == fullname.size() - ProjectType.size())// 判断后缀是否为.type
- {
- addProject(name);
- }
- } while (_findnext(handle, &data) == 0);
- _findclose(handle);
- }
- // 时间更新
- void CGH_Printer::timerUpdate()
- {
- QDateTime time = QDateTime::currentDateTime();
- QString str = time.toString("yyyy-MM-dd \nhh:mm:ss");
- ui.labelDatetime->setText(str);
- }
- //// 硬件工作状态检测
- //void CGH_Printer::StateUpdate(int statetype)
- //{
- // // SLM工作状态检测
- // if (statetype == SLM_ERROR)
- // {
- // curSLMState = false;
- // delete Desktop;
- // delete labelPrint;
- //
- // ui.labelSLM->clear();
- // ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Red));
- // error_messages.append(SLM_ERROR_MESSAGE);
- // }
- // else if (statetype == SLM_OK)
- // {
- // curSLMState = true;
- // Desktop = new QDesktopWidget();
- // labelPrint = new QLabel();
- // SLMDisplay();
- //
- // ui.labelSLM->clear();
- // ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Green));
- // error_messages.removeOne(SLM_ERROR_MESSAGE);
- // }
- //
- // // 电子快门工作状态检测
- // if (statetype == SHUTTER_ERROR)
- // {
- // curShutterState = false;
- // delete MyShutter;
- //
- // ui.labelShutter->clear();
- // ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Red));
- // error_messages.append(SHUTTER_ERROR_MESSAGE);
- // }
- // else if (statetype == SHUTTER_OK)
- // {
- // MyShutter = new CGH_Shutter();
- // MyShutter->connect();
- // curShutterState = MyShutter->isconnected();
- //
- // ui.labelShutter->clear();
- // ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Green));
- // error_messages.removeOne(SHUTTER_ERROR_MESSAGE);
- // }
- //
- // // 平移台工作状态检测
- // if (statetype == TRANSTABLE_ERROR)
- // {
- // curTransTableState = false;
- // ControllerID = -1;
- // DeviceNum = 0;
- // delete ControllerIDN;
- //
- // ui.labelStages->clear();
- // ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Red));
- // error_messages.append(TRANSTABLE_ERROR_MESSAGE);
- // }
- // else if (statetype == TRANSTABLE_OK)
- // {
- // ControllerID = PI_OpenRS232DaisyChain(8, 115200, &DeviceNum, ControllerIDN, BufferSize);
- // if (ControllerID != -1)
- // {
- // curTransTableState = true;
- // PITransTableInit();
- //
- // ui.labelStages->clear();
- // ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Green));
- // error_messages.removeOne(TRANSTABLE_ERROR_MESSAGE);
- // }
- // }
- //
- // // CCD工作状态检测
- // if (statetype == CCD_ERROR)
- // {
- // curCCDState = false;
- // ComboDevice();
- //
- // ui.labelCCD->clear();
- // ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Red));
- // error_messages.append(CCD_ERROR_MESSAGE);
- // }
- // else if (statetype == CCD_OK)
- // {
- // curCCDState = true;
- // ComboDevice();
- //
- // ui.labelCCD->clear();
- // ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Green));
- // error_messages.removeOne(CCD_ERROR_MESSAGE);
- // }
- //
- // ui.textEditWarning->clear();
- // for (const QString msg : error_messages) {
- // ui.textEditWarning->insertPlainText(msg + '\n');
- // }
- //}
- void CGH_Printer::BusyState()
- {
- ui.labelStateMarking->setPixmap(QPixmap(":/CGH_Printer/Configure/IMG/Parallelogram_Red.png"));
- ui.labelWorkState->setText("正忙");
- }
- void CGH_Printer::ReadyState()
- {
- ui.labelStateMarking->setPixmap(QPixmap(":/CGH_Printer/Configure/IMG/Parallelogram_Green.png"));
- ui.labelWorkState->setText("就绪");
- }
- void CGH_Printer::ReadTransTableConfigue()
- {
- if (ControllerID != -1)
- {
- PI_qACC(Devices[0], sAxis.c_str(), &AccX);
- PI_qACC(Devices[1], sAxis.c_str(), &AccY);
- PI_qDEC(Devices[0], sAxis.c_str(), &DecX);
- PI_qDEC(Devices[1], sAxis.c_str(), &DecY);
- PI_qVEL(Devices[0], sAxis.c_str(), &MaxvX);
- PI_qVEL(Devices[1], sAxis.c_str(), &MaxvY);
- ui.lineEditAccX->setText(QString::number(AccX, 'f', 3));
- ui.lineEditAccY->setText(QString::number(AccY, 'f', 3));
- ui.lineEditDecX->setText(QString::number(DecX, 'f', 3));
- ui.lineEditDecY->setText(QString::number(DecY, 'f', 3));
- ui.lineEditMaxvX->setText(QString::number(MaxvX, 'f', 3));
- ui.lineEditMaxvY->setText(QString::number(MaxvY, 'f', 3));
- }
- }
- void CGH_Printer::WorkStateUpdate()
- {
- BOOL isMoving_sAxisX = FALSE;
- BOOL isMoving_sAxisY = FALSE;
- if (curTransTableState)
- {
- PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
- PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
- }
- if (isMoving_sAxisX || isMoving_sAxisY)
- {
- CoordinateUpdate();
- }
- else if (!isMoving_sAxisX && !isMoving_sAxisY && !curShutterWorkState)
- {
- ReadyState();
- timer_WorkState->stop();
- }
- }
- void CGH_Printer::MoveUp()
- {
- if (curTransTableState)
- {
- double offset = ui.lineEditMoveUp->text().toDouble();
- offset = -1 * offset;
- if (!PI_MVR(Devices[1], sAxis.c_str(), &offset))
- {
- QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
- }
- else
- {
- BusyState();
- timer_WorkState->start();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::MoveDown()
- {
- if (curTransTableState)
- {
- double offset = ui.lineEditMoveDown->text().toDouble();
- if (!PI_MVR(Devices[1], sAxis.c_str(), &offset))
- {
- QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
- }
- else
- {
- BusyState();
- timer_WorkState->start();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- // 平移台左移
- void CGH_Printer::MoveLeft()
- {
- if (curTransTableState)
- {
- double offset = ui.lineEditMoveLeft->text().toDouble();
- if (!PI_MVR(Devices[0], sAxis.c_str(), &offset))
- {
- QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
- }
- else
- {
- BusyState();
- timer_WorkState->start();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- // 平移台右移
- void CGH_Printer::MoveRight()
- {
- if (curTransTableState)
- {
- double offset = ui.lineEditMoveRight->text().toDouble();
- offset = -1 * offset;
- if (!PI_MVR(Devices[0], sAxis.c_str(), &offset))
- {
- QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
- }
- else
- {
- BusyState();
- timer_WorkState->start();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::MoveZero()
- {
- if (curTransTableState)
- {
- bool isMoving_sAxisX = TRUE;
- bool isMoving_sAxisY = TRUE;
- isMoving_sAxisX = PI_GOH(Devices[0], sAxis.c_str());
- isMoving_sAxisY = PI_GOH(Devices[1], sAxis.c_str());
- if (isMoving_sAxisX || isMoving_sAxisY)
- {
- BusyState();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("不能移动到零点!"));
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::TranstableStop()
- {
- if (curTransTableState)
- {
- PI_HLT(Devices[0], sAxis.c_str());
- PI_HLT(Devices[1], sAxis.c_str());
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::Expose()
- {
- if (curShutterState)
- {
- BusyState();
- int Ext = ui.lineEditShutter->text().toInt();// 快门曝光时间
- timer_Expose->setInterval(Ext);
- MyShutter->open();
- curShutterWorkState = true;
- timer_Expose->start();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::ShutterStop()
- {
- if (curShutterState)
- {
- MyShutter->close();
- curShutterWorkState = false;
- timer_Expose->stop();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::ExposeUpdate()
- {
- timer_Expose->stop();
- MyShutter->close();
- curShutterWorkState = false;
- }
- void CGH_Printer::WorkTimeUpdate()
- {
- timePrintCur = clock();
- Printtimed = (timePrintCur - timePrintStart) / CLOCKS_PER_SEC;
- string Worktimed;
- Worktimed = formatTime(Printtimed);
- ui.lineEditPrinted->setText(QString::fromStdString(Worktimed));
- }
- void CGH_Printer::PrintOKUpdate()
- {
- ReadyState();
- // UI控件设置
- ui.pushButtonPrintOK->setChecked(false);
- labelPrint->clear();
- ui.labelSLMCopy->clear();
- timer_Work->stop();
- ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
- QMessageBox::about(this, tr("提示"), tr("打印已完成!"));
- }
- void CGH_Printer::PrintCancelUpdate()
- {
- ReadyState();
- // UI控件设置
- ui.pushButtonPrintOK->setChecked(false);
- ui.progressBarPrint->setValue(0);
- ui.lineEditPrinted->setText("00:00:00");
- ui.lineEditStart->setText("00:00:00");
- labelPrint->clear();
- ui.labelSLMCopy->clear();
- ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
- timer_Work->stop();
- QMessageBox::about(this, tr("提示"), tr("打印已停止!"));
- }
- // 平移台轴坐标实时更新
- void CGH_Printer::CoordinateUpdate()
- {
- PI_qPOS(Devices[0], sAxis.c_str(), &CoordinateX);
- PI_qPOS(Devices[1], sAxis.c_str(), &CoordinateY);
- ui.labelXPosition->setText(QString::number(CoordinateX, 'f', 3));
- ui.labelYPosition->setText(QString::number(CoordinateY, 'f', 3));
- }
- // 新建工程
- void CGH_Printer::NewProject()
- {
- CGH_ProjectView* myNewProjectView = new CGH_ProjectView(this);
- CGH_Project* myNewProject = new CGH_Project();
- myNewProjectView->initWindow();
- if (myNewProjectView->exec() == QDialog::Accepted) {
- //保存参数
- myNewProject->setWorkName(myNewProjectView->getViewName());
- myNewProject->setWorkLSpacing(myNewProjectView->getViewLSpacing());
- myNewProject->setWorkCSpacing(myNewProjectView->getViewCSpacing());
- myNewProject->setWorkLine(myNewProjectView->getViewLine());
- myNewProject->setWorkColumn(myNewProjectView->getViewColumn());
- myNewProject->setWorkPrefix(myNewProjectView->getViewPrefix());
- myNewProject->setWorkExpose(myNewProjectView->getViewExpose());
- myNewProject->setWorkQuiet(myNewProjectView->getViewQuiet());
- myNewProject->setWorkResource(myNewProjectView->getViewResource());
- myNewProject->saveToLocal();
- addProject(myNewProject);
- }
- }
- // 修改工程
- void CGH_Printer::ModifyProject() {
- if (pButtonGroup->checkedButton())
- {
- CGH_ProjectView* myModifyProjectView = new CGH_ProjectView(this);
- string ModifyProjectName = (pButtonGroup->checkedButton())->text().toStdString();
- CGH_Project* myModifyProject = new CGH_Project(ModifyProjectName);
- myModifyProjectView->initWindow();
- myModifyProjectView->setViewName(myModifyProject->getWorkName());
- myModifyProjectView->setViewLSpacing(myModifyProject->getWorkLSpacing());
- myModifyProjectView->setViewCSpacing(myModifyProject->getWorkCSpacing());
- myModifyProjectView->setViewLine(myModifyProject->getWorkLine());
- myModifyProjectView->setViewColumn(myModifyProject->getWorkColumn());
- myModifyProjectView->setViewPrefix(myModifyProject->getWorkPrefix());
- myModifyProjectView->setViewExpose(myModifyProject->getWorkExpose());
- myModifyProjectView->setViewQuiet(myModifyProject->getWorkQuiet());
- myModifyProjectView->setViewResource(myModifyProject->getWorkResource());
- if (myModifyProjectView->exec() == QDialog::Accepted) {
- string fullProjectName;
- fullProjectName = absProjectPath + "/" + (myModifyProject->getWorkName()) + ProjectType;
- remove(fullProjectName.c_str());
- ui.verticalLayoutWork->removeWidget(pButtonGroup->checkedButton());
- delete pButtonGroup->checkedButton();
- myModifyProject->setWorkName(myModifyProjectView->getViewName());
- myModifyProject->setWorkLSpacing(myModifyProjectView->getViewLSpacing());
- myModifyProject->setWorkCSpacing(myModifyProjectView->getViewCSpacing());
- myModifyProject->setWorkLine(myModifyProjectView->getViewLine());
- myModifyProject->setWorkColumn(myModifyProjectView->getViewColumn());
- myModifyProject->setWorkPrefix(myModifyProjectView->getViewPrefix());
- myModifyProject->setWorkExpose(myModifyProjectView->getViewExpose());
- myModifyProject->setWorkQuiet(myModifyProjectView->getViewQuiet());
- myModifyProject->setWorkResource(myModifyProjectView->getViewResource());
- myModifyProject->saveToLocal();
- addProject(myModifyProject);
- }
- }
- else
- {
- QMessageBox::about(this, tr("提示"), tr("未选中工程!"));
- }
- }
- // 添加工程文件
- void CGH_Printer::addProject(CGH_Project* pj)
- {
- string WorkName = pj->getWorkName();
- addProject(WorkName);
- }
- void CGH_Printer::addProject(const string& name)
- {
- QPushButton* Button = new QPushButton;
- string fullprojectName = name + ProjectType;
- Button->setText(QString::fromLocal8Bit(fullprojectName.c_str()));
- Button->setCheckable(true);
- //Button->setAutoExclusive(true);
- pButtonGroup->addButton(Button);
- ui.verticalLayoutWork->addWidget(Button);
- }
- // 删除工程文件
- void CGH_Printer::DeleteProject()
- {
- string fileName;
- QString ButtonName;
- fileName = (pButtonGroup->checkedButton())->text().toStdString();
- ButtonName = (pButtonGroup->checkedButton())->objectName();
- QPushButton* tempButton = this->findChild<QPushButton *>(ButtonName);
- string fullProjectName;
- fullProjectName = absProjectPath + "/" + fileName;
- if (QMessageBox::warning(this, tr("提示"), tr("确定删除工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- remove(fullProjectName.c_str());
- ui.verticalLayoutWork->removeWidget(pButtonGroup->checkedButton());
- delete pButtonGroup->checkedButton();
- }
- return;
- }
- void CGH_Printer::Underfeed()
- {
- if (curTransTableState)
- {
- if (!PI_GOH(Devices[0], sAxis.c_str()) && !PI_FNL(Devices[1], sAxis.c_str()))
- {
- QMessageBox::critical(this, tr("错误"), tr("不能完成下料!"));
- }
- else
- {
- BusyState();
- timer_WorkState->start();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::TempSaved()
- {
- if (curTransTableState)
- {
- if (QMessageBox::information(this, tr("提示"), tr("是否暂时保存配置?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- AccX = ui.lineEditAccX->text().toDouble();
- AccY = ui.lineEditAccY->text().toDouble();
- DecX = ui.lineEditDecX->text().toDouble();
- DecY = ui.lineEditDecY->text().toDouble();
- MaxvX = ui.lineEditMaxvX->text().toDouble();
- MaxvY = ui.lineEditMaxvY->text().toDouble();
- PI_SPA(Devices[0], sAxis.c_str(), &Acc, &AccX, NULL);
- PI_SPA(Devices[1], sAxis.c_str(), &Acc, &AccY, NULL);
- PI_SPA(Devices[0], sAxis.c_str(), &Dec, &DecX, NULL);
- PI_SPA(Devices[1], sAxis.c_str(), &Dec, &DecY, NULL);
- PI_SPA(Devices[0], sAxis.c_str(), &Maxv, &MaxvX, NULL);
- PI_SPA(Devices[1], sAxis.c_str(), &Maxv, &MaxvY, NULL);
- }
- else
- {
- ReadTransTableConfigue();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::PermSaved()
- {
- if (curTransTableState)
- {
- if (QMessageBox::information(this, tr("提示"), tr("是否永久保存配置?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- AccX = ui.lineEditAccX->text().toDouble();
- AccY = ui.lineEditAccY->text().toDouble();
- DecX = ui.lineEditDecX->text().toDouble();
- DecY = ui.lineEditDecY->text().toDouble();
- MaxvX = ui.lineEditMaxvX->text().toDouble();
- MaxvY = ui.lineEditMaxvY->text().toDouble();
- PI_SPA(Devices[0], sAxis.c_str(), &Acc, &AccX, NULL);
- PI_SPA(Devices[1], sAxis.c_str(), &Acc, &AccY, NULL);
- PI_SPA(Devices[0], sAxis.c_str(), &Dec, &DecX, NULL);
- PI_SPA(Devices[1], sAxis.c_str(), &Dec, &DecY, NULL);
- PI_SPA(Devices[0], sAxis.c_str(), &Maxv, &MaxvX, NULL);
- PI_SPA(Devices[1], sAxis.c_str(), &Maxv, &MaxvY, NULL);
- PI_RPA(Devices[0], sAxis.c_str(), &Acc);
- PI_RPA(Devices[1], sAxis.c_str(), &Acc);
- PI_RPA(Devices[0], sAxis.c_str(), &Dec);
- PI_RPA(Devices[1], sAxis.c_str(), &Dec);
- PI_RPA(Devices[0], sAxis.c_str(), &Maxv);
- PI_RPA(Devices[1], sAxis.c_str(), &Maxv);
- }
- else
- {
- ReadTransTableConfigue();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- void CGH_Printer::Feed()
- {
- if (curTransTableState)
- {
- if (!PI_GOH(Devices[1], sAxis.c_str()) && !PI_GOH(Devices[0], sAxis.c_str()))
- {
- QMessageBox::critical(this, tr("错误"), tr("不能完成上料!"));
- }
- else
- {
- BusyState();
- timer_WorkState->start();
- }
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
- }
- }
- // 打印选中的工程
- void CGH_Printer::PrintTemp()
- {
- if (pButtonGroup->checkedButton())
- {
- Print();
- }
- else
- {
- QMessageBox::about(this, tr("提示"), tr("未选中工程!"));
- }
- }
- void CGH_Printer::Print()
- {
- if (QMessageBox::information(this, tr("提示"), tr("是否加载工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- string PrintProjectName = (pButtonGroup->checkedButton())->text().toStdString();
- CGH_Project* PrintProject = new CGH_Project(PrintProjectName);
- PrintName = PrintProject->getWorkName();
- PrintLSpacing = stod(PrintProject->getWorkLSpacing());
- PrintCSpacing = stod(PrintProject->getWorkCSpacing());
- PrintLine = stoi(PrintProject->getWorkLine());
- PrintColumn = stoi(PrintProject->getWorkColumn());
- PrintPrefix = PrintProject->getWorkPrefix();
- PrintExpose = stoi(PrintProject->getWorkExpose());
- PrintQuiet = stoi(PrintProject->getWorkQuiet());
- PrintResource = PrintProject->getWorkResource();
- ui.tabWidget->setCurrentIndex(3);
- ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
- ui.progressBarPrint->setValue(0);
- labelPrint->clear();
- // 加载实物图
- string sep = "/";
- string Format = ".bmp";
- string Phyfilename;// 实物图路径
- Phyfilename = PrintResource + sep + PrintPrefix + Format;
- ui.labelPhy->setPixmap(QPixmap(QString::fromStdString(Phyfilename)));
- }
- }
- void CGH_Printer::SLMUpdate(const QString& tempCGH)
- {
- labelPrint->clear();
- labelPrint->setPixmap(QPixmap(tempCGH));
- ui.labelSLMCopy->setPixmap(QPixmap(tempCGH));
- QString CurPrintName;
- CurPrintName = QString::fromStdString(PrintName) + "(" + tempCGH + ")";
- ui.lineEditPrintName->setText(tempCGH);
- }
- void CGH_Printer::PrintUpdate(int tempLL, int tempCC)
- {
- PrintLL = tempLL;
- PrintCC = tempCC;
- CurProgress = (PrintLL - 1) * PrintColumn + PrintCC;
- FulProgress = PrintLine * PrintColumn;
- ui.progressBarPrint->setMaximum(FulProgress);
- ui.progressBarPrint->setValue(CurProgress);
- }
- void CGH_Printer::PrintStop()
- {
- if (QMessageBox::warning(this, tr("提示"), tr("是否停止打印?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- PRINTSTOP = TRUE;
- }
- }
- // 打印工作进程
- void CGH_Printer::PrintProgress()
- {
- if (!ui.lineEditPrintName->text().isEmpty() && curTransTableState && curShutterState && curSLMState)
- {
- if (QMessageBox::warning(this, tr("提示"), tr("是否开始打印?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- PRINTSTOP = FALSE;
- BusyState();
- // 开始工作时间
- QDateTime timeStart = QDateTime::currentDateTime();
- QString str = timeStart.toString("hh:mm:ss");
- ui.lineEditStart->setText(str);
- // 已打印
- timePrintStart = clock();
- timer_Work->start();
- m_Printer->start();
- }
- else
- {
- ui.pushButtonPrintOK->setChecked(false);
- }
- }
- else if (ui.lineEditPrintName->text().isEmpty())
- {
- ui.pushButtonPrintOK->setChecked(false);
- QMessageBox::about(this, tr("提示"), tr("未加载工程!"));
- }
- else
- {
- ui.pushButtonPrintOK->setChecked(false);
- QMessageBox::about(this, tr("提示"), tr("请检查电子快门、空间光调制器和电控平移台的状态!"));
- }
- }
- void CGH_Printer::ComboDevice()
- {
- ui.comboBoxDevice->clear();
- m_pCameraInfos = QCameraInfo::availableCameras();
- for (int i = 0; i < m_pCameraInfos.size(); i++)
- {
- ui.comboBoxDevice->addItem(m_pCameraInfos[i].description());
- }
- m_pCameraIndex = ui.comboBoxDevice->currentIndex();
- }
- // 切换设备
- void CGH_Printer::ChangeDevice()
- {
- if (m_pCameraOpen)
- {
- CloseCamera();
- m_pCameraIndex = ui.comboBoxDevice->currentIndex();
- OpenCamera();
- ComboFormatandFramerate();
- }
- }
- // 切换分辨率
- void CGH_Printer::ChangeFormat()
- {
- if (m_pCameraOpen)
- {
- QString strFormat = ui.comboBoxFormat->currentText();
- QStringList ListFormat = strFormat.split('x');
- CloseCamera();
- m_pCamera = new QCamera(m_pCameraInfos[m_pCameraIndex]);
- QCameraViewfinderSettings* m_pCameraSet = new QCameraViewfinderSettings();
- m_pCameraSet->setResolution(ListFormat[0].toInt(), ListFormat[1].toInt());
- m_pCamera->setViewfinderSettings(*m_pCameraSet);
- m_pCamera->setViewfinder(m_pViewfinder);
- m_pCamera->start();
- }
- }
- void CGH_Printer::CGHLoad()
- {
- QFileDialog* CGH_dialog = new QFileDialog(this);
- QString filefull;
- QString Fullfilename;
- QFileInfo fileinfo;
- QString curPath = QString::fromStdString(absResourcesPath);// 默认路径
- // 路径不存在则创建路径
- QDir dir(curPath);
- if (!dir.exists(curPath))
- {
- dir.mkdir(curPath);
- }
- QString dlgTitle = "选择文件";// 对话框标题
- QString filter = "Bmp Files(*.bmp)";// 文件过滤器
- filefull = CGH_dialog->getOpenFileName(this, dlgTitle, curPath, filter);
- QFileInfo file(filefull);
- //点击确定按钮
- if (file.isFile() && file.exists())
- {
- //获取新建项目路径
- fileinfo = QFileInfo(filefull);
- Fullfilename = fileinfo.absolutePath() + "/" + fileinfo.fileName();
- ui.lineEditCGHName->setText(Fullfilename);//设置路径栏
- ui.labelCGHDisplay->clear();
- ui.labelCGHDisplay->setPixmap(QPixmap(Fullfilename));
- // labelPrint->setPixmap(QPixmap(Fullfilename));
- if (Desktop->numScreens() == 2)
- {
- labelPrint->clear();
- labelPrint->setPixmap(QPixmap(Fullfilename));
- }
- }
- //点取消则返回
- else
- {
- return;
- }
- delete CGH_dialog;
- CGH_dialog = NULL;
- }
- // 视频预览
- void CGH_Printer::Preview()
- {
- if (m_pCameraInfos.size() > 0)
- {
- if (!m_pCameraOpen)
- {
- ui.pushButtonPreview->setText("停止");
- OpenCamera();
- ComboFormatandFramerate();
- m_pCameraOpen = TRUE;
- }
- else
- {
- ui.pushButtonPreview->setText("预览");
- CloseCamera();
- m_pCameraOpen = FALSE;
- ui.comboBoxFormat->clear();
- ui.comboBoxFramerate->clear();
- delete m_pCamera;
- }
- }
- else
- {
- QMessageBox::about(this, tr("提示"), tr("打开相机失败!"));
- }
- }
- // 视频截图
- void CGH_Printer::Snapshot()
- {
- if (m_pCameraOpen)
- {
- string filename;
- m_pCameraCapture = new QCameraImageCapture(m_pCamera);
- m_pCameraCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
- QString curPath = QString::fromStdString(absCapturePath);// 默认路径
- // 路径不存在则创建路径
- QDir dir(curPath);
- if (!dir.exists(curPath))
- {
- dir.mkdir(curPath);
- }
- QString dlgTitle = "保存文件";// 对话框标题
- QString filter = "Jpep Files(*.jpg)";// 文件过滤器
- QString aFileName = QFileDialog::getSaveFileName(this, dlgTitle, curPath, filter);
- if (!aFileName.isEmpty())
- m_pCameraCapture->capture(aFileName);
- // 默认输出到Capture文件夹
- // QDir dir(QString::fromStdString(absCapturePath));
- // dir.setFilter(QDir::Files | QDir::NoSymLinks);
- // QFileInfoList list = dir.entryInfoList();
- // int file_count = list.count();
- // if (!dir.exists() || file_count <= 0)
- // {
- // filename = absCapturePath + "/Cap_0";
- // }
- // else
- // {
- // QStringList string_list;
- // int maxindex = 0;
- // for (int i = 0; i < file_count; i++)
- // {
- // QFileInfo file_info = list.at(i);
- // QString curfilename = file_info.fileName();
- // int start = curfilename.lastIndexOf("_");
- // int end = curfilename.lastIndexOf(".");
- // QString temp = curfilename.mid(start+1, end - start-1);
- // int curindex = temp.toInt();
- // maxindex = qMax(maxindex, curindex);
- // }
- // filename = absCapturePath + "/Cap_" + to_string(maxindex + 1);
- // }
- }
- else
- {
- QMessageBox::about(this, tr("提示"), tr("相机未开启!"));
- }
- }
- void CGH_Printer::ComboFormatandFramerate()
- {
- QList<QSize> m_pCameraFormats = m_pCamera->supportedViewfinderResolutions();
- QString strFormat;
- foreach(QSize m_pCameraFormat, m_pCameraFormats)
- {
- strFormat = QString("%1x%2").arg(m_pCameraFormat.width()).arg(m_pCameraFormat.height());
- ui.comboBoxFormat->addItem(strFormat);
- }
- QList<QCamera::FrameRateRange> m_pCameraFramerates = m_pCamera->supportedViewfinderFrameRateRanges();
- foreach(QCamera::FrameRateRange m_pCameraFramerate, m_pCameraFramerates)
- {
- ui.comboBoxFramerate->addItem(QString::number(m_pCameraFramerate.maximumFrameRate, 'f', 0));
- }
- }
- void CGH_Printer::OpenCamera()
- {
- m_pCamera = new QCamera(m_pCameraInfos[m_pCameraIndex]);
- m_pCamera->setViewfinder(m_pViewfinder);
- m_pCamera->setCaptureMode(QCamera::CaptureStillImage);
- m_pCamera->start();
- QList<QSize> ViewFormats = m_pCamera->supportedViewfinderResolutions();
- QCameraViewfinderSettings* initm_pCameraSet = new QCameraViewfinderSettings();
- initm_pCameraSet->setResolution(ViewFormats[0].width(), ViewFormats[0].height());
- QList<QCamera::FrameRateRange> ViewFramerates = m_pCamera->supportedViewfinderFrameRateRanges();
- initm_pCameraSet->setMaximumFrameRate(ViewFramerates[0].maximumFrameRate);
- initm_pCameraSet->setMinimumFrameRate(ViewFramerates[0].minimumFrameRate);
- m_pCamera->setViewfinderSettings(*initm_pCameraSet);
- }
- void CGH_Printer::CloseCamera()
- {
- m_pCamera->stop();
- }
- void CGH_Printer::SLMDisplay()
- {
- QRect winMain = Desktop->screenGeometry(1);
- labelPrint->setGeometry(winMain);
- labelPrint->setWindowFlags(Qt::FramelessWindowHint |
- Qt::WindowStaysOnTopHint |
- Qt::Popup | Qt::Tool);//设置窗口弹出、无边框、窗口置顶
- //labelPrint->setWindowFlags(Qt::FramelessWindowHint |
- // Qt::WindowStaysOnTopHint |
- // Qt::Popup | Qt::Tool);//设置窗口弹出、无边框、窗口置顶
- labelPrint->setCursor(Qt::BlankCursor);
- //labelPrint->move(winMain.width(), 0);
- labelPrint->showFullScreen();
- labelPrint->setAlignment(Qt::AlignCenter);
- labelPrint->setScaledContents(true);
- }
- void CGH_Printer::PITransTableInit()
- {
- for (int num = 1; num <= DeviceNum; num++)
- {
- int Device = PI_ConnectDaisyChainDevice(ControllerID, num);
- if (Device >= 0)
- {
- Devices.push_back(Device);
- }
- }
- // 轴开启伺服控制
- for (const auto& Device : Devices)
- {
- PI_SVO(Device, sAxis.c_str(), &SERVO_ON);
- }
- BusyState();
- timer_WorkState->start();
- // 轴参考移动
- for (const auto& Device : Devices)
- {
- PI_FRF(Device, sAxis.c_str());
- }
- }
- void CGH_Printer::closeEvent(QCloseEvent* event)
- {
- if (QMessageBox::information(this, tr("提示"), tr("是否关闭程序?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
- {
- event->accept();
- }
- else
- {
- event->ignore();
- }
- }
- string CGH_Printer::numberToString(int n,int l)
- {
- string res = to_string(n);
- int length = res.size();
- while (length++ < l) {
- res = "0" + res;
- }
- return res;
- }
- std::string CGH_Printer::formatTime(long ss)
- {
- int mi = 60;
- int hh = mi * 60;
- long hour = ss / hh;
- long minute = (ss - hour * hh) / mi;
- long second = ss - hour * hh - minute * mi;
- string shour, sminute, ssecond;
- shour = numberToString(hour, 2);
- sminute = numberToString(minute, 2);
- ssecond = numberToString(second, 2);
- string format;
- format = shour + ":" + sminute + ":" + ssecond;
- return format;
- }
-
|