PrintThread.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "PrintThread.h"
  2. PrintThread::PrintThread(QObject* parent) : m_Printer(dynamic_cast<CGH_Printer*>(parent))
  3. {
  4. connect(this, SIGNAL(TransCGH(const QString&)), m_Printer, SLOT(SLMUpdate(const QString&)));
  5. connect(this, SIGNAL(TransPrintProgress(int, int)), m_Printer, SLOT(PrintUpdate(int, int)));
  6. connect(this, SIGNAL(PrintOK()), m_Printer, SLOT(PrintOKUpdate()));
  7. connect(this, SIGNAL(PrintCancel()), m_Printer, SLOT(PrintCancelUpdate()));
  8. // 初始化变量
  9. MyShutter = new CGH_Shutter();
  10. HoloLine = 0;
  11. HoloColumn = 0;
  12. OffsetX = 0;
  13. PrintColumn = 0;
  14. PrintExpose = 0;
  15. PrintLine = 0;
  16. PrintQuiet = 0;
  17. PrintLSpacing = 0;
  18. PrintCSpacing = 0;
  19. initPrintX = 0;
  20. initPrintY = 0;
  21. PRINTSTOP = FALSE;
  22. }
  23. PrintThread::~PrintThread()
  24. {
  25. }
  26. std::string PrintThread::numberToString(int n, int l /*= 3*/)
  27. {
  28. string res = to_string(n);
  29. int length = res.size();
  30. while (length++ < l) {
  31. res = "0" + res;
  32. }
  33. return res;
  34. }
  35. void PrintThread::run()
  36. {
  37. Print();
  38. if (!PRINTSTOP)
  39. {
  40. emit PrintOK();
  41. }
  42. else
  43. {
  44. emit PrintCancel();
  45. }
  46. }
  47. void PrintThread::Print()
  48. {
  49. PRINTSTOP = FALSE;
  50. // 主线程参数传递到子线程
  51. Devices = m_Printer->Get_Devices();
  52. sAxis = m_Printer->Get_sAxis();
  53. PrintLSpacing = m_Printer->Get_PrintLSpacing();
  54. PrintCSpacing = m_Printer->Get_PrintCSpacing();
  55. PrintLine = m_Printer->Get_PrintLine();
  56. PrintColumn = m_Printer->Get_PrintColumn();
  57. PrintPrefix = m_Printer->Get_PrintPrefix();
  58. PrintExpose = m_Printer->Get_PrintExpose();
  59. PrintQuiet = m_Printer->Get_PrintQuiet();
  60. PrintResource = m_Printer->Get_PrintResource();
  61. // 平移台
  62. HoloLine = PrintLSpacing * PrintLine;
  63. HoloColumn = PrintCSpacing * PrintColumn;
  64. initPrintX = -(HoloColumn + PrintCSpacing) / 2;
  65. initPrintY = -(HoloLine - PrintLSpacing) / 2;
  66. PI_MOV(Devices[0], sAxis.c_str(), &initPrintX);
  67. PI_MOV(Devices[1], sAxis.c_str(), &initPrintY);
  68. BOOL isMoving_sAxisX = TRUE;
  69. BOOL isMoving_sAxisY = TRUE;
  70. while (isMoving_sAxisX || isMoving_sAxisY)
  71. {
  72. PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
  73. PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
  74. QCoreApplication::processEvents();
  75. }
  76. // 开始打印任务
  77. int LL, CC, KK;
  78. string Format = ".bmp";
  79. string sep = "/";
  80. string Filename, PrintFullname;
  81. string midl, midr;
  82. OffsetY = PrintLSpacing;
  83. for (LL = 1; LL <= PrintLine; LL++)
  84. {
  85. midl = numberToString(LL);
  86. for (CC = 1; CC <= PrintColumn; CC++)
  87. {
  88. if (LL % 2 == 1)
  89. {
  90. KK = CC;
  91. midr = numberToString(KK);
  92. }
  93. else
  94. {
  95. KK = PrintColumn - CC + 1;
  96. midr = numberToString(KK);
  97. }
  98. Filename = PrintPrefix + midl + midr + Format;
  99. PrintFullname = PrintResource + sep + Filename;
  100. if (LL % 2 == 1)
  101. {
  102. OffsetX = PrintCSpacing;
  103. PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
  104. }
  105. else
  106. {
  107. OffsetX = -1 * PrintCSpacing;
  108. PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
  109. }
  110. isMoving_sAxisX = TRUE;
  111. isMoving_sAxisY = TRUE;
  112. while (isMoving_sAxisX || isMoving_sAxisY)
  113. {
  114. PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
  115. PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
  116. QCoreApplication::processEvents();
  117. }
  118. emit TransCGH(QString::fromStdString(PrintFullname));
  119. Sleep(PrintQuiet);// 静台
  120. MyShutter->open();
  121. Sleep(PrintExpose);
  122. MyShutter->close();
  123. emit TransPrintProgress(LL, CC);
  124. PRINTSTOP = m_Printer->Get_PRINTSTOP();
  125. if (PRINTSTOP)
  126. {
  127. break;
  128. }
  129. }
  130. if (LL % 2 == 1)
  131. {
  132. OffsetX = PrintCSpacing;
  133. PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
  134. }
  135. else
  136. {
  137. OffsetX = -1 * PrintCSpacing;
  138. PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
  139. }
  140. PI_MVR(Devices[1], sAxis.c_str(), &OffsetY);
  141. isMoving_sAxisX = TRUE;
  142. isMoving_sAxisY = TRUE;
  143. while (isMoving_sAxisX || isMoving_sAxisY)
  144. {
  145. PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
  146. PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
  147. QCoreApplication::processEvents();
  148. }
  149. if (PRINTSTOP)
  150. {
  151. break;
  152. }
  153. }
  154. }