1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759 |
- #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>
- #include "LoopThread.h"
- #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(100);// 定时器的刷新间隔
- // CheckState->start();// 线程调用
- // Coordinate->start();// 线程调用
-
- }
- void CGH_Printer::initVariables()
- {
- // 定时器对象的初始化
- timer_calendar = new QTimer();
- timer_WorkState = new QTimer();// 工作状态检测
- timer_Expose = new QTimer();
- timer_loop = new QTimer();
- timer_loop->setSingleShot(true); // 设置为单次触发
- 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);// 平移台坐标更新线程的初始化
- //m_LoopThread = new LoopThread(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;
- //循环图片路径初始化
- loopCGH = "CGH";
- }
- 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.pushButtonLoad_loop, SIGNAL(clicked()), this, SLOT(CGHLoad_loop()));
- // *** 电控平移台 *** //
- 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.pushButtonShutterExpose_1, SIGNAL(clicked()), this, SLOT(Expose_1()));
- //connect(ui.pushButtonShutterStop_1, SIGNAL(clicked()), this, SLOT(ShutterStop_1()));
- connect(ui.pushButtonShutterExpose_2, SIGNAL(clicked()), this, SLOT(Expose_2()));
- connect(ui.pushButtonShutterStop_2, SIGNAL(clicked()), this, SLOT(ShutterStop_2()));
- connect(ui.pushButtonShutterExpose_3, SIGNAL(clicked()), this, SLOT(Expose_3()));
- connect(ui.pushButtonShutterExpose_loop, SIGNAL(clicked()), this, SLOT(Expose_loop()));
- //connect(ui.pushButtonShutterStop_3, SIGNAL(clicked()), this, SLOT(ShutterStop_3()));
- connect(timer_loop, &QTimer::timeout, this, &CGH_Printer::SLMUpdate_loop);//定时器发出的信号
- // *** 配置保存 *** //
- connect(ui.pushButtonTempSaved, SIGNAL(clicked()), this, SLOT(TempSaved()));
- connect(ui.pushButtonPermSaved, SIGNAL(clicked()), this, SLOT(PermSaved()));
- //connect(this,&CGH_Printer::sendCGH, m_LoopThread,&LoopThread::setloopCGH);//将全息图地址传给子线程
- //connect(this, &CGH_Printer::sendtime,m_LoopThread, &LoopThread::settime_num);//将时间传给子线程
- //connect(m_LoopThread, &LoopThread::sendmessage, this, [=](QString CGHName) {
- // loopCGH = CGHName;
- // SLMUpdate_loop();
- // });//接收子线程的全息图地址
- }
- 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.lineEditMove->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()
- {
- CreateDirectoryW(L".\\Project", NULL);//判断是否有Project文件,没有则创建
- _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.lineEditMove->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.lineEditMove->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.lineEditMove->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.lineEditMove->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::Expose_1()
- {
- if (curShutterState)
- {
- BusyState();
- int Ext = ui.lineEditShutter_1->text().toInt();// 快门曝光时间
- timer_Expose->setInterval(Ext);
- MyShutter->open_1();
- curShutterWorkState = true;
- timer_Expose->start();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::Expose_2()
- {
- if (curShutterState)
- {
- BusyState();
- int Ext = ui.lineEditShutter_2->text().toInt();// 快门曝光时间
- timer_Expose->setInterval(Ext);
- MyShutter->open_2();
- curShutterWorkState = true;
- timer_Expose->start();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::Expose_3()
- {
- if (curShutterState)
- {
- BusyState();
- int Ext = ui.lineEditShutter_3->text().toInt();// 快门曝光时间
- timer_Expose->setInterval(Ext);
- MyShutter->open_3();
- curShutterWorkState = true;
- timer_Expose->start();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::Expose_loop()
- {
- BusyState();
- int Ext_1 = ui.lineEditShutter_1->text().toInt();// 快门1曝光时间
- int Ext_2 = ui.lineEditShutter_2->text().toInt();// 快门2曝光时间
- int Ext_3 = ui.lineEditShutter_3->text().toInt();// 快门3曝光时间
- int Cyc_loop = ui.lineEditShutter_loop->text().toInt();// 快门曝光循环次数
- ui.label_looptime->setText(QString::number(((Ext_1 + Ext_2 + Ext_3) * Cyc_loop)));
- // 获取新建项目路径
- QString Fullfilename_1 = ui.lineEditCGHName_loop->text() + "1.bmp";
- QString Fullfilename_2 = ui.lineEditCGHName_loop->text() + "2.bmp";
- QString Fullfilename_3 = ui.lineEditCGHName_loop->text() + "3.bmp";
- //emit sendCGH(Fullfilename_3);
- //emit sendtime(Ext_1);
- //m_LoopThread->start();
-
- }
- //void CGH_Printer::Expose_loop()
- //{
- //BusyState();
- //int Ext_1 = ui.lineEditShutter_1->text().toInt();// 快门1曝光时间
- //int Ext_2 = ui.lineEditShutter_2->text().toInt();// 快门2曝光时间
- //int Ext_3 = ui.lineEditShutter_3->text().toInt();// 快门3曝光时间
- //int Cyc_loop = ui.lineEditShutter_loop->text().toInt();// 快门曝光循环次数
- //ui.label_looptime->setText(QString::number(((Ext_1+ Ext_2+ Ext_3)*Cyc_loop)));
- ////timer_Expose->setInterval(Ext);
- //
- ////获取新建项目路径
- //QString Fullfilename_1;
- //QString Fullfilename_2;
- //QString Fullfilename_3;
- //Fullfilename_1 = ui.lineEditCGHName_loop->text()+"1.bmp";
- //Fullfilename_2 = ui.lineEditCGHName_loop->text() + "2.bmp";
- //Fullfilename_3 = ui.lineEditCGHName_loop->text() + "3.bmp";
- //for (int i=0;i< Cyc_loop;i++)
- //{
- //
- // ui.labelCGHDisplay_loop->clear();
- // ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename_1));
- // ui.labelCGHDisplay_loop->update();
- // // labelPrint->setPixmap(QPixmap(Fullfilename));
- // if (Desktop->numScreens() == 2)
- // {
- // labelPrint->clear();
- // labelPrint->setPixmap(QPixmap(Fullfilename_1));
- // }
- // timer_Expose->setInterval(Ext_1);
- // curShutterWorkState = true;
- // timer_Expose->start();
- // timer_WorkState->start();
- //
- // ui.labelCGHDisplay_loop->clear();
- // ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename_2));
- // ui.labelCGHDisplay_loop->update();
- // // labelPrint->setPixmap(QPixmap(Fullfilename));
- // if (Desktop->numScreens() == 2)
- // {
- // labelPrint->clear();
- // labelPrint->setPixmap(QPixmap(Fullfilename_2));
- // }
- // timer_Expose->setInterval(Ext_2);
- // curShutterWorkState = true;
- // timer_Expose->start();
- // timer_WorkState->start();
- //
- // ui.labelCGHDisplay_loop->clear();
- // ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename_3));
- // ui.labelCGHDisplay_loop->update();
- // // labelPrint->setPixmap(QPixmap(Fullfilename));
- // if (Desktop->numScreens() == 2)
- // {
- // labelPrint->clear();
- // labelPrint->setPixmap(QPixmap(Fullfilename_3));
- // }
- // timer_Expose->setInterval(Ext_3);
- // curShutterWorkState = true;
- // timer_Expose->start();
- // timer_WorkState->start();
- //}
- //if (curShutterState)
- //{
- //
- // BusyState();
- // int Ext_1 = ui.lineEditShutter_1->text().toInt();// 快门1曝光时间
- // int Ext_2 = ui.lineEditShutter_2->text().toInt();// 快门2曝光时间
- // int Ext_3 = ui.lineEditShutter_3->text().toInt();// 快门3曝光时间
- // int Cyc_loop = ui.lineEditShutter_loop->text().toInt();// 快门曝光循环次数
- // ui.label_looptime->setText(QString::number(((Ext_1+ Ext_2+ Ext_3)*Cyc_loop)));
- // //timer_Expose->setInterval(Ext);
- // Sleep(1000);// 静台
- // //获取新建项目路径
-
- // QString Fullfilename_1;
- // QString Fullfilename_2;
- // QString Fullfilename_3;
- // Fullfilename_1 = ui.lineEditCGHName_loop->text()+"1.bmp";
- // Fullfilename_2 = ui.lineEditCGHName_loop->text() + "2.bmp";
- // Fullfilename_3 = ui.lineEditCGHName_loop->text() + "3.bmp";
- // for (int i=0;i< Cyc_loop;i++)
- // {
- // MyShutter->open_1();
- // ui.labelCGHDisplay_loop->clear();
- // ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename_1));
- // // labelPrint->setPixmap(QPixmap(Fullfilename));
- // if (Desktop->numScreens() == 2)
- // {
- // labelPrint->clear();
- // labelPrint->setPixmap(QPixmap(Fullfilename_1));
- // }
- // Sleep(Ext_1);
- // MyShutter->open_2();
- // ui.labelCGHDisplay_loop->clear();
- // ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename_2));
- // // labelPrint->setPixmap(QPixmap(Fullfilename));
- // if (Desktop->numScreens() == 2)
- // {
- // labelPrint->clear();
- // labelPrint->setPixmap(QPixmap(Fullfilename_2));
- // }
- // Sleep(Ext_2);
- // MyShutter->open_3();
- // ui.labelCGHDisplay_loop->clear();
- // ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename_3));
- // // labelPrint->setPixmap(QPixmap(Fullfilename));
- // if (Desktop->numScreens() == 2)
- // {
- // labelPrint->clear();
- // labelPrint->setPixmap(QPixmap(Fullfilename_3));
- // }
- // Sleep(Ext_3);
- // }
- //
- // MyShutter->close();
- // curShutterWorkState = false;
- // timer_Expose->stop();
- // 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::ShutterStop_1()
- {
- if (curShutterState)
- {
- MyShutter->close_1();
- curShutterWorkState = false;
- timer_Expose->stop();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::ShutterStop_2()
- {
- if (curShutterState)
- {
- MyShutter->close_2();
- curShutterWorkState = false;
- timer_Expose->stop();
- timer_WorkState->start();
- }
- else
- {
- QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
- }
- }
- void CGH_Printer::ShutterStop_3()
- {
- if (curShutterState)
- {
- MyShutter->close_3();
- 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_SEP(Devices[0], szPassword, sAxis.c_str(), &Acc, &AccX, NULL);
- PI_SEP(Devices[1], szPassword, sAxis.c_str(), &Acc, &AccY, NULL);
- PI_SEP(Devices[0], szPassword, sAxis.c_str(), &Dec, &DecX, NULL);
- PI_SEP(Devices[1], szPassword, sAxis.c_str(), &Dec, &DecY, NULL);
- PI_SEP(Devices[0], szPassword, sAxis.c_str(), &Maxv, &MaxvX, NULL);
- PI_SEP(Devices[1], szPassword, 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::SLMUpdate_loop()
- {
- labelPrint->clear();
- labelPrint->setPixmap(QPixmap(loopCGH));
- ui.labelCGHDisplay_loop->clear();
- ui.labelCGHDisplay_loop->setPixmap(QPixmap(loopCGH));
- }
- 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::CGHLoad_loop()
- {
- QFileDialog* CGH_dialog = new QFileDialog(this);
- QString filefull;
- QString Fullfilename;
- QString Fullfilename_loop;
- 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();
- Fullfilename_loop = fileinfo.absolutePath() + "/";
- ui.labelCGHDisplay_loop->clear();
- ui.labelCGHDisplay_loop->setPixmap(QPixmap(Fullfilename));
- ui.lineEditCGHName_loop->setText(Fullfilename_loop);//设置路径栏
- // 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);
- labelPrint->setScaledContents(false);
- QPalette label_palette;
- label_palette.setColor(QPalette::Background, QColor(0, 0, 0));
- labelPrint->setAutoFillBackground(true);
- labelPrint->setPalette(label_palette);
- }
- 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;
- }
-
|