CGH_Printer.cpp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  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.lineEditShutter->setText(QString::fromStdString(maps_Configure["时间"]));
  228. ReadTransTableConfigue();
  229. // 设置曝光时间输入为整数
  230. QIntValidator* aIntValidator;
  231. aIntValidator = new QIntValidator(this);
  232. ui.lineEditShutter->setValidator(aIntValidator);
  233. ui.lineEditPrinted->setText("00:00:00");
  234. ui.lineEditStart->setText("00:00:00");
  235. }
  236. void CGH_Printer::loadHistory()
  237. {
  238. _finddata_t data;
  239. auto handle = _findfirst((absProjectPath + "/*.*").c_str(), &data);// 读取第一文件或文件夹
  240. do
  241. {
  242. string fullname = data.name;// 文件名
  243. // 去掉文件名后缀
  244. int length = strlen(fullname.c_str()) - strlen(ProjectType.c_str());
  245. string name = fullname.substr(0, length);
  246. if (fullname.rfind(ProjectType) == fullname.size() - ProjectType.size())// 判断后缀是否为.type
  247. {
  248. addProject(name);
  249. }
  250. } while (_findnext(handle, &data) == 0);
  251. _findclose(handle);
  252. }
  253. // 时间更新
  254. void CGH_Printer::timerUpdate()
  255. {
  256. QDateTime time = QDateTime::currentDateTime();
  257. QString str = time.toString("yyyy-MM-dd \nhh:mm:ss");
  258. ui.labelDatetime->setText(str);
  259. }
  260. //// 硬件工作状态检测
  261. //void CGH_Printer::StateUpdate(int statetype)
  262. //{
  263. // // SLM工作状态检测
  264. // if (statetype == SLM_ERROR)
  265. // {
  266. // curSLMState = false;
  267. // delete Desktop;
  268. // delete labelPrint;
  269. //
  270. // ui.labelSLM->clear();
  271. // ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Red));
  272. // error_messages.append(SLM_ERROR_MESSAGE);
  273. // }
  274. // else if (statetype == SLM_OK)
  275. // {
  276. // curSLMState = true;
  277. // Desktop = new QDesktopWidget();
  278. // labelPrint = new QLabel();
  279. // SLMDisplay();
  280. //
  281. // ui.labelSLM->clear();
  282. // ui.labelSLM->setPixmap(QPixmap::fromImage(*icon_Green));
  283. // error_messages.removeOne(SLM_ERROR_MESSAGE);
  284. // }
  285. //
  286. // // 电子快门工作状态检测
  287. // if (statetype == SHUTTER_ERROR)
  288. // {
  289. // curShutterState = false;
  290. // delete MyShutter;
  291. //
  292. // ui.labelShutter->clear();
  293. // ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Red));
  294. // error_messages.append(SHUTTER_ERROR_MESSAGE);
  295. // }
  296. // else if (statetype == SHUTTER_OK)
  297. // {
  298. // MyShutter = new CGH_Shutter();
  299. // MyShutter->connect();
  300. // curShutterState = MyShutter->isconnected();
  301. //
  302. // ui.labelShutter->clear();
  303. // ui.labelShutter->setPixmap(QPixmap::fromImage(*icon_Green));
  304. // error_messages.removeOne(SHUTTER_ERROR_MESSAGE);
  305. // }
  306. //
  307. // // 平移台工作状态检测
  308. // if (statetype == TRANSTABLE_ERROR)
  309. // {
  310. // curTransTableState = false;
  311. // ControllerID = -1;
  312. // DeviceNum = 0;
  313. // delete ControllerIDN;
  314. //
  315. // ui.labelStages->clear();
  316. // ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Red));
  317. // error_messages.append(TRANSTABLE_ERROR_MESSAGE);
  318. // }
  319. // else if (statetype == TRANSTABLE_OK)
  320. // {
  321. // ControllerID = PI_OpenRS232DaisyChain(8, 115200, &DeviceNum, ControllerIDN, BufferSize);
  322. // if (ControllerID != -1)
  323. // {
  324. // curTransTableState = true;
  325. // PITransTableInit();
  326. //
  327. // ui.labelStages->clear();
  328. // ui.labelStages->setPixmap(QPixmap::fromImage(*icon_Green));
  329. // error_messages.removeOne(TRANSTABLE_ERROR_MESSAGE);
  330. // }
  331. // }
  332. //
  333. // // CCD工作状态检测
  334. // if (statetype == CCD_ERROR)
  335. // {
  336. // curCCDState = false;
  337. // ComboDevice();
  338. //
  339. // ui.labelCCD->clear();
  340. // ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Red));
  341. // error_messages.append(CCD_ERROR_MESSAGE);
  342. // }
  343. // else if (statetype == CCD_OK)
  344. // {
  345. // curCCDState = true;
  346. // ComboDevice();
  347. //
  348. // ui.labelCCD->clear();
  349. // ui.labelCCD->setPixmap(QPixmap::fromImage(*icon_Green));
  350. // error_messages.removeOne(CCD_ERROR_MESSAGE);
  351. // }
  352. //
  353. // ui.textEditWarning->clear();
  354. // for (const QString msg : error_messages) {
  355. // ui.textEditWarning->insertPlainText(msg + '\n');
  356. // }
  357. //}
  358. void CGH_Printer::BusyState()
  359. {
  360. ui.labelStateMarking->setPixmap(QPixmap(":/CGH_Printer/Configure/IMG/Parallelogram_Red.png"));
  361. ui.labelWorkState->setText("正忙");
  362. }
  363. void CGH_Printer::ReadyState()
  364. {
  365. ui.labelStateMarking->setPixmap(QPixmap(":/CGH_Printer/Configure/IMG/Parallelogram_Green.png"));
  366. ui.labelWorkState->setText("就绪");
  367. }
  368. void CGH_Printer::ReadTransTableConfigue()
  369. {
  370. if (ControllerID != -1)
  371. {
  372. PI_qACC(Devices[0], sAxis.c_str(), &AccX);
  373. PI_qACC(Devices[1], sAxis.c_str(), &AccY);
  374. PI_qDEC(Devices[0], sAxis.c_str(), &DecX);
  375. PI_qDEC(Devices[1], sAxis.c_str(), &DecY);
  376. PI_qVEL(Devices[0], sAxis.c_str(), &MaxvX);
  377. PI_qVEL(Devices[1], sAxis.c_str(), &MaxvY);
  378. ui.lineEditAccX->setText(QString::number(AccX, 'f', 3));
  379. ui.lineEditAccY->setText(QString::number(AccY, 'f', 3));
  380. ui.lineEditDecX->setText(QString::number(DecX, 'f', 3));
  381. ui.lineEditDecY->setText(QString::number(DecY, 'f', 3));
  382. ui.lineEditMaxvX->setText(QString::number(MaxvX, 'f', 3));
  383. ui.lineEditMaxvY->setText(QString::number(MaxvY, 'f', 3));
  384. }
  385. }
  386. void CGH_Printer::WorkStateUpdate()
  387. {
  388. BOOL isMoving_sAxisX = FALSE;
  389. BOOL isMoving_sAxisY = FALSE;
  390. if (curTransTableState)
  391. {
  392. PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
  393. PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
  394. }
  395. if (isMoving_sAxisX || isMoving_sAxisY)
  396. {
  397. CoordinateUpdate();
  398. }
  399. else if (!isMoving_sAxisX && !isMoving_sAxisY && !curShutterWorkState)
  400. {
  401. ReadyState();
  402. timer_WorkState->stop();
  403. }
  404. }
  405. void CGH_Printer::MoveUp()
  406. {
  407. if (curTransTableState)
  408. {
  409. double offset = ui.lineEditMoveUp->text().toDouble();
  410. offset = -1 * offset;
  411. if (!PI_MVR(Devices[1], sAxis.c_str(), &offset))
  412. {
  413. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  414. }
  415. else
  416. {
  417. BusyState();
  418. timer_WorkState->start();
  419. }
  420. }
  421. else
  422. {
  423. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  424. }
  425. }
  426. void CGH_Printer::MoveDown()
  427. {
  428. if (curTransTableState)
  429. {
  430. double offset = ui.lineEditMoveDown->text().toDouble();
  431. if (!PI_MVR(Devices[1], sAxis.c_str(), &offset))
  432. {
  433. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  434. }
  435. else
  436. {
  437. BusyState();
  438. timer_WorkState->start();
  439. }
  440. }
  441. else
  442. {
  443. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  444. }
  445. }
  446. // 平移台左移
  447. void CGH_Printer::MoveLeft()
  448. {
  449. if (curTransTableState)
  450. {
  451. double offset = ui.lineEditMoveLeft->text().toDouble();
  452. if (!PI_MVR(Devices[0], sAxis.c_str(), &offset))
  453. {
  454. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  455. }
  456. else
  457. {
  458. BusyState();
  459. timer_WorkState->start();
  460. }
  461. }
  462. else
  463. {
  464. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  465. }
  466. }
  467. // 平移台右移
  468. void CGH_Printer::MoveRight()
  469. {
  470. if (curTransTableState)
  471. {
  472. double offset = ui.lineEditMoveRight->text().toDouble();
  473. offset = -1 * offset;
  474. if (!PI_MVR(Devices[0], sAxis.c_str(), &offset))
  475. {
  476. QMessageBox::critical(this, tr("错误"), tr("不能移动到目标!"));
  477. }
  478. else
  479. {
  480. BusyState();
  481. timer_WorkState->start();
  482. }
  483. }
  484. else
  485. {
  486. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  487. }
  488. }
  489. void CGH_Printer::MoveZero()
  490. {
  491. if (curTransTableState)
  492. {
  493. bool isMoving_sAxisX = TRUE;
  494. bool isMoving_sAxisY = TRUE;
  495. isMoving_sAxisX = PI_GOH(Devices[0], sAxis.c_str());
  496. isMoving_sAxisY = PI_GOH(Devices[1], sAxis.c_str());
  497. if (isMoving_sAxisX || isMoving_sAxisY)
  498. {
  499. BusyState();
  500. timer_WorkState->start();
  501. }
  502. else
  503. {
  504. QMessageBox::critical(this, tr("错误"), tr("不能移动到零点!"));
  505. }
  506. }
  507. else
  508. {
  509. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  510. }
  511. }
  512. void CGH_Printer::TranstableStop()
  513. {
  514. if (curTransTableState)
  515. {
  516. PI_HLT(Devices[0], sAxis.c_str());
  517. PI_HLT(Devices[1], sAxis.c_str());
  518. timer_WorkState->start();
  519. }
  520. else
  521. {
  522. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  523. }
  524. }
  525. void CGH_Printer::Expose()
  526. {
  527. if (curShutterState)
  528. {
  529. BusyState();
  530. int Ext = ui.lineEditShutter->text().toInt();// 快门曝光时间
  531. timer_Expose->setInterval(Ext);
  532. MyShutter->open();
  533. curShutterWorkState = true;
  534. timer_Expose->start();
  535. timer_WorkState->start();
  536. }
  537. else
  538. {
  539. QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
  540. }
  541. }
  542. void CGH_Printer::ShutterStop()
  543. {
  544. if (curShutterState)
  545. {
  546. MyShutter->close();
  547. curShutterWorkState = false;
  548. timer_Expose->stop();
  549. timer_WorkState->start();
  550. }
  551. else
  552. {
  553. QMessageBox::critical(this, tr("错误"), tr("电子快门未连接!"));
  554. }
  555. }
  556. void CGH_Printer::ExposeUpdate()
  557. {
  558. timer_Expose->stop();
  559. MyShutter->close();
  560. curShutterWorkState = false;
  561. }
  562. void CGH_Printer::WorkTimeUpdate()
  563. {
  564. timePrintCur = clock();
  565. Printtimed = (timePrintCur - timePrintStart) / CLOCKS_PER_SEC;
  566. string Worktimed;
  567. Worktimed = formatTime(Printtimed);
  568. ui.lineEditPrinted->setText(QString::fromStdString(Worktimed));
  569. }
  570. void CGH_Printer::PrintOKUpdate()
  571. {
  572. ReadyState();
  573. // UI控件设置
  574. ui.pushButtonPrintOK->setChecked(false);
  575. labelPrint->clear();
  576. ui.labelSLMCopy->clear();
  577. timer_Work->stop();
  578. ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
  579. QMessageBox::about(this, tr("提示"), tr("打印已完成!"));
  580. }
  581. void CGH_Printer::PrintCancelUpdate()
  582. {
  583. ReadyState();
  584. // UI控件设置
  585. ui.pushButtonPrintOK->setChecked(false);
  586. ui.progressBarPrint->setValue(0);
  587. ui.lineEditPrinted->setText("00:00:00");
  588. ui.lineEditStart->setText("00:00:00");
  589. labelPrint->clear();
  590. ui.labelSLMCopy->clear();
  591. ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
  592. timer_Work->stop();
  593. QMessageBox::about(this, tr("提示"), tr("打印已停止!"));
  594. }
  595. // 平移台轴坐标实时更新
  596. void CGH_Printer::CoordinateUpdate()
  597. {
  598. PI_qPOS(Devices[0], sAxis.c_str(), &CoordinateX);
  599. PI_qPOS(Devices[1], sAxis.c_str(), &CoordinateY);
  600. ui.labelXPosition->setText(QString::number(CoordinateX, 'f', 3));
  601. ui.labelYPosition->setText(QString::number(CoordinateY, 'f', 3));
  602. }
  603. // 新建工程
  604. void CGH_Printer::NewProject()
  605. {
  606. CGH_ProjectView* myNewProjectView = new CGH_ProjectView(this);
  607. CGH_Project* myNewProject = new CGH_Project();
  608. myNewProjectView->initWindow();
  609. if (myNewProjectView->exec() == QDialog::Accepted) {
  610. //保存参数
  611. myNewProject->setWorkName(myNewProjectView->getViewName());
  612. myNewProject->setWorkLSpacing(myNewProjectView->getViewLSpacing());
  613. myNewProject->setWorkCSpacing(myNewProjectView->getViewCSpacing());
  614. myNewProject->setWorkLine(myNewProjectView->getViewLine());
  615. myNewProject->setWorkColumn(myNewProjectView->getViewColumn());
  616. myNewProject->setWorkPrefix(myNewProjectView->getViewPrefix());
  617. myNewProject->setWorkExpose(myNewProjectView->getViewExpose());
  618. myNewProject->setWorkQuiet(myNewProjectView->getViewQuiet());
  619. myNewProject->setWorkResource(myNewProjectView->getViewResource());
  620. myNewProject->saveToLocal();
  621. addProject(myNewProject);
  622. }
  623. }
  624. // 修改工程
  625. void CGH_Printer::ModifyProject() {
  626. if (pButtonGroup->checkedButton())
  627. {
  628. CGH_ProjectView* myModifyProjectView = new CGH_ProjectView(this);
  629. string ModifyProjectName = (pButtonGroup->checkedButton())->text().toStdString();
  630. CGH_Project* myModifyProject = new CGH_Project(ModifyProjectName);
  631. myModifyProjectView->initWindow();
  632. myModifyProjectView->setViewName(myModifyProject->getWorkName());
  633. myModifyProjectView->setViewLSpacing(myModifyProject->getWorkLSpacing());
  634. myModifyProjectView->setViewCSpacing(myModifyProject->getWorkCSpacing());
  635. myModifyProjectView->setViewLine(myModifyProject->getWorkLine());
  636. myModifyProjectView->setViewColumn(myModifyProject->getWorkColumn());
  637. myModifyProjectView->setViewPrefix(myModifyProject->getWorkPrefix());
  638. myModifyProjectView->setViewExpose(myModifyProject->getWorkExpose());
  639. myModifyProjectView->setViewQuiet(myModifyProject->getWorkQuiet());
  640. myModifyProjectView->setViewResource(myModifyProject->getWorkResource());
  641. if (myModifyProjectView->exec() == QDialog::Accepted) {
  642. string fullProjectName;
  643. fullProjectName = absProjectPath + "/" + (myModifyProject->getWorkName()) + ProjectType;
  644. remove(fullProjectName.c_str());
  645. ui.verticalLayoutWork->removeWidget(pButtonGroup->checkedButton());
  646. delete pButtonGroup->checkedButton();
  647. myModifyProject->setWorkName(myModifyProjectView->getViewName());
  648. myModifyProject->setWorkLSpacing(myModifyProjectView->getViewLSpacing());
  649. myModifyProject->setWorkCSpacing(myModifyProjectView->getViewCSpacing());
  650. myModifyProject->setWorkLine(myModifyProjectView->getViewLine());
  651. myModifyProject->setWorkColumn(myModifyProjectView->getViewColumn());
  652. myModifyProject->setWorkPrefix(myModifyProjectView->getViewPrefix());
  653. myModifyProject->setWorkExpose(myModifyProjectView->getViewExpose());
  654. myModifyProject->setWorkQuiet(myModifyProjectView->getViewQuiet());
  655. myModifyProject->setWorkResource(myModifyProjectView->getViewResource());
  656. myModifyProject->saveToLocal();
  657. addProject(myModifyProject);
  658. }
  659. }
  660. else
  661. {
  662. QMessageBox::about(this, tr("提示"), tr("未选中工程!"));
  663. }
  664. }
  665. // 添加工程文件
  666. void CGH_Printer::addProject(CGH_Project* pj)
  667. {
  668. string WorkName = pj->getWorkName();
  669. addProject(WorkName);
  670. }
  671. void CGH_Printer::addProject(const string& name)
  672. {
  673. QPushButton* Button = new QPushButton;
  674. string fullprojectName = name + ProjectType;
  675. Button->setText(QString::fromLocal8Bit(fullprojectName.c_str()));
  676. Button->setCheckable(true);
  677. //Button->setAutoExclusive(true);
  678. pButtonGroup->addButton(Button);
  679. ui.verticalLayoutWork->addWidget(Button);
  680. }
  681. // 删除工程文件
  682. void CGH_Printer::DeleteProject()
  683. {
  684. string fileName;
  685. QString ButtonName;
  686. fileName = (pButtonGroup->checkedButton())->text().toStdString();
  687. ButtonName = (pButtonGroup->checkedButton())->objectName();
  688. QPushButton* tempButton = this->findChild<QPushButton *>(ButtonName);
  689. string fullProjectName;
  690. fullProjectName = absProjectPath + "/" + fileName;
  691. if (QMessageBox::warning(this, tr("提示"), tr("确定删除工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  692. {
  693. remove(fullProjectName.c_str());
  694. ui.verticalLayoutWork->removeWidget(pButtonGroup->checkedButton());
  695. delete pButtonGroup->checkedButton();
  696. }
  697. return;
  698. }
  699. void CGH_Printer::Underfeed()
  700. {
  701. if (curTransTableState)
  702. {
  703. if (!PI_GOH(Devices[0], sAxis.c_str()) && !PI_FNL(Devices[1], sAxis.c_str()))
  704. {
  705. QMessageBox::critical(this, tr("错误"), tr("不能完成下料!"));
  706. }
  707. else
  708. {
  709. BusyState();
  710. timer_WorkState->start();
  711. }
  712. }
  713. else
  714. {
  715. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  716. }
  717. }
  718. void CGH_Printer::TempSaved()
  719. {
  720. if (curTransTableState)
  721. {
  722. if (QMessageBox::information(this, tr("提示"), tr("是否暂时保存配置?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  723. {
  724. AccX = ui.lineEditAccX->text().toDouble();
  725. AccY = ui.lineEditAccY->text().toDouble();
  726. DecX = ui.lineEditDecX->text().toDouble();
  727. DecY = ui.lineEditDecY->text().toDouble();
  728. MaxvX = ui.lineEditMaxvX->text().toDouble();
  729. MaxvY = ui.lineEditMaxvY->text().toDouble();
  730. PI_SPA(Devices[0], sAxis.c_str(), &Acc, &AccX, NULL);
  731. PI_SPA(Devices[1], sAxis.c_str(), &Acc, &AccY, NULL);
  732. PI_SPA(Devices[0], sAxis.c_str(), &Dec, &DecX, NULL);
  733. PI_SPA(Devices[1], sAxis.c_str(), &Dec, &DecY, NULL);
  734. PI_SPA(Devices[0], sAxis.c_str(), &Maxv, &MaxvX, NULL);
  735. PI_SPA(Devices[1], sAxis.c_str(), &Maxv, &MaxvY, NULL);
  736. }
  737. else
  738. {
  739. ReadTransTableConfigue();
  740. }
  741. }
  742. else
  743. {
  744. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  745. }
  746. }
  747. void CGH_Printer::PermSaved()
  748. {
  749. if (curTransTableState)
  750. {
  751. if (QMessageBox::information(this, tr("提示"), tr("是否永久保存配置?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  752. {
  753. AccX = ui.lineEditAccX->text().toDouble();
  754. AccY = ui.lineEditAccY->text().toDouble();
  755. DecX = ui.lineEditDecX->text().toDouble();
  756. DecY = ui.lineEditDecY->text().toDouble();
  757. MaxvX = ui.lineEditMaxvX->text().toDouble();
  758. MaxvY = ui.lineEditMaxvY->text().toDouble();
  759. PI_SPA(Devices[0], sAxis.c_str(), &Acc, &AccX, NULL);
  760. PI_SPA(Devices[1], sAxis.c_str(), &Acc, &AccY, NULL);
  761. PI_SPA(Devices[0], sAxis.c_str(), &Dec, &DecX, NULL);
  762. PI_SPA(Devices[1], sAxis.c_str(), &Dec, &DecY, NULL);
  763. PI_SPA(Devices[0], sAxis.c_str(), &Maxv, &MaxvX, NULL);
  764. PI_SPA(Devices[1], sAxis.c_str(), &Maxv, &MaxvY, NULL);
  765. PI_RPA(Devices[0], sAxis.c_str(), &Acc);
  766. PI_RPA(Devices[1], sAxis.c_str(), &Acc);
  767. PI_RPA(Devices[0], sAxis.c_str(), &Dec);
  768. PI_RPA(Devices[1], sAxis.c_str(), &Dec);
  769. PI_RPA(Devices[0], sAxis.c_str(), &Maxv);
  770. PI_RPA(Devices[1], sAxis.c_str(), &Maxv);
  771. }
  772. else
  773. {
  774. ReadTransTableConfigue();
  775. }
  776. }
  777. else
  778. {
  779. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  780. }
  781. }
  782. void CGH_Printer::Feed()
  783. {
  784. if (curTransTableState)
  785. {
  786. if (!PI_GOH(Devices[1], sAxis.c_str()) && !PI_GOH(Devices[0], sAxis.c_str()))
  787. {
  788. QMessageBox::critical(this, tr("错误"), tr("不能完成上料!"));
  789. }
  790. else
  791. {
  792. BusyState();
  793. timer_WorkState->start();
  794. }
  795. }
  796. else
  797. {
  798. QMessageBox::critical(this, tr("错误"), tr("平移台未连接!"));
  799. }
  800. }
  801. // 打印选中的工程
  802. void CGH_Printer::PrintTemp()
  803. {
  804. if (pButtonGroup->checkedButton())
  805. {
  806. Print();
  807. }
  808. else
  809. {
  810. QMessageBox::about(this, tr("提示"), tr("未选中工程!"));
  811. }
  812. }
  813. void CGH_Printer::Print()
  814. {
  815. if (QMessageBox::information(this, tr("提示"), tr("是否加载工程?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  816. {
  817. string PrintProjectName = (pButtonGroup->checkedButton())->text().toStdString();
  818. CGH_Project* PrintProject = new CGH_Project(PrintProjectName);
  819. PrintName = PrintProject->getWorkName();
  820. PrintLSpacing = stod(PrintProject->getWorkLSpacing());
  821. PrintCSpacing = stod(PrintProject->getWorkCSpacing());
  822. PrintLine = stoi(PrintProject->getWorkLine());
  823. PrintColumn = stoi(PrintProject->getWorkColumn());
  824. PrintPrefix = PrintProject->getWorkPrefix();
  825. PrintExpose = stoi(PrintProject->getWorkExpose());
  826. PrintQuiet = stoi(PrintProject->getWorkQuiet());
  827. PrintResource = PrintProject->getWorkResource();
  828. ui.tabWidget->setCurrentIndex(3);
  829. ui.lineEditPrintName->setText(QString::fromStdString(PrintName));
  830. ui.progressBarPrint->setValue(0);
  831. labelPrint->clear();
  832. // 加载实物图
  833. string sep = "/";
  834. string Format = ".bmp";
  835. string Phyfilename;// 实物图路径
  836. Phyfilename = PrintResource + sep + PrintPrefix + Format;
  837. ui.labelPhy->setPixmap(QPixmap(QString::fromStdString(Phyfilename)));
  838. }
  839. }
  840. void CGH_Printer::SLMUpdate(const QString& tempCGH)
  841. {
  842. labelPrint->clear();
  843. labelPrint->setPixmap(QPixmap(tempCGH));
  844. ui.labelSLMCopy->setPixmap(QPixmap(tempCGH));
  845. QString CurPrintName;
  846. CurPrintName = QString::fromStdString(PrintName) + "(" + tempCGH + ")";
  847. ui.lineEditPrintName->setText(tempCGH);
  848. }
  849. void CGH_Printer::PrintUpdate(int tempLL, int tempCC)
  850. {
  851. PrintLL = tempLL;
  852. PrintCC = tempCC;
  853. CurProgress = (PrintLL - 1) * PrintColumn + PrintCC;
  854. FulProgress = PrintLine * PrintColumn;
  855. ui.progressBarPrint->setMaximum(FulProgress);
  856. ui.progressBarPrint->setValue(CurProgress);
  857. }
  858. void CGH_Printer::PrintStop()
  859. {
  860. if (QMessageBox::warning(this, tr("提示"), tr("是否停止打印?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  861. {
  862. PRINTSTOP = TRUE;
  863. }
  864. }
  865. // 打印工作进程
  866. void CGH_Printer::PrintProgress()
  867. {
  868. if (!ui.lineEditPrintName->text().isEmpty() && curTransTableState && curShutterState && curSLMState)
  869. {
  870. if (QMessageBox::warning(this, tr("提示"), tr("是否开始打印?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  871. {
  872. PRINTSTOP = FALSE;
  873. BusyState();
  874. // 开始工作时间
  875. QDateTime timeStart = QDateTime::currentDateTime();
  876. QString str = timeStart.toString("hh:mm:ss");
  877. ui.lineEditStart->setText(str);
  878. // 已打印
  879. timePrintStart = clock();
  880. timer_Work->start();
  881. m_Printer->start();
  882. }
  883. else
  884. {
  885. ui.pushButtonPrintOK->setChecked(false);
  886. }
  887. }
  888. else if (ui.lineEditPrintName->text().isEmpty())
  889. {
  890. ui.pushButtonPrintOK->setChecked(false);
  891. QMessageBox::about(this, tr("提示"), tr("未加载工程!"));
  892. }
  893. else
  894. {
  895. ui.pushButtonPrintOK->setChecked(false);
  896. QMessageBox::about(this, tr("提示"), tr("请检查电子快门、空间光调制器和电控平移台的状态!"));
  897. }
  898. }
  899. void CGH_Printer::ComboDevice()
  900. {
  901. ui.comboBoxDevice->clear();
  902. m_pCameraInfos = QCameraInfo::availableCameras();
  903. for (int i = 0; i < m_pCameraInfos.size(); i++)
  904. {
  905. ui.comboBoxDevice->addItem(m_pCameraInfos[i].description());
  906. }
  907. m_pCameraIndex = ui.comboBoxDevice->currentIndex();
  908. }
  909. // 切换设备
  910. void CGH_Printer::ChangeDevice()
  911. {
  912. if (m_pCameraOpen)
  913. {
  914. CloseCamera();
  915. m_pCameraIndex = ui.comboBoxDevice->currentIndex();
  916. OpenCamera();
  917. ComboFormatandFramerate();
  918. }
  919. }
  920. // 切换分辨率
  921. void CGH_Printer::ChangeFormat()
  922. {
  923. if (m_pCameraOpen)
  924. {
  925. QString strFormat = ui.comboBoxFormat->currentText();
  926. QStringList ListFormat = strFormat.split('x');
  927. CloseCamera();
  928. m_pCamera = new QCamera(m_pCameraInfos[m_pCameraIndex]);
  929. QCameraViewfinderSettings* m_pCameraSet = new QCameraViewfinderSettings();
  930. m_pCameraSet->setResolution(ListFormat[0].toInt(), ListFormat[1].toInt());
  931. m_pCamera->setViewfinderSettings(*m_pCameraSet);
  932. m_pCamera->setViewfinder(m_pViewfinder);
  933. m_pCamera->start();
  934. }
  935. }
  936. void CGH_Printer::CGHLoad()
  937. {
  938. QFileDialog* CGH_dialog = new QFileDialog(this);
  939. QString filefull;
  940. QString Fullfilename;
  941. QFileInfo fileinfo;
  942. QString curPath = QString::fromStdString(absResourcesPath);// 默认路径
  943. // 路径不存在则创建路径
  944. QDir dir(curPath);
  945. if (!dir.exists(curPath))
  946. {
  947. dir.mkdir(curPath);
  948. }
  949. QString dlgTitle = "选择文件";// 对话框标题
  950. QString filter = "Bmp Files(*.bmp)";// 文件过滤器
  951. filefull = CGH_dialog->getOpenFileName(this, dlgTitle, curPath, filter);
  952. QFileInfo file(filefull);
  953. //点击确定按钮
  954. if (file.isFile() && file.exists())
  955. {
  956. //获取新建项目路径
  957. fileinfo = QFileInfo(filefull);
  958. Fullfilename = fileinfo.absolutePath() + "/" + fileinfo.fileName();
  959. ui.lineEditCGHName->setText(Fullfilename);//设置路径栏
  960. ui.labelCGHDisplay->clear();
  961. ui.labelCGHDisplay->setPixmap(QPixmap(Fullfilename));
  962. // labelPrint->setPixmap(QPixmap(Fullfilename));
  963. if (Desktop->numScreens() == 2)
  964. {
  965. labelPrint->clear();
  966. labelPrint->setPixmap(QPixmap(Fullfilename));
  967. }
  968. }
  969. //点取消则返回
  970. else
  971. {
  972. return;
  973. }
  974. delete CGH_dialog;
  975. CGH_dialog = NULL;
  976. }
  977. // 视频预览
  978. void CGH_Printer::Preview()
  979. {
  980. if (m_pCameraInfos.size() > 0)
  981. {
  982. if (!m_pCameraOpen)
  983. {
  984. ui.pushButtonPreview->setText("停止");
  985. OpenCamera();
  986. ComboFormatandFramerate();
  987. m_pCameraOpen = TRUE;
  988. }
  989. else
  990. {
  991. ui.pushButtonPreview->setText("预览");
  992. CloseCamera();
  993. m_pCameraOpen = FALSE;
  994. ui.comboBoxFormat->clear();
  995. ui.comboBoxFramerate->clear();
  996. delete m_pCamera;
  997. }
  998. }
  999. else
  1000. {
  1001. QMessageBox::about(this, tr("提示"), tr("打开相机失败!"));
  1002. }
  1003. }
  1004. // 视频截图
  1005. void CGH_Printer::Snapshot()
  1006. {
  1007. if (m_pCameraOpen)
  1008. {
  1009. string filename;
  1010. m_pCameraCapture = new QCameraImageCapture(m_pCamera);
  1011. m_pCameraCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
  1012. QString curPath = QString::fromStdString(absCapturePath);// 默认路径
  1013. // 路径不存在则创建路径
  1014. QDir dir(curPath);
  1015. if (!dir.exists(curPath))
  1016. {
  1017. dir.mkdir(curPath);
  1018. }
  1019. QString dlgTitle = "保存文件";// 对话框标题
  1020. QString filter = "Jpep Files(*.jpg)";// 文件过滤器
  1021. QString aFileName = QFileDialog::getSaveFileName(this, dlgTitle, curPath, filter);
  1022. if (!aFileName.isEmpty())
  1023. m_pCameraCapture->capture(aFileName);
  1024. // 默认输出到Capture文件夹
  1025. // QDir dir(QString::fromStdString(absCapturePath));
  1026. // dir.setFilter(QDir::Files | QDir::NoSymLinks);
  1027. // QFileInfoList list = dir.entryInfoList();
  1028. // int file_count = list.count();
  1029. // if (!dir.exists() || file_count <= 0)
  1030. // {
  1031. // filename = absCapturePath + "/Cap_0";
  1032. // }
  1033. // else
  1034. // {
  1035. // QStringList string_list;
  1036. // int maxindex = 0;
  1037. // for (int i = 0; i < file_count; i++)
  1038. // {
  1039. // QFileInfo file_info = list.at(i);
  1040. // QString curfilename = file_info.fileName();
  1041. // int start = curfilename.lastIndexOf("_");
  1042. // int end = curfilename.lastIndexOf(".");
  1043. // QString temp = curfilename.mid(start+1, end - start-1);
  1044. // int curindex = temp.toInt();
  1045. // maxindex = qMax(maxindex, curindex);
  1046. // }
  1047. // filename = absCapturePath + "/Cap_" + to_string(maxindex + 1);
  1048. // }
  1049. }
  1050. else
  1051. {
  1052. QMessageBox::about(this, tr("提示"), tr("相机未开启!"));
  1053. }
  1054. }
  1055. void CGH_Printer::ComboFormatandFramerate()
  1056. {
  1057. QList<QSize> m_pCameraFormats = m_pCamera->supportedViewfinderResolutions();
  1058. QString strFormat;
  1059. foreach(QSize m_pCameraFormat, m_pCameraFormats)
  1060. {
  1061. strFormat = QString("%1x%2").arg(m_pCameraFormat.width()).arg(m_pCameraFormat.height());
  1062. ui.comboBoxFormat->addItem(strFormat);
  1063. }
  1064. QList<QCamera::FrameRateRange> m_pCameraFramerates = m_pCamera->supportedViewfinderFrameRateRanges();
  1065. foreach(QCamera::FrameRateRange m_pCameraFramerate, m_pCameraFramerates)
  1066. {
  1067. ui.comboBoxFramerate->addItem(QString::number(m_pCameraFramerate.maximumFrameRate, 'f', 0));
  1068. }
  1069. }
  1070. void CGH_Printer::OpenCamera()
  1071. {
  1072. m_pCamera = new QCamera(m_pCameraInfos[m_pCameraIndex]);
  1073. m_pCamera->setViewfinder(m_pViewfinder);
  1074. m_pCamera->setCaptureMode(QCamera::CaptureStillImage);
  1075. m_pCamera->start();
  1076. QList<QSize> ViewFormats = m_pCamera->supportedViewfinderResolutions();
  1077. QCameraViewfinderSettings* initm_pCameraSet = new QCameraViewfinderSettings();
  1078. initm_pCameraSet->setResolution(ViewFormats[0].width(), ViewFormats[0].height());
  1079. QList<QCamera::FrameRateRange> ViewFramerates = m_pCamera->supportedViewfinderFrameRateRanges();
  1080. initm_pCameraSet->setMaximumFrameRate(ViewFramerates[0].maximumFrameRate);
  1081. initm_pCameraSet->setMinimumFrameRate(ViewFramerates[0].minimumFrameRate);
  1082. m_pCamera->setViewfinderSettings(*initm_pCameraSet);
  1083. }
  1084. void CGH_Printer::CloseCamera()
  1085. {
  1086. m_pCamera->stop();
  1087. }
  1088. void CGH_Printer::SLMDisplay()
  1089. {
  1090. QRect winMain = Desktop->screenGeometry(1);
  1091. labelPrint->setGeometry(winMain);
  1092. labelPrint->setWindowFlags(Qt::FramelessWindowHint |
  1093. Qt::WindowStaysOnTopHint |
  1094. Qt::Popup | Qt::Tool);//设置窗口弹出、无边框、窗口置顶
  1095. //labelPrint->setWindowFlags(Qt::FramelessWindowHint |
  1096. // Qt::WindowStaysOnTopHint |
  1097. // Qt::Popup | Qt::Tool);//设置窗口弹出、无边框、窗口置顶
  1098. labelPrint->setCursor(Qt::BlankCursor);
  1099. //labelPrint->move(winMain.width(), 0);
  1100. labelPrint->showFullScreen();
  1101. labelPrint->setAlignment(Qt::AlignCenter);
  1102. labelPrint->setScaledContents(true);
  1103. }
  1104. void CGH_Printer::PITransTableInit()
  1105. {
  1106. for (int num = 1; num <= DeviceNum; num++)
  1107. {
  1108. int Device = PI_ConnectDaisyChainDevice(ControllerID, num);
  1109. if (Device >= 0)
  1110. {
  1111. Devices.push_back(Device);
  1112. }
  1113. }
  1114. // 轴开启伺服控制
  1115. for (const auto& Device : Devices)
  1116. {
  1117. PI_SVO(Device, sAxis.c_str(), &SERVO_ON);
  1118. }
  1119. BusyState();
  1120. timer_WorkState->start();
  1121. // 轴参考移动
  1122. for (const auto& Device : Devices)
  1123. {
  1124. PI_FRF(Device, sAxis.c_str());
  1125. }
  1126. }
  1127. void CGH_Printer::closeEvent(QCloseEvent* event)
  1128. {
  1129. if (QMessageBox::information(this, tr("提示"), tr("是否关闭程序?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
  1130. {
  1131. event->accept();
  1132. }
  1133. else
  1134. {
  1135. event->ignore();
  1136. }
  1137. }
  1138. string CGH_Printer::numberToString(int n,int l)
  1139. {
  1140. string res = to_string(n);
  1141. int length = res.size();
  1142. while (length++ < l) {
  1143. res = "0" + res;
  1144. }
  1145. return res;
  1146. }
  1147. std::string CGH_Printer::formatTime(long ss)
  1148. {
  1149. int mi = 60;
  1150. int hh = mi * 60;
  1151. long hour = ss / hh;
  1152. long minute = (ss - hour * hh) / mi;
  1153. long second = ss - hour * hh - minute * mi;
  1154. string shour, sminute, ssecond;
  1155. shour = numberToString(hour, 2);
  1156. sminute = numberToString(minute, 2);
  1157. ssecond = numberToString(second, 2);
  1158. string format;
  1159. format = shour + ":" + sminute + ":" + ssecond;
  1160. return format;
  1161. }