CGH_Printer.cpp 51 KB

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