CGH_Printer.cpp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. #include "CGH_Printer.h"
  2. #include <qdatetime.h>
  3. #include <qlabel.h>
  4. #include <thread>
  5. #include "CGH_State.h"
  6. #include <fstream>
  7. #include <map>
  8. #include <iostream>
  9. // #include "CGH_CoordinateThread.h"
  10. #include <math.h>
  11. #include <io.h>
  12. #include <set>
  13. #include <QMessageBox>
  14. #include <QFileDialog>
  15. #include <cstdio>
  16. #include <QButtonGroup>
  17. #include <stdlib.h>
  18. #include <time.h>
  19. #include <sstream>
  20. #define FREEBUF(x) {if(x!=NULL){delete [] x;x=NULL;}}
  21. CGH_Printer* gcam = NULL;// 线程函数中使用的全局变量
  22. #include <QDebug>
  23. CGH_Printer::CGH_Printer(QWidget* parent)
  24. : QMainWindow(parent)
  25. {
  26. ui.setupUi(this);
  27. //----------------------------------------修改tabwidget的颜色
  28. ////widget 背景色属性
  29. //ui.tabWidget->setAttribute(Qt::WA_StyledBackground);
  30. ////标题栏红色背景,tab选中蓝色,未选中灰色
  31. //ui.tabWidget->setStyleSheet("QTabWidget#tabWidget{background-color:rgb(255,0,0);}\
  32. // QTabBar::tab{background-color:rgb(220,200,180);color:rgb(0,0,0);font:10pt '新宋体'}\
  33. // QTabBar::tab::selected{background-color:rgb(0,100,200);color:rgb(255,0,0);font:10pt '新宋体'}");
  34. ////绿色背景
  35. //ui.tab->setStyleSheet("QWidget#tab{"
  36. // "background-color:#00ff00;"
  37. // "border:1px solid #eeeeee;}");
  38. //--------------------------------------------------------------------------------------------------------------
  39. Desktop = new QDesktopWidget();
  40. QRect MainWindow = Desktop->screenGeometry(0);
  41. this->setGeometry(MainWindow);
  42. this->move((MainWindow.width()-this->width())/2, (MainWindow.height()-this->height())/2);
  43. initVariables();
  44. initConfigure();
  45. initSlots();
  46. timer_calendar->start(500);// 定时器的刷新间隔
  47. // CheckState->start();// 线程调用
  48. // Coordinate->start();// 线程调用
  49. }
  50. void CGH_Printer::initVariables()
  51. {
  52. // 定时器对象的初始化
  53. timer_calendar = new QTimer();
  54. timer_WorkState = new QTimer();// 工作状态检测
  55. timer_Expose = new QTimer();
  56. timer_Work = new QTimer();
  57. timer_Work->setInterval(100);
  58. timer_WorkState->setInterval(100);
  59. // 线程对象的初始化
  60. // CheckState = new CGH_CheckStateThread(this);// 硬件状态检测线程的初始化
  61. m_Printer = new PrintThread(this);
  62. // Coordinate = new CGH_CoordinateThread(this);// 平移台坐标更新线程的初始化
  63. // 状态检测的初始化
  64. icon_Red = new QImage();
  65. icon_Green = new QImage();
  66. icon_Red->load(":/CGH_Printer/Configure/IMG/Redlight.png");
  67. icon_Green->load(":/CGH_Printer/Configure/IMG/Greenlight.png");
  68. curShutterState = false;
  69. error_messages.append(SHUTTER_ERROR_MESSAGE);
  70. curSLMState = false;
  71. error_messages.append(SLM_ERROR_MESSAGE);
  72. curTransTableState = false;
  73. error_messages.append(TRANSTABLE_ERROR_MESSAGE);
  74. curCCDState = false;
  75. error_messages.append(CCD_ERROR_MESSAGE);
  76. curShutterWorkState = false;
  77. // 快门对象的初始化
  78. MyShutter = new CGH_Shutter();
  79. // t1 = new QElapsedTimer();
  80. // CCD变量的初始化
  81. m_pCameraInfos = QCameraInfo::availableCameras();
  82. m_pCamera = new QCamera(this);
  83. m_pCameraCapture = new QCameraImageCapture(m_pCamera);
  84. m_pViewfinder = new QCameraViewfinder(ui.widgetCCD);
  85. m_pViewfinder->resize(ui.widgetCCD->size());
  86. m_pCameraOpen = FALSE;
  87. // 平移台变量的初始化
  88. ControllerID = -1;// 控制器ID
  89. DeviceNum = 0;// 设备数量
  90. ControllerIDN = new char[BufferSize];// 接受IDN字符的缓冲区
  91. sAxis = "1";// 轴标识符
  92. // 工程对象的初始化
  93. pButtonGroup = new QButtonGroup();
  94. pButtonGroup->setExclusive(true);
  95. // SLM显示弹窗对象的初始化
  96. // Desktop = new QDesktopWidget();
  97. labelPrint = new QLabel();
  98. PRINTSTOP = FALSE;
  99. }
  100. void CGH_Printer::initConfigure()
  101. {
  102. // 路径的初始化
  103. ProjectType = ".pro";
  104. ConfigureName = "Configure.txt";
  105. absPath = (QCoreApplication::applicationDirPath()).toStdString();
  106. relConfigurePath = "../Configure";
  107. relProjectPath = "../Project";
  108. relCapturePath = "../Capture";
  109. relResourcesPath = "../Resources";
  110. absConfigurePath = absPath + "/" + relConfigurePath;
  111. absProjectPath = absPath + "/" + relProjectPath;
  112. absCapturePath = absPath + "/" + relCapturePath;
  113. absResourcesPath = absPath + "/" + relResourcesPath;
  114. // 工作状态的初始化
  115. ui.labelWorkState->setText("就绪");
  116. // 打印进度条的初始化
  117. ui.progressBarPrint->setMinimum(0);
  118. ui.progressBarPrint->setMaximum(100);
  119. ui.progressBarPrint->setValue(0);
  120. //double dProgress = (ui.progressBarPrint->value() - ui.progressBarPrint->minimum()) * 100.0
  121. // / (ui.progressBarPrint->maximum() - ui.progressBarPrint->minimum());
  122. //ui.progressBarPrint->setFormat(QString::fromLocal8Bit("当前进度为:%1%").arg(QString::number(dProgress, 'f', 50)));
  123. //ui.progressBarPrint->setAlignment(Qt::AlignRight | Qt::AlignVCenter); // 对齐方式
  124. // Shutter状态的初始化
  125. // MyShutter->connect();
  126. curShutterState = MyShutter->isconnected();
  127. if (curShutterState)
  128. {
  129. error_messages.removeOne(SHUTTER_ERROR_MESSAGE);
  130. ui.labelShutter->clear();
  131. ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Green));
  132. }
  133. // SLM状态的初始化
  134. //int SLM_Num = Desktop->numScreens();//获取当前环境屏幕个数
  135. if (Desktop->numScreens() == 2)
  136. {
  137. curSLMState = true;
  138. error_messages.removeOne(SLM_ERROR_MESSAGE);
  139. ui.labelSLM->clear();
  140. ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Green));
  141. SLMDisplay();
  142. }
  143. // CCD设备的初始化
  144. if (m_pCameraInfos.size() > 0)
  145. {
  146. curCCDState = true;
  147. error_messages.removeOne(CCD_ERROR_MESSAGE);
  148. ui.labelCCD->clear();
  149. ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Green));
  150. ComboDevice();
  151. }
  152. // 平移台控制的初始化
  153. // 通讯连接
  154. ControllerID = PI_OpenRS232DaisyChain(8, 115200, &DeviceNum, ControllerIDN, BufferSize);
  155. // 如果成功打开菊花链,则开始进行通讯连接
  156. if (ControllerID != -1)
  157. {
  158. curTransTableState = true;
  159. error_messages.removeOne(TRANSTABLE_ERROR_MESSAGE);
  160. ui.labelStages->clear();
  161. ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Green));
  162. PITransTableInit();
  163. }
  164. for (const QString msg : error_messages) {
  165. ui.textEditWarning->insertPlainText(msg + '\n');
  166. }
  167. ReadConfigure();
  168. // 以下的语句出错,我暂时屏蔽了
  169. // loadHistory();
  170. }
  171. void CGH_Printer::initSlots()
  172. {
  173. connect(timer_calendar, SIGNAL(timeout()), this, SLOT(timerUpdate()));
  174. connect(timer_WorkState, SIGNAL(timeout()), this, SLOT(WorkStateUpdate()));
  175. connect(timer_Expose, SIGNAL(timeout()), this, SLOT(ExposeUpdate()));
  176. connect(timer_Work, SIGNAL(timeout()), this, SLOT(WorkTimeUpdate()));
  177. // 作业页面
  178. connect(ui.pushButtonNew, SIGNAL(clicked()), this, SLOT(NewProject()));
  179. connect(ui.pushButtonModify, SIGNAL(clicked()), this, SLOT(ModifyProject()));
  180. connect(ui.pushButtonDelete, SIGNAL(clicked()), this, SLOT(DeleteProject()));
  181. connect(ui.pushButtonFeed, SIGNAL(clicked()), this, SLOT(Feed()));
  182. connect(ui.pushButtonUnderfeed, SIGNAL(clicked()), this, SLOT(Underfeed()));
  183. connect(ui.pushButtonPrint, SIGNAL(clicked()), this, SLOT(PrintTemp()));
  184. connect(ui.pushButtonPrintOK, SIGNAL(clicked()), this, SLOT(PrintProgress()));
  185. connect(ui.pushButtonPrintCancel, SIGNAL(clicked()), this, SLOT(PrintStop()));
  186. connect(ui.pushButtonPreview, SIGNAL(clicked()), this, SLOT(Preview()));
  187. //connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(Preview()));//添加一个槽函数,页面切换打开相机
  188. connect(ui.pushButtonSnapshot, SIGNAL(clicked()), this, SLOT(Snapshot()));
  189. connect(ui.comboBoxDevice, SIGNAL(currentIndexChanged(int)), this, SLOT(ChangeDevice()));
  190. connect(ui.comboBoxFormat, SIGNAL(currentIndexChanged(int)), this, SLOT(ChangeFormat()));
  191. connect(ui.pushButtonLoad, SIGNAL(clicked()), this, SLOT(CGHLoad()));
  192. // *** 电控平移台 *** //
  193. connect(ui.pushButtonUp, SIGNAL(clicked()), this, SLOT(MoveUp()));
  194. connect(ui.pushButtonDown, SIGNAL(clicked()), this, SLOT(MoveDown()));
  195. connect(ui.pushButtonLeft, SIGNAL(clicked()), this, SLOT(MoveLeft()));
  196. connect(ui.pushButtonRight, SIGNAL(clicked()), this, SLOT(MoveRight()));
  197. connect(ui.pushButtonTranstableStop, SIGNAL(clicked()), this, SLOT(TranstableStop()));
  198. connect(ui.pushButtonBlank, SIGNAL(clicked()), this, SLOT(MoveZero()));
  199. // *** 电子快门 *** //
  200. connect(ui.pushButtonShutterExpose, SIGNAL(clicked()), this, SLOT(Expose()));
  201. connect(ui.pushButtonShutterStop, SIGNAL(clicked()), this, SLOT(ShutterStop()));
  202. // *** 配置保存 *** //
  203. connect(ui.pushButtonTempSaved, SIGNAL(clicked()), this, SLOT(TempSaved()));
  204. connect(ui.pushButtonPermSaved, SIGNAL(clicked()), this, SLOT(PermSaved()));
  205. }
  206. void CGH_Printer::ReadConfigure()
  207. {
  208. // 配置文件加载
  209. ifstream infile;
  210. map<string, string> maps_Configure;
  211. string name_temp, value_temp;
  212. infile.open(absConfigurePath + "/" + ConfigureName);
  213. if (infile)
  214. {
  215. while (!infile.eof())
  216. {
  217. infile >> name_temp >> value_temp;
  218. maps_Configure[name_temp] = value_temp;
  219. }
  220. }
  221. infile.close();
  222. // 参数设置
  223. //ui.lineEditMoveUp->setText(QString::fromStdString(maps_Configure["前"]));
  224. //ui.lineEditMoveDown->setText(QString::fromStdString(maps_Configure["后"]));
  225. //ui.lineEditMoveLeft->setText(QString::fromStdString(maps_Configure["左"]));
  226. //ui.lineEditMoveRight->setText(QString::fromStdString(maps_Configure["右"]));
  227. ui.lineEditMove->setText(QString::fromStdString(maps_Configure["位移"]));
  228. ui.lineEditShutter->setText(QString::fromStdString(maps_Configure["时间"]));
  229. ReadTransTableConfigue();
  230. // 设置曝光时间输入为整数
  231. QIntValidator* aIntValidator;
  232. aIntValidator = new QIntValidator(this);
  233. ui.lineEditShutter->setValidator(aIntValidator);
  234. ui.lineEditPrinted->setText("00:00:00");
  235. ui.lineEditStart->setText("00:00:00");
  236. }
  237. void CGH_Printer::loadHistory()
  238. {
  239. _finddata_t data;
  240. auto handle = _findfirst((absProjectPath + "/*.*").c_str(), &data);// 读取第一文件或文件夹
  241. do
  242. {
  243. string fullname = data.name;// 文件名
  244. // 去掉文件名后缀
  245. int length = strlen(fullname.c_str()) - strlen(ProjectType.c_str());
  246. string name = fullname.substr(0, length);
  247. if (fullname.rfind(ProjectType) == fullname.size() - ProjectType.size())// 判断后缀是否为.type
  248. {
  249. addProject(name);
  250. }
  251. } while (_findnext(handle, &data) == 0);
  252. _findclose(handle);
  253. }
  254. // 时间更新
  255. void CGH_Printer::timerUpdate()
  256. {
  257. QDateTime time = QDateTime::currentDateTime();
  258. QString str = time.toString("yyyy-MM-dd \nhh:mm:ss");
  259. ui.labelDatetime->setText(str);
  260. }
  261. //// 硬件工作状态检测
  262. //void CGH_Printer::StateUpdate(int statetype)
  263. //{
  264. // // SLM工作状态检测
  265. // if (statetype == SLM_ERROR)
  266. // {
  267. // curSLMState = false;
  268. // delete Desktop;
  269. // delete labelPrint;
  270. //
  271. // ui.labelSLM->clear();
  272. // ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Red));
  273. // error_messages.append(SLM_ERROR_MESSAGE);
  274. // }
  275. // else if (statetype == SLM_OK)
  276. // {
  277. // curSLMState = true;
  278. // Desktop = new QDesktopWidget();
  279. // labelPrint = new QLabel();
  280. // SLMDisplay();
  281. //
  282. // ui.labelSLM->clear();
  283. // ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Green));
  284. // error_messages.removeOne(SLM_ERROR_MESSAGE);
  285. // }
  286. //
  287. // // 电子快门工作状态检测
  288. // if (statetype == SHUTTER_ERROR)
  289. // {
  290. // curShutterState = false;
  291. // delete MyShutter;
  292. //
  293. // ui.labelShutter->clear();
  294. // ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Red));
  295. // error_messages.append(SHUTTER_ERROR_MESSAGE);
  296. // }
  297. // else if (statetype == SHUTTER_OK)
  298. // {
  299. // MyShutter = new CGH_Shutter();
  300. // MyShutter->connect();
  301. // curShutterState = MyShutter->isconnected();
  302. //
  303. // ui.labelShutter->clear();
  304. // ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Green));
  305. // error_messages.removeOne(SHUTTER_ERROR_MESSAGE);
  306. // }
  307. //
  308. // // 平移台工作状态检测
  309. // if (statetype == TRANSTABLE_ERROR)
  310. // {
  311. // curTransTableState = false;
  312. // ControllerID = -1;
  313. // DeviceNum = 0;
  314. // delete ControllerIDN;
  315. //
  316. // ui.labelStages->clear();
  317. // ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Red));
  318. // error_messages.append(TRANSTABLE_ERROR_MESSAGE);
  319. // }
  320. // else if (statetype == TRANSTABLE_OK)
  321. // {
  322. // ControllerID = PI_OpenRS232DaisyChain(8, 115200, &DeviceNum, ControllerIDN, BufferSize);
  323. // if (ControllerID != -1)
  324. // {
  325. // curTransTableState = true;
  326. // PITransTableInit();
  327. //
  328. // ui.labelStages->clear();
  329. // ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Green));
  330. // error_messages.removeOne(TRANSTABLE_ERROR_MESSAGE);
  331. // }
  332. // }
  333. //
  334. // // CCD工作状态检测
  335. // if (statetype == CCD_ERROR)
  336. // {
  337. // curCCDState = false;
  338. // ComboDevice();
  339. //
  340. // ui.labelCCD->clear();
  341. // ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Red));
  342. // error_messages.append(CCD_ERROR_MESSAGE);
  343. // }
  344. // else if (statetype == CCD_OK)
  345. // {
  346. // curCCDState = true;
  347. // ComboDevice();
  348. //
  349. // ui.labelCCD->clear();
  350. // ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Green));
  351. // error_messages.removeOne(CCD_ERROR_MESSAGE);
  352. // }
  353. //
  354. // ui.textEditWarning->clear();
  355. // for (const QString msg : error_messages) {
  356. // ui.textEditWarning->insertPlainText(msg + '\n');
  357. // }
  358. //}
  359. void CGH_Printer::BusyState()
  360. {
  361. ui.labelStateMarking->setPixmap(QPixmap(":/CGH_Printer/Configure/IMG/Parallelogram_Red.png"));
  362. ui.labelWorkState->setText("正忙");
  363. }
  364. void CGH_Printer::ReadyState()
  365. {
  366. ui.labelStateMarking->setPixmap(QPixmap(":/CGH_Printer/Configure/IMG/Parallelogram_Green.png"));
  367. ui.labelWorkState->setText("就绪");
  368. }
  369. void CGH_Printer::ReadTransTableConfigue()
  370. {
  371. if (ControllerID != -1)
  372. {
  373. PI_qACC(Devices[0], sAxis.c_str(), &AccX);
  374. PI_qACC(Devices[1], sAxis.c_str(), &AccY);
  375. PI_qDEC(Devices[0], sAxis.c_str(), &DecX);
  376. PI_qDEC(Devices[1], sAxis.c_str(), &DecY);
  377. PI_qVEL(Devices[0], sAxis.c_str(), &MaxvX);
  378. PI_qVEL(Devices[1], sAxis.c_str(), &MaxvY);
  379. ui.lineEditAccX->setText(QString::number(AccX, 'f', 3));
  380. ui.lineEditAccY->setText(QString::number(AccY, 'f', 3));
  381. ui.lineEditDecX->setText(QString::number(DecX, 'f', 3));
  382. ui.lineEditDecY->setText(QString::number(DecY, 'f', 3));
  383. ui.lineEditMaxvX->setText(QString::number(MaxvX, 'f', 3));
  384. ui.lineEditMaxvY->setText(QString::number(MaxvY, 'f', 3));
  385. }
  386. }
  387. void CGH_Printer::WorkStateUpdate()
  388. {
  389. BOOL isMoving_sAxisX = FALSE;
  390. BOOL isMoving_sAxisY = FALSE;
  391. if (curTransTableState)
  392. {
  393. PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
  394. PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
  395. }
  396. if (isMoving_sAxisX || isMoving_sAxisY)
  397. {
  398. CoordinateUpdate();
  399. }
  400. else if (!isMoving_sAxisX && !isMoving_sAxisY && !curShutterWorkState)
  401. {
  402. ReadyState();
  403. timer_WorkState->stop();
  404. }
  405. }
  406. void CGH_Printer::MoveUp()
  407. {
  408. if (curTransTableState)
  409. {
  410. double offset = ui.lineEditMove->text().toDouble();
  411. offset = -1 * offset;
  412. if (!PI_MVR(Devices[1], sAxis.c_str(), &offset))
  413. {
  414. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  415. }
  416. else
  417. {
  418. BusyState();
  419. timer_WorkState->start();
  420. }
  421. }
  422. else
  423. {
  424. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  425. }
  426. }
  427. void CGH_Printer::MoveDown()
  428. {
  429. if (curTransTableState)
  430. {
  431. double offset = ui.lineEditMove->text().toDouble();
  432. if (!PI_MVR(Devices[1], sAxis.c_str(), &offset))
  433. {
  434. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  435. }
  436. else
  437. {
  438. BusyState();
  439. timer_WorkState->start();
  440. }
  441. }
  442. else
  443. {
  444. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  445. }
  446. }
  447. // 平移台左移
  448. void CGH_Printer::MoveLeft()
  449. {
  450. if (curTransTableState)
  451. {
  452. double offset = ui.lineEditMove->text().toDouble();
  453. if (!PI_MVR(Devices[0], sAxis.c_str(), &offset))
  454. {
  455. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  456. }
  457. else
  458. {
  459. BusyState();
  460. timer_WorkState->start();
  461. }
  462. }
  463. else
  464. {
  465. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  466. }
  467. }
  468. // 平移台右移
  469. void CGH_Printer::MoveRight()
  470. {
  471. if (curTransTableState)
  472. {
  473. double offset = ui.lineEditMove->text().toDouble();
  474. offset = -1 * offset;
  475. if (!PI_MVR(Devices[0], sAxis.c_str(), &offset))
  476. {
  477. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  478. }
  479. else
  480. {
  481. BusyState();
  482. timer_WorkState->start();
  483. }
  484. }
  485. else
  486. {
  487. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  488. }
  489. }
  490. void CGH_Printer::MoveZero()
  491. {
  492. if (curTransTableState)
  493. {
  494. bool isMoving_sAxisX = TRUE;
  495. bool isMoving_sAxisY = TRUE;
  496. isMoving_sAxisX = PI_GOH(Devices[0], sAxis.c_str());
  497. isMoving_sAxisY = PI_GOH(Devices[1], sAxis.c_str());
  498. if (isMoving_sAxisX || isMoving_sAxisY)
  499. {
  500. BusyState();
  501. timer_WorkState->start();
  502. }
  503. else
  504. {
  505. QMessageBox::critical(this, tr("错误"), tr("不能移动到零点!"));
  506. }
  507. }
  508. else
  509. {
  510. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  511. }
  512. }
  513. void CGH_Printer::TranstableStop()
  514. {
  515. if (curTransTableState)
  516. {
  517. PI_HLT(Devices[0], sAxis.c_str());
  518. PI_HLT(Devices[1], sAxis.c_str());
  519. timer_WorkState->start();
  520. }
  521. else
  522. {
  523. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  524. }
  525. }
  526. void CGH_Printer::Expose()
  527. {
  528. if (curShutterState)
  529. {
  530. BusyState();
  531. int Ext = ui.lineEditShutter->text().toInt();// 快门曝光时间
  532. timer_Expose->setInterval(Ext);
  533. MyShutter->open();
  534. curShutterWorkState = true;
  535. timer_Expose->start();
  536. timer_WorkState->start();
  537. }
  538. else
  539. {
  540. QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
  541. }
  542. }
  543. void CGH_Printer::ShutterStop()
  544. {
  545. if (curShutterState)
  546. {
  547. MyShutter->close();
  548. curShutterWorkState = false;
  549. timer_Expose->stop();
  550. timer_WorkState->start();
  551. }
  552. else
  553. {
  554. QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
  555. }
  556. }
  557. void CGH_Printer::ExposeUpdate()
  558. {
  559. timer_Expose->stop();
  560. MyShutter->close();
  561. curShutterWorkState = false;
  562. }
  563. void CGH_Printer::WorkTimeUpdate()
  564. {
  565. timePrintCur = clock();
  566. Printtimed = (timePrintCur - timePrintStart) / CLOCKS_PER_SEC;
  567. string Worktimed;
  568. Worktimed = formatTime(Printtimed);
  569. ui.lineEditPrinted->setText(QString::fromStdString(Worktimed));
  570. }
  571. void CGH_Printer::PrintOKUpdate()
  572. {
  573. ReadyState();
  574. // UI控件设置
  575. ui.pushButtonPrintOK->setChecked(false);
  576. labelPrint->clear();
  577. ui.labelSLMCopy->clear();
  578. timer_Work->stop();
  579. ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
  580. QMessageBox::about(this, tr("提示"), tr("打印已完成!"));
  581. }
  582. void CGH_Printer::PrintCancelUpdate()
  583. {
  584. ReadyState();
  585. // UI控件设置
  586. ui.pushButtonPrintOK->setChecked(false);
  587. ui.progressBarPrint->setValue(0);
  588. ui.lineEditPrinted->setText("00:00:00");
  589. ui.lineEditStart->setText("00:00:00");
  590. labelPrint->clear();
  591. ui.labelSLMCopy->clear();
  592. ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
  593. timer_Work->stop();
  594. QMessageBox::about(this, tr("提示"), tr("打印已停止!"));
  595. }
  596. // 平移台轴坐标实时更新
  597. void CGH_Printer::CoordinateUpdate()
  598. {
  599. PI_qPOS(Devices[0], sAxis.c_str(), &CoordinateX);
  600. PI_qPOS(Devices[1], sAxis.c_str(), &CoordinateY);
  601. ui.labelXPosition->setText(QString::number(CoordinateX, 'f', 3));
  602. ui.labelYPosition->setText(QString::number(CoordinateY, 'f', 3));
  603. }
  604. // 新建工程
  605. void CGH_Printer::NewProject()
  606. {
  607. CGH_ProjectView* myNewProjectView = new CGH_ProjectView(this);
  608. CGH_Project* myNewProject = new CGH_Project();
  609. myNewProjectView->initWindow();
  610. if (myNewProjectView->exec() == QDialog::Accepted) {
  611. //保存参数
  612. myNewProject->setWorkName(myNewProjectView->getViewName());
  613. myNewProject->setWorkLSpacing(myNewProjectView->getViewLSpacing());
  614. myNewProject->setWorkCSpacing(myNewProjectView->getViewCSpacing());
  615. myNewProject->setWorkLine(myNewProjectView->getViewLine());
  616. myNewProject->setWorkColumn(myNewProjectView->getViewColumn());
  617. myNewProject->setWorkPrefix(myNewProjectView->getViewPrefix());
  618. myNewProject->setWorkExpose(myNewProjectView->getViewExpose());
  619. myNewProject->setWorkQuiet(myNewProjectView->getViewQuiet());
  620. myNewProject->setWorkResource(myNewProjectView->getViewResource());
  621. myNewProject->saveToLocal();
  622. addProject(myNewProject);
  623. }
  624. }
  625. // 修改工程
  626. void CGH_Printer::ModifyProject() {
  627. if (pButtonGroup->checkedButton())
  628. {
  629. CGH_ProjectView* myModifyProjectView = new CGH_ProjectView(this);
  630. string ModifyProjectName = (pButtonGroup->checkedButton())->text().toStdString();
  631. CGH_Project* myModifyProject = new CGH_Project(ModifyProjectName);
  632. myModifyProjectView->initWindow();
  633. myModifyProjectView->setViewName(myModifyProject->getWorkName());
  634. myModifyProjectView->setViewLSpacing(myModifyProject->getWorkLSpacing());
  635. myModifyProjectView->setViewCSpacing(myModifyProject->getWorkCSpacing());
  636. myModifyProjectView->setViewLine(myModifyProject->getWorkLine());
  637. myModifyProjectView->setViewColumn(myModifyProject->getWorkColumn());
  638. myModifyProjectView->setViewPrefix(myModifyProject->getWorkPrefix());
  639. myModifyProjectView->setViewExpose(myModifyProject->getWorkExpose());
  640. myModifyProjectView->setViewQuiet(myModifyProject->getWorkQuiet());
  641. myModifyProjectView->setViewResource(myModifyProject->getWorkResource());
  642. if (myModifyProjectView->exec() == QDialog::Accepted) {
  643. string fullProjectName;
  644. fullProjectName = absProjectPath + "/" + (myModifyProject->getWorkName()) + ProjectType;
  645. remove(fullProjectName.c_str());
  646. ui.verticalLayoutWork->removeWidget(pButtonGroup->checkedButton());
  647. delete pButtonGroup->checkedButton();
  648. myModifyProject->setWorkName(myModifyProjectView->getViewName());
  649. myModifyProject->setWorkLSpacing(myModifyProjectView->getViewLSpacing());
  650. myModifyProject->setWorkCSpacing(myModifyProjectView->getViewCSpacing());
  651. myModifyProject->setWorkLine(myModifyProjectView->getViewLine());
  652. myModifyProject->setWorkColumn(myModifyProjectView->getViewColumn());
  653. myModifyProject->setWorkPrefix(myModifyProjectView->getViewPrefix());
  654. myModifyProject->setWorkExpose(myModifyProjectView->getViewExpose());
  655. myModifyProject->setWorkQuiet(myModifyProjectView->getViewQuiet());
  656. myModifyProject->setWorkResource(myModifyProjectView->getViewResource());
  657. myModifyProject->saveToLocal();
  658. addProject(myModifyProject);
  659. }
  660. }
  661. else
  662. {
  663. QMessageBox::about(this, tr("提示"), tr("未选中工程!"));
  664. }
  665. }
  666. // 添加工程文件
  667. void CGH_Printer::addProject(CGH_Project* pj)
  668. {
  669. string WorkName = pj->getWorkName();
  670. addProject(WorkName);
  671. }
  672. void CGH_Printer::addProject(const string& name)
  673. {
  674. QPushButton* Button = new QPushButton;
  675. string fullprojectName = name + ProjectType;
  676. Button->setText(QString::fromLocal8Bit(fullprojectName.c_str()));
  677. Button->setCheckable(true);
  678. //Button->setAutoExclusive(true);
  679. pButtonGroup->addButton(Button);
  680. ui.verticalLayoutWork->addWidget(Button);
  681. }
  682. // 删除工程文件
  683. void CGH_Printer::DeleteProject()
  684. {
  685. string fileName;
  686. QString ButtonName;
  687. fileName = (pButtonGroup->checkedButton())->text().toStdString();
  688. ButtonName = (pButtonGroup->checkedButton())->objectName();
  689. QPushButton* tempButton = this->findChild<QPushButton *>(ButtonName);
  690. string fullProjectName;
  691. fullProjectName = absProjectPath + "/" + fileName;
  692. if (QMessageBox::warning(this, tr("提示"), tr("确定删除工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  693. {
  694. remove(fullProjectName.c_str());
  695. ui.verticalLayoutWork->removeWidget(pButtonGroup->checkedButton());
  696. delete pButtonGroup->checkedButton();
  697. }
  698. return;
  699. }
  700. void CGH_Printer::Underfeed()
  701. {
  702. if (curTransTableState)
  703. {
  704. if (!PI_GOH(Devices[0], sAxis.c_str()) && !PI_FNL(Devices[1], sAxis.c_str()))
  705. {
  706. QMessageBox::critical(this, tr("错误"), tr("不能完成下料!"));
  707. }
  708. else
  709. {
  710. BusyState();
  711. timer_WorkState->start();
  712. }
  713. }
  714. else
  715. {
  716. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  717. }
  718. }
  719. void CGH_Printer::TempSaved()
  720. {
  721. if (curTransTableState)
  722. {
  723. if (QMessageBox::information(this, tr("提示"), tr("是否暂时保存配置?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  724. {
  725. AccX = ui.lineEditAccX->text().toDouble();
  726. AccY = ui.lineEditAccY->text().toDouble();
  727. DecX = ui.lineEditDecX->text().toDouble();
  728. DecY = ui.lineEditDecY->text().toDouble();
  729. MaxvX = ui.lineEditMaxvX->text().toDouble();
  730. MaxvY = ui.lineEditMaxvY->text().toDouble();
  731. PI_SPA(Devices[0], sAxis.c_str(), &Acc, &AccX, NULL);
  732. PI_SPA(Devices[1], sAxis.c_str(), &Acc, &AccY, NULL);
  733. PI_SPA(Devices[0], sAxis.c_str(), &Dec, &DecX, NULL);
  734. PI_SPA(Devices[1], sAxis.c_str(), &Dec, &DecY, NULL);
  735. PI_SPA(Devices[0], sAxis.c_str(), &Maxv, &MaxvX, NULL);
  736. PI_SPA(Devices[1], sAxis.c_str(), &Maxv, &MaxvY, NULL);
  737. }
  738. else
  739. {
  740. ReadTransTableConfigue();
  741. }
  742. }
  743. else
  744. {
  745. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  746. }
  747. }
  748. void CGH_Printer::PermSaved()
  749. {
  750. if (curTransTableState)
  751. {
  752. if (QMessageBox::information(this, tr("提示"), tr("是否永久保存配置?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  753. {
  754. AccX = ui.lineEditAccX->text().toDouble();
  755. AccY = ui.lineEditAccY->text().toDouble();
  756. DecX = ui.lineEditDecX->text().toDouble();
  757. DecY = ui.lineEditDecY->text().toDouble();
  758. MaxvX = ui.lineEditMaxvX->text().toDouble();
  759. MaxvY = ui.lineEditMaxvY->text().toDouble();
  760. PI_SPA(Devices[0], sAxis.c_str(), &Acc, &AccX, NULL);
  761. PI_SPA(Devices[1], sAxis.c_str(), &Acc, &AccY, NULL);
  762. PI_SPA(Devices[0], sAxis.c_str(), &Dec, &DecX, NULL);
  763. PI_SPA(Devices[1], sAxis.c_str(), &Dec, &DecY, NULL);
  764. PI_SPA(Devices[0], sAxis.c_str(), &Maxv, &MaxvX, NULL);
  765. PI_SPA(Devices[1], sAxis.c_str(), &Maxv, &MaxvY, NULL);
  766. PI_RPA(Devices[0], sAxis.c_str(), &Acc);
  767. PI_RPA(Devices[1], sAxis.c_str(), &Acc);
  768. PI_RPA(Devices[0], sAxis.c_str(), &Dec);
  769. PI_RPA(Devices[1], sAxis.c_str(), &Dec);
  770. PI_RPA(Devices[0], sAxis.c_str(), &Maxv);
  771. PI_RPA(Devices[1], sAxis.c_str(), &Maxv);
  772. }
  773. else
  774. {
  775. ReadTransTableConfigue();
  776. }
  777. }
  778. else
  779. {
  780. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  781. }
  782. }
  783. void CGH_Printer::Feed()
  784. {
  785. if (curTransTableState)
  786. {
  787. if (!PI_GOH(Devices[1], sAxis.c_str()) && !PI_GOH(Devices[0], sAxis.c_str()))
  788. {
  789. QMessageBox::critical(this, tr("错误"), tr("不能完成上料!"));
  790. }
  791. else
  792. {
  793. BusyState();
  794. timer_WorkState->start();
  795. }
  796. }
  797. else
  798. {
  799. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  800. }
  801. }
  802. // 打印选中的工程
  803. void CGH_Printer::PrintTemp()
  804. {
  805. if (pButtonGroup->checkedButton())
  806. {
  807. Print();
  808. }
  809. else
  810. {
  811. QMessageBox::about(this, tr("提示"), tr("未选中工程!"));
  812. }
  813. }
  814. void CGH_Printer::Print()
  815. {
  816. if (QMessageBox::information(this, tr("提示"), tr("是否加载工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  817. {
  818. string PrintProjectName = (pButtonGroup->checkedButton())->text().toStdString();
  819. CGH_Project* PrintProject = new CGH_Project(PrintProjectName);
  820. PrintName = PrintProject->getWorkName();
  821. PrintLSpacing = stod(PrintProject->getWorkLSpacing());
  822. PrintCSpacing = stod(PrintProject->getWorkCSpacing());
  823. PrintLine = stoi(PrintProject->getWorkLine());
  824. PrintColumn = stoi(PrintProject->getWorkColumn());
  825. PrintPrefix = PrintProject->getWorkPrefix();
  826. PrintExpose = stoi(PrintProject->getWorkExpose());
  827. PrintQuiet = stoi(PrintProject->getWorkQuiet());
  828. PrintResource = PrintProject->getWorkResource();
  829. ui.tabWidget->setCurrentIndex(3);
  830. ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
  831. ui.progressBarPrint->setValue(0);
  832. labelPrint->clear();
  833. // 加载实物图
  834. string sep = "/";
  835. string Format = ".bmp";
  836. string Phyfilename;// 实物图路径
  837. Phyfilename = PrintResource + sep + PrintPrefix + Format;
  838. ui.labelPhy->setPixmap(QPixmap(QString::fromStdString(Phyfilename)));
  839. }
  840. }
  841. void CGH_Printer::SLMUpdate(const QString& tempCGH)
  842. {
  843. labelPrint->clear();
  844. labelPrint->setPixmap(QPixmap(tempCGH));
  845. ui.labelSLMCopy->setPixmap(QPixmap(tempCGH));
  846. QString CurPrintName;
  847. CurPrintName = QString::fromStdString(PrintName) + "(" + tempCGH + ")";
  848. ui.lineEditPrintName->setText(tempCGH);
  849. }
  850. void CGH_Printer::PrintUpdate(int tempLL, int tempCC)
  851. {
  852. PrintLL = tempLL;
  853. PrintCC = tempCC;
  854. CurProgress = (PrintLL - 1) * PrintColumn + PrintCC;
  855. FulProgress = PrintLine * PrintColumn;
  856. ui.progressBarPrint->setMaximum(FulProgress);
  857. ui.progressBarPrint->setValue(CurProgress);
  858. }
  859. void CGH_Printer::PrintStop()
  860. {
  861. if (QMessageBox::warning(this, tr("提示"), tr("是否停止打印?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  862. {
  863. PRINTSTOP = TRUE;
  864. }
  865. }
  866. // 打印工作进程
  867. void CGH_Printer::PrintProgress()
  868. {
  869. if (!ui.lineEditPrintName->text().isEmpty() && curTransTableState && curShutterState && curSLMState)
  870. {
  871. if (QMessageBox::warning(this, tr("提示"), tr("是否开始打印?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  872. {
  873. PRINTSTOP = FALSE;
  874. BusyState();
  875. // 开始工作时间
  876. QDateTime timeStart = QDateTime::currentDateTime();
  877. QString str = timeStart.toString("hh:mm:ss");
  878. ui.lineEditStart->setText(str);
  879. // 已打印
  880. timePrintStart = clock();
  881. timer_Work->start();
  882. m_Printer->start();
  883. }
  884. else
  885. {
  886. ui.pushButtonPrintOK->setChecked(false);
  887. }
  888. }
  889. else if (ui.lineEditPrintName->text().isEmpty())
  890. {
  891. ui.pushButtonPrintOK->setChecked(false);
  892. QMessageBox::about(this, tr("提示"), tr("未加载工程!"));
  893. }
  894. else
  895. {
  896. ui.pushButtonPrintOK->setChecked(false);
  897. QMessageBox::about(this, tr("提示"), tr("请检查电子快门、空间光调制器和电控平移台的状态!"));
  898. }
  899. }
  900. void CGH_Printer::ComboDevice()
  901. {
  902. ui.comboBoxDevice->clear();
  903. m_pCameraInfos = QCameraInfo::availableCameras();
  904. for (int i = 0; i < m_pCameraInfos.size(); i++)
  905. {
  906. ui.comboBoxDevice->addItem(m_pCameraInfos[i].description());
  907. }
  908. m_pCameraIndex = ui.comboBoxDevice->currentIndex();
  909. }
  910. // 切换设备
  911. void CGH_Printer::ChangeDevice()
  912. {
  913. if (m_pCameraOpen)
  914. {
  915. CloseCamera();
  916. m_pCameraIndex = ui.comboBoxDevice->currentIndex();
  917. OpenCamera();
  918. ComboFormatandFramerate();
  919. }
  920. }
  921. // 切换分辨率
  922. void CGH_Printer::ChangeFormat()
  923. {
  924. if (m_pCameraOpen)
  925. {
  926. QString strFormat = ui.comboBoxFormat->currentText();
  927. QStringList ListFormat = strFormat.split('x');
  928. CloseCamera();
  929. m_pCamera = new QCamera(m_pCameraInfos[m_pCameraIndex]);
  930. QCameraViewfinderSettings* m_pCameraSet = new QCameraViewfinderSettings();
  931. m_pCameraSet->setResolution(ListFormat[0].toInt(), ListFormat[1].toInt());
  932. m_pCamera->setViewfinderSettings(*m_pCameraSet);
  933. m_pCamera->setViewfinder(m_pViewfinder);
  934. m_pCamera->start();
  935. }
  936. }
  937. void CGH_Printer::CGHLoad()
  938. {
  939. QFileDialog* CGH_dialog = new QFileDialog(this);
  940. QString filefull;
  941. QString Fullfilename;
  942. QFileInfo fileinfo;
  943. QString curPath = QString::fromStdString(absResourcesPath);// 默认路径
  944. // 路径不存在则创建路径
  945. QDir dir(curPath);
  946. if (!dir.exists(curPath))
  947. {
  948. dir.mkdir(curPath);
  949. }
  950. QString dlgTitle = "选择文件";// 对话框标题
  951. QString filter = "Bmp Files(*.bmp)";// 文件过滤器
  952. filefull = CGH_dialog->getOpenFileName(this, dlgTitle, curPath, filter);
  953. QFileInfo file(filefull);
  954. //点击确定按钮
  955. if (file.isFile() && file.exists())
  956. {
  957. //获取新建项目路径
  958. fileinfo = QFileInfo(filefull);
  959. Fullfilename = fileinfo.absolutePath() + "/" + fileinfo.fileName();
  960. ui.lineEditCGHName->setText(Fullfilename);//设置路径栏
  961. ui.labelCGHDisplay->clear();
  962. ui.labelCGHDisplay->setPixmap(QPixmap(Fullfilename));
  963. // labelPrint->setPixmap(QPixmap(Fullfilename));
  964. if (Desktop->numScreens() == 2)
  965. {
  966. labelPrint->clear();
  967. labelPrint->setPixmap(QPixmap(Fullfilename));
  968. }
  969. }
  970. //点取消则返回
  971. else
  972. {
  973. return;
  974. }
  975. delete CGH_dialog;
  976. CGH_dialog = NULL;
  977. }
  978. // 视频预览
  979. void CGH_Printer::Preview()
  980. {
  981. if (m_pCameraInfos.size() > 0)
  982. {
  983. if (!m_pCameraOpen)
  984. {
  985. ui.pushButtonPreview->setText("停止");
  986. OpenCamera();
  987. ComboFormatandFramerate();
  988. m_pCameraOpen = TRUE;
  989. }
  990. else
  991. {
  992. ui.pushButtonPreview->setText("预览");
  993. CloseCamera();
  994. m_pCameraOpen = FALSE;
  995. ui.comboBoxFormat->clear();
  996. ui.comboBoxFramerate->clear();
  997. delete m_pCamera;
  998. }
  999. }
  1000. else
  1001. {
  1002. QMessageBox::about(this, tr("提示"), tr("打开相机失败!"));
  1003. }
  1004. }
  1005. // 视频截图
  1006. void CGH_Printer::Snapshot()
  1007. {
  1008. if (m_pCameraOpen)
  1009. {
  1010. string filename;
  1011. m_pCameraCapture = new QCameraImageCapture(m_pCamera);
  1012. m_pCameraCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
  1013. QString curPath = QString::fromStdString(absCapturePath);// 默认路径
  1014. // 路径不存在则创建路径
  1015. QDir dir(curPath);
  1016. if (!dir.exists(curPath))
  1017. {
  1018. dir.mkdir(curPath);
  1019. }
  1020. QString dlgTitle = "保存文件";// 对话框标题
  1021. QString filter = "Jpep Files(*.jpg)";// 文件过滤器
  1022. QString aFileName = QFileDialog::getSaveFileName(this, dlgTitle, curPath, filter);
  1023. if (!aFileName.isEmpty())
  1024. m_pCameraCapture->capture(aFileName);
  1025. // 默认输出到Capture文件夹
  1026. // QDir dir(QString::fromStdString(absCapturePath));
  1027. // dir.setFilter(QDir::Files | QDir::NoSymLinks);
  1028. // QFileInfoList list = dir.entryInfoList();
  1029. // int file_count = list.count();
  1030. // if (!dir.exists() || file_count <= 0)
  1031. // {
  1032. // filename = absCapturePath + "/Cap_0";
  1033. // }
  1034. // else
  1035. // {
  1036. // QStringList string_list;
  1037. // int maxindex = 0;
  1038. // for (int i = 0; i < file_count; i++)
  1039. // {
  1040. // QFileInfo file_info = list.at(i);
  1041. // QString curfilename = file_info.fileName();
  1042. // int start = curfilename.lastIndexOf("_");
  1043. // int end = curfilename.lastIndexOf(".");
  1044. // QString temp = curfilename.mid(start+1, end - start-1);
  1045. // int curindex = temp.toInt();
  1046. // maxindex = qMax(maxindex, curindex);
  1047. // }
  1048. // filename = absCapturePath + "/Cap_" + to_string(maxindex + 1);
  1049. // }
  1050. }
  1051. else
  1052. {
  1053. QMessageBox::about(this, tr("提示"), tr("相机未开启!"));
  1054. }
  1055. }
  1056. void CGH_Printer::ComboFormatandFramerate()
  1057. {
  1058. QList<QSize> m_pCameraFormats = m_pCamera->supportedViewfinderResolutions();
  1059. QString strFormat;
  1060. foreach(QSize m_pCameraFormat, m_pCameraFormats)
  1061. {
  1062. strFormat = QString("%1x%2").arg(m_pCameraFormat.width()).arg(m_pCameraFormat.height());
  1063. ui.comboBoxFormat->addItem(strFormat);
  1064. }
  1065. QList<QCamera::FrameRateRange> m_pCameraFramerates = m_pCamera->supportedViewfinderFrameRateRanges();
  1066. foreach(QCamera::FrameRateRange m_pCameraFramerate, m_pCameraFramerates)
  1067. {
  1068. ui.comboBoxFramerate->addItem(QString::number(m_pCameraFramerate.maximumFrameRate, 'f', 0));
  1069. }
  1070. }
  1071. void CGH_Printer::OpenCamera()
  1072. {
  1073. m_pCamera = new QCamera(m_pCameraInfos[m_pCameraIndex]);
  1074. m_pCamera->setViewfinder(m_pViewfinder);
  1075. m_pCamera->setCaptureMode(QCamera::CaptureStillImage);
  1076. m_pCamera->start();
  1077. QList<QSize> ViewFormats = m_pCamera->supportedViewfinderResolutions();
  1078. QCameraViewfinderSettings* initm_pCameraSet = new QCameraViewfinderSettings();
  1079. initm_pCameraSet->setResolution(ViewFormats[0].width(), ViewFormats[0].height());
  1080. QList<QCamera::FrameRateRange> ViewFramerates = m_pCamera->supportedViewfinderFrameRateRanges();
  1081. initm_pCameraSet->setMaximumFrameRate(ViewFramerates[0].maximumFrameRate);
  1082. initm_pCameraSet->setMinimumFrameRate(ViewFramerates[0].minimumFrameRate);
  1083. m_pCamera->setViewfinderSettings(*initm_pCameraSet);
  1084. }
  1085. void CGH_Printer::CloseCamera()
  1086. {
  1087. m_pCamera->stop();
  1088. }
  1089. void CGH_Printer::SLMDisplay()
  1090. {
  1091. QRect winMain = Desktop->screenGeometry(1);
  1092. labelPrint->setGeometry(winMain);
  1093. labelPrint->setWindowFlags(Qt::FramelessWindowHint |
  1094. Qt::WindowStaysOnTopHint |
  1095. Qt::Popup | Qt::Tool);//设置窗口弹出、无边框、窗口置顶
  1096. //labelPrint->setWindowFlags(Qt::FramelessWindowHint |
  1097. // Qt::WindowStaysOnTopHint |
  1098. // Qt::Popup | Qt::Tool);//设置窗口弹出、无边框、窗口置顶
  1099. labelPrint->setCursor(Qt::BlankCursor);
  1100. //labelPrint->move(winMain.width(), 0);
  1101. labelPrint->showFullScreen();
  1102. labelPrint->setAlignment(Qt::AlignCenter);
  1103. //labelPrint->setScaledContents(true);
  1104. labelPrint->setScaledContents(false);
  1105. QPalette label_palette;
  1106. label_palette.setColor(QPalette::Background, QColor(0, 0, 0));
  1107. labelPrint->setAutoFillBackground(true);
  1108. labelPrint->setPalette(label_palette);
  1109. }
  1110. void CGH_Printer::PITransTableInit()
  1111. {
  1112. for (int num = 1; num <= DeviceNum; num++)
  1113. {
  1114. int Device = PI_ConnectDaisyChainDevice(ControllerID, num);
  1115. if (Device >= 0)
  1116. {
  1117. Devices.push_back(Device);
  1118. }
  1119. }
  1120. // 轴开启伺服控制
  1121. for (const auto& Device : Devices)
  1122. {
  1123. PI_SVO(Device, sAxis.c_str(), &SERVO_ON);
  1124. }
  1125. BusyState();
  1126. timer_WorkState->start();
  1127. // 轴参考移动
  1128. for (const auto& Device : Devices)
  1129. {
  1130. PI_FRF(Device, sAxis.c_str());
  1131. }
  1132. }
  1133. void CGH_Printer::closeEvent(QCloseEvent* event)
  1134. {
  1135. if (QMessageBox::information(this, tr("提示"), tr("是否关闭程序?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  1136. {
  1137. event->accept();
  1138. }
  1139. else
  1140. {
  1141. event->ignore();
  1142. }
  1143. }
  1144. string CGH_Printer::numberToString(int n,int l)
  1145. {
  1146. string res = to_string(n);
  1147. int length = res.size();
  1148. while (length++ < l) {
  1149. res = "0" + res;
  1150. }
  1151. return res;
  1152. }
  1153. std::string CGH_Printer::formatTime(long ss)
  1154. {
  1155. int mi = 60;
  1156. int hh = mi * 60;
  1157. long hour = ss / hh;
  1158. long minute = (ss - hour * hh) / mi;
  1159. long second = ss - hour * hh - minute * mi;
  1160. string shour, sminute, ssecond;
  1161. shour = numberToString(hour, 2);
  1162. sminute = numberToString(minute, 2);
  1163. ssecond = numberToString(second, 2);
  1164. string format;
  1165. format = shour + ":" + sminute + ":" + ssecond;
  1166. return format;
  1167. }