123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include "PrintThread.h"
- PrintThread::PrintThread(QObject* parent) : m_Printer(dynamic_cast<CGH_Printer*>(parent))
- {
- connect(this, SIGNAL(TransCGH(const QString&)), m_Printer, SLOT(SLMUpdate(const QString&)));
- connect(this, SIGNAL(TransPrintProgress(int, int)), m_Printer, SLOT(PrintUpdate(int, int)));
- connect(this, SIGNAL(PrintOK()), m_Printer, SLOT(PrintOKUpdate()));
- connect(this, SIGNAL(PrintCancel()), m_Printer, SLOT(PrintCancelUpdate()));
- // 初始化变量
- MyShutter = new CGH_Shutter();
- HoloLine = 0;
- HoloColumn = 0;
- OffsetX = 0;
- PrintColumn = 0;
- PrintExpose = 0;
- PrintLine = 0;
- PrintQuiet = 0;
- PrintLSpacing = 0;
- PrintCSpacing = 0;
- initPrintX = 0;
- initPrintY = 0;
- PRINTSTOP = FALSE;
- }
- PrintThread::~PrintThread()
- {
- }
- std::string PrintThread::numberToString(int n, int l /*= 3*/)
- {
- string res = to_string(n);
- int length = res.size();
- while (length++ < l) {
- res = "0" + res;
- }
- return res;
- }
- void PrintThread::run()
- {
- Print();
- if (!PRINTSTOP)
- {
- emit PrintOK();
- }
- else
- {
- emit PrintCancel();
- }
- }
- void PrintThread::Print()
- {
- PRINTSTOP = FALSE;
- // 主线程参数传递到子线程
- Devices = m_Printer->Get_Devices();
- sAxis = m_Printer->Get_sAxis();
- PrintLSpacing = m_Printer->Get_PrintLSpacing();
- PrintCSpacing = m_Printer->Get_PrintCSpacing();
- PrintLine = m_Printer->Get_PrintLine();
- PrintColumn = m_Printer->Get_PrintColumn();
- PrintPrefix = m_Printer->Get_PrintPrefix();
- PrintExpose = m_Printer->Get_PrintExpose();
- PrintQuiet = m_Printer->Get_PrintQuiet();
- PrintResource = m_Printer->Get_PrintResource();
- // 平移台
- HoloLine = PrintLSpacing * PrintLine;
- HoloColumn = PrintCSpacing * PrintColumn;
- initPrintX = -(HoloColumn + PrintCSpacing) / 2;
- initPrintY = -(HoloLine - PrintLSpacing) / 2;
- PI_MOV(Devices[0], sAxis.c_str(), &initPrintX);
- PI_MOV(Devices[1], sAxis.c_str(), &initPrintY);
- BOOL isMoving_sAxisX = TRUE;
- BOOL isMoving_sAxisY = TRUE;
- while (isMoving_sAxisX || isMoving_sAxisY)
- {
- PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
- PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
- QCoreApplication::processEvents();
- }
- // 开始打印任务
- int LL, CC, KK;
- string Format = ".bmp";
- string sep = "/";
- string Filename, PrintFullname;
- string midl, midr;
- OffsetY = PrintLSpacing;
- for (LL = 1; LL <= PrintLine; LL++)
- {
- midl = numberToString(LL);
- for (CC = 1; CC <= PrintColumn; CC++)
- {
- if (LL % 2 == 1)
- {
- KK = CC;
- midr = numberToString(KK);
- }
- else
- {
- KK = PrintColumn - CC + 1;
- midr = numberToString(KK);
- }
- Filename = PrintPrefix + midl + midr + Format;
- PrintFullname = PrintResource + sep + Filename;
- if (LL % 2 == 1)
- {
- OffsetX = PrintCSpacing;
- PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
- }
- else
- {
- OffsetX = -1 * PrintCSpacing;
- PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
- }
- isMoving_sAxisX = TRUE;
- isMoving_sAxisY = TRUE;
- while (isMoving_sAxisX || isMoving_sAxisY)
- {
- PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
- PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
- QCoreApplication::processEvents();
- }
- emit TransCGH(QString::fromStdString(PrintFullname));
- Sleep(PrintQuiet);// 静台
- MyShutter->open();
- Sleep(PrintExpose);
- MyShutter->close();
- emit TransPrintProgress(LL, CC);
- PRINTSTOP = m_Printer->Get_PRINTSTOP();
- if (PRINTSTOP)
- {
- break;
- }
- }
- if (LL % 2 == 1)
- {
- OffsetX = PrintCSpacing;
- PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
- }
- else
- {
- OffsetX = -1 * PrintCSpacing;
- PI_MVR(Devices[0], sAxis.c_str(), &OffsetX);
- }
- PI_MVR(Devices[1], sAxis.c_str(), &OffsetY);
- isMoving_sAxisX = TRUE;
- isMoving_sAxisY = TRUE;
- while (isMoving_sAxisX || isMoving_sAxisY)
- {
- PI_IsMoving(Devices[0], sAxis.c_str(), &isMoving_sAxisX);
- PI_IsMoving(Devices[1], sAxis.c_str(), &isMoving_sAxisY);
- QCoreApplication::processEvents();
- }
- if (PRINTSTOP)
- {
- break;
- }
- }
- }
|