CGH_Printer.cpp 40 KB

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