CGH_Printer.cpp 40 KB

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