diff --git a/NPlotter.pro b/NPlotter.pro index d6734ae..5951c53 100644 --- a/NPlotter.pro +++ b/NPlotter.pro @@ -68,10 +68,10 @@ SOURCES += \ machine/bmp/bwbmp.cpp \ machine/bmp/creatprintbmp.cpp \ machine/tcp/qbindtcpsocket.cpp \ - machine/tcp/tcpclient.cpp + machine/tcp/tcpclient.cpp \ + datafile/view/drawdata.cpp FORMS += \ - mainwidget.ui \ mainwindow.ui \ printviewwindow.ui \ printnumbersetdialog.ui \ @@ -135,7 +135,11 @@ HEADERS += \ machine/bmp/creatprintbmp.h \ machine/tcp/qbindtcpsocket.h \ machine/tcp/tcpclient.h \ - machine/printinfo/mcfiles.h + machine/printinfo/mcfiles.h \ + datafile/view/drawdata.h + +TRANSLATIONS += chinese.ts\ +english.ts RESOURCES += \ res.qrc diff --git a/chinese.qm b/chinese.qm new file mode 100644 index 0000000..44f7bbb Binary files /dev/null and b/chinese.qm differ diff --git a/chinese.ts b/chinese.ts new file mode 100644 index 0000000..efab92e --- /dev/null +++ b/chinese.ts @@ -0,0 +1,1089 @@ + + + + + AddMachineDialog + + + Dialog + + + + + Ok + 确定 + + + + Cancel + 取消 + + + + IP: + + + + + Name: + 名称: + + + + + Prompt + 提示 + + + + Please enter the correct IP! + 请输入正确的IP! + + + + Please enter the correct machine name! + 请输入正确的机器名称! + + + + DrawingSetDialog + + + Dialog + + + + + Use vector fonts + 使用矢量字体 + 使用矢量字体 + + + + Graph positive rotation 90 angle + Graph positive rotation angle + 图形正向旋转90度 + 图形正向旋转90度 + + + + Ok + 确定 + + + + Boundary and alignment spacing + 边界及对位间距 + 边界及对位间距 + + + + + + + mm + + + + + + 0 + + + + + Right margin: + 右边距: + 右边距: + + + + Mark margin: + 马克间距: + 马克间距: + + + + Butt joint margin: + 对接符间距: + 对接符间距: + + + + 1000 + + + + + Paper Width + 纸张宽度 + 纸张宽度 + + + + 2400 + + + + + Cancel + 取消 + + + + Lineweight settings + 线宽设置 + 线宽设置 + + + + Lineweight: + 线宽: + 线宽: + + + + 2 + + + + + pixel + 像素 + 像素 + + + + HistoryDialog + + + Dialog + + + + + Clear + 清除 + + + + Cancel + 取消 + + + + Draw + 绘制 + + + + ImportHPGL + + + Encrypted file parsing error! + 加密文件解析错误! + + + + MainWindow + + + MainWindow + + + + + Print Info + 打印信息 + + + + Total Files: + 文件总数: + + + + Total Length: + 总长度: + + + + Progress: + 打印进度: + + + + File(F) + 文件(F) + + + + Testing + 测试 + + + + Connect Manage(C) + 连接管理(C) + + + + Setting(S) + 设置(S) + + + + Language(L) + 语言(L) + + + + About(A) + 关于(A) + + + + toolBar + + + + + Open File + 打开文件 + + + + + Ctrl+O + + + + + Open Image + 打开图片 + + + + + Ctrl+I + + + + + + Start + 启动 + + + + + Pause + 停止 + + + + + + Delete + 删除 + + + + Ctrl+Del + + + + + Exit + 退出 + + + + USB + + + + + NetWork + 网络 + + + + Delete Link + 删除连接 + + + + Auto Print Dir + 自动绘图目录 + + + + log + 日志 + + + + Parameter Import + 参数导入 + + + + Parameter Export + 参数导出 + + + + Drawing Setting + 图形设置 + + + + Plotter Setting View + 绘图仪设置 + + + + Chinese + 中文 + + + + English + + + + + OpenFileIcon + + + + + OpenFile + 打开文件 + + + + OpenImageIcon + + + + + OpenImage + 打开图片 + + + + StartIcon + + + + + PauseIcon + + + + + DrawingSetIcon + + + + + DrawingSetting + + + + + Add Machine + 添加机器 + + + + Delete Machine + 删除机器 + + + + test1.plt + + + + + + + + + + + + + + Prompt + 提示 + + + + Printing this file, it cannot be moved! + 正在打印此文件,不可移动! + + + + + Connnecting... + 连接中... + + + + + Connected + 已连接 + + + + + + NotConnected + 未连接 + + + + + Idle + 空闲中 + + + + + Working + 工作中 + + + + + + Waitting + 未打印 + + + + + + Printting + 打印中 + + + + + FileName + 文件名称 + + + + + Length + 长度 + + + + + Width + 宽度 + + + + + Printed + 已打印 + + + + + Progress + 打印进度 + + + + + Numbers + 份数 + + + + + State + 状态 + + + + + FilePath + 文件路径 + + + + + StartPoint + 起点 + + + + + McName + 机器名称 + + + + + McIp + 机器IP + + + + + McConState + 连接状态 + + + + + McState + 工作状态 + + + + + McProgress + 打印进度 + + + + Print preview + 打印预览 + + + + Number of modified print + 修改打印份数 + + + + Modify the starting print point + 修改起始打印点 + + + + View print information + 查看打印信息 + + + + Do you want to delete this drawing? + 是否删除该项绘图? + + + + Printing this file, it cannot be deleted! + 正在打印此文件,不可删除! + + + + After deletion, the machine cannot be controlled. Do you want to delete this machine? + 删除后将不能控制机器,是否删除此机器? + + + + Complete + 打印完成 + + + + + Please select a machine! + 请选择机器! + + + + + Loading file, please wait! + 正在加载文件,请等待! + + + + + Open File Dialog + 打开文件对话框 + + + + File(*.plt *.dxf) + 文件(*.plt *.dxf) + + + + Image File(*.png *.bmp *.jpg) + 图片(*.png *.bmp *.jpg) + + + + Please select the machine you want to set the directory! + 请选择要设置目录的机器! + + + + Select Folder + 选择文件夹 + + + + The maximum number of connections has been reached and cannot be added again! + 已达到最大连接数量,不可再添加! + + + + PlotterSetDialog + + + Dialog + + + + + Print startup mode selection + 打印启动方式选择 + 打印启动方式选择 + + + + Auto Print + 自动打印 + 自动打印 + + + + Print mode selection + 打印模式选择 + 打印模式选择 + + + + Single + 单向 + 单向 + + + + Double + 双向 + 双向 + + + + Graphic error correction + 图形误差修正 + 图形误差修正 + + + + + 1000 + + + + + + + + + mm + + + + + + 1 meter actual output: + 1米实际输出: + 1米实际输出: + + + + Drawing 1 meter Square + 绘1米正方形 + 绘1米正方形 + + + + Two way print error setting + 双向打印误差设置 + 双向打印误差设置 + + + + + + + + + + + 0 + + + + + Two way print error: + 双向打印错位误差: + 双向打印错位误差: + + + + Print drawing width: + 打印图形宽度: + 打印图形宽度: + + + + 1600 + + + + + Print Error Correction + 打印误差修正图 + 打印误差修正图 + + + + Error setting between nozzles + 喷头间误差设置 + 喷头间误差设置 + + + + + + + + + pixel + 像素 + 像素 + + + + 1、2 error between nozzles: + 1、2喷头间错误误差: + 1、2喷头间错误误差: + + + + 2、3 error between nozzles: + 2、3喷头间错误误差: + 2、3喷头间错误误差: + + + + 3、4 error between nozzles: + 3、4喷头间错误误差: + 3、4喷头间错误误差: + + + + 1、2 overlap between nozzles: + 1、2喷头间重叠误差: + 1、2喷头间重叠误差: + + + + 2、3 overlap between nozzles: + 2、3喷头间重叠误差: + 2、3喷头间重叠误差: + + + + 3、4 overlap between nozzles: + 3、4喷头间重叠误差: + 3、4喷头间重叠误差: + + + + Correction diagram between nozzles + 打印喷头间误差修正图 + 打印喷头间误差修正图 + + + + Paper feeding error correction + 走纸误差修正 + 走纸误差修正 + + + + Paper feeding error set: + 走纸误差设置: + 走纸误差设置: + + + + Print paper feed error + 打印走纸误差 + 打印走纸误差 + + + + Ok + 确定 + 确定 + + + + Cancel + 取消 + 取消 + + + + Sprinkler selection + 喷头选择 + 喷头选择 + + + + Nozzle 1 + 1号喷头 + 1号喷头 + + + + Nozzle 2 + 2号喷头 + 2号喷头 + + + + Nozzle 3 + 3号喷头 + 3号喷头 + + + + Nozzle 4 + 4号喷头 + 4号喷头 + + + + PrintInfoDialog + + + Dialog + + + + + Working Info + 工作信息 + + + + File Name: + 文件名称: + + + + Width/Height: + 宽度/高度: + + + + Print Number: + 打印份数: + + + + Start Print Point: + 起始打印位置: + + + + Total Blocks: + 总块数: + + + + Current Print Block: + 当前打印块数: + + + + Printed Block Number: + 已打印块数: + + + + Leave Block Number: + 剩余打印块数: + + + + Select Block Number: + 当前选中块数: + + + + Back + 返回 + + + + piece + + + + + PrintNumberSetDialog + + + Dialog + + + + + (1-255) + + + + + 1 + + + + + Number: + 份数: + 份数: + + + + Ok + 确定 + + + + Cancel + 取消 + + + + Prompt + 提示 + + + + Unreasonable value input! + 数值输入不合理! + + + + PrintViewWindow + + + Print View + 打印预览 + + + + mm + + + + + + + 0 + + + + + Draw + 绘制 + + + + Y: + + + + + 1 + + + + + Start point: + 起始位置: + + + + X: + + + + + Number: + 份数: + + + + Prompt + 提示 + + + + Unreasonable value input! + 数值输入不合理! + + + + StartSetDialog + + + Dialog + + + + + Ok + 确定 + + + + Cancel + 取消 + + + + 0 + + + + + Start: + 起点: + + + + (range) + (范围) + + + + Prompt + 提示 + + + + Unreasonable value input! + 数值输入不合理! + + + diff --git a/datafile/hpgl/importhpgl.cpp b/datafile/hpgl/importhpgl.cpp index fbb4716..4bd04d6 100644 --- a/datafile/hpgl/importhpgl.cpp +++ b/datafile/hpgl/importhpgl.cpp @@ -119,6 +119,7 @@ void ImportHPGL::IniPara() m_pMarker=NULL; m_dScale=(double)1.0; + m_rotateAngle = 0; m_chTerminator = 3; m_nTerminatorMode = 1; @@ -242,7 +243,7 @@ void ImportHPGL::creatPolylinePainterPath() for(int j = 0; j < nPointCount; j++) { double x = (polyLine.m_listPoint.at(j).x() - minX)/(double)M_IDPMM*MMPIXELY; - double y = ((0 - (polyLine.m_listPoint.at(j).y() - minY))+(maxY-minY))/(double)M_IDPMM*MMPIXELY; + double y = (maxY - polyLine.m_listPoint.at(j).y())/(double)M_IDPMM*MMPIXELY; QPointF point(x,y); if(j == 0) @@ -629,6 +630,11 @@ bool ImportHPGL::MoveToNextEnglishChar() //将m_listXY加入到m_pMarker中,并将m_listXY清空 void ImportHPGL::AddPolylineToMarker() { + if(m_listXY.size() <= 0) + { + return; + } + //长度<0.2mm为钻孔 CRPPolyline RPPolyline1; QPoint pt1,pt2; @@ -679,15 +685,44 @@ void ImportHPGL::AddPolylineToMarker() } } m_listXY.clear(); + + return; } void ImportHPGL::AddPoint2listXY(QPoint ptPoint) { + double angle, sina, cosa; + double rcx, rcy; + + if(m_rotateAngle != 0) + { + angle = (m_rotateAngle * PI) / 180.0; + sina = (double)qSin(angle); + cosa = (double)qCos(angle); + } + if ((m_listXY.size() == 0) && (m_ptCurrentPos != ptPoint)) { + if(m_rotateAngle != 0) + { + rcx = (m_ptCurrentPos.x()*cosa - m_ptCurrentPos.y()*sina); + rcy = (m_ptCurrentPos.x()*sina + m_ptCurrentPos.y()*cosa); + + m_ptCurrentPos.setX(rcx); + m_ptCurrentPos.setY(rcy); + } m_listXY.append(m_ptCurrentPos); } + if(m_rotateAngle != 0) + { + rcx = (ptPoint.x()*cosa - ptPoint.y()*sina); + rcy = (ptPoint.x()*sina + ptPoint.y()*cosa); + + ptPoint.setX(rcx); + ptPoint.setY(rcy); + } + m_listXY.append(ptPoint); } @@ -1145,8 +1180,6 @@ bool ImportHPGL::ReadSecretFile(QString stePathName, Marker *pMarker) int notchOffsetX,notchOffsetY; notchOffsetX = notchOffsetY = 0; - IniPara(); - if (!file.open(QIODevice::ReadOnly)) { return false; @@ -1491,11 +1524,33 @@ bool ImportHPGL::ReadSecretFile(QString stePathName, Marker *pMarker) bitmapInfo.m_ptAbPostRD.setX(bitPost[6] + m_ptOrigin.x() + m_nLength); bitmapInfo.m_ptAbPostRD.setY(bitPost[7] + m_ptOrigin.y()); + //正向旋转90度 + if(m_rotateAngle != 0) + { + double angle,sina,cosa,rcx1,rcy1,rcx2,rcy2; + angle = (m_rotateAngle * PI) / 180.0; + sina = (double)qSin(angle); + cosa = (double)qCos(angle); + + rcx1 = (bitmapInfo.m_ptAbPostLD.x()*cosa - bitmapInfo.m_ptAbPostLD.y()*sina); + rcy1 = (bitmapInfo.m_ptAbPostLD.x()*sina + bitmapInfo.m_ptAbPostLD.y()*cosa); + bitmapInfo.m_ptAbPostLD.setX(rcx1); + bitmapInfo.m_ptAbPostLD.setY(rcy1); + bitmapInfo.m_ptAbPostLU = bitmapInfo.m_ptAbPostLD; + + rcx2 = (bitmapInfo.m_ptAbPostRU.x()*cosa - bitmapInfo.m_ptAbPostRU.y()*sina); + rcy2 = (bitmapInfo.m_ptAbPostRU.x()*sina + bitmapInfo.m_ptAbPostRU.y()*cosa); + bitmapInfo.m_ptAbPostRU.setX(rcx2); + bitmapInfo.m_ptAbPostRU.setY(rcy2); + bitmapInfo.m_ptAbPostRD = bitmapInfo.m_ptAbPostRU; + } + bitmapInfo.m_iTransparent = bitDispStyle[0]; bitmapInfo.m_iBKColor = bitDispStyle[1]; bitmapInfo.m_iWidth = bitGDIInfo[0]; bitmapInfo.m_iHeight = bitGDIInfo[1]; + bitmapInfo.m_iStride = bitGDIInfo[2]; bitmapInfo.m_iPixelFormat = bitGDIInfo[3]; @@ -1510,12 +1565,15 @@ bool ImportHPGL::ReadSecretFile(QString stePathName, Marker *pMarker) unBmpArr.append(pBmpData[nCount]); } QByteArray pUnCompressData; + pUnCompressData.clear(); //解压缩 // 文件路径 QDir apppath(qApp->applicationDirPath()); - QString zipPath = apppath.path(); - QString zipFile = stePathName + "bfile.zip"; + QFileInfo fileInfo(stePathName); + QString zipPath = fileInfo.absolutePath();//获取Secret.plt所在的目录 + QString cpstePathName = stePathName; + QString zipFile = cpstePathName.remove(cpstePathName.length()-3,3) + "zip"; QFile file(zipFile); if (!file.open(QIODevice::WriteOnly)) { @@ -1525,25 +1583,81 @@ bool ImportHPGL::ReadSecretFile(QString stePathName, Marker *pMarker) file.write(unBmpArr); file.close(); - QZipReader reader(zipFile); - if(!reader.exists()) + //判断zip文件是否存在 + if (!QFile::exists(zipFile)) { + qDebug() << "The zip file does not exist"; return false; } - reader.extractAll(zipFile); - //QVector list = reader.fileInfoList(); - QZipReader::FileInfo fileInfo = reader.entryInfoAt(0);//文件夹名称 - pUnCompressData = reader.fileData(fileInfo.filePath); + QZipReader reader(zipFile); + + //解压到当前unzipfile文件夹目录 + QString unzipPath = zipPath + apppath.separator() + "unzipfile"; + QDir unzipDir(unzipPath); + if(!unzipDir.exists()) + { + unzipDir.mkdir(unzipPath); + } + if (!reader.extractAll(unzipPath)) + { + qDebug() << "Failed to extract all files from the zip."; + return false; + } reader.close(); - // bitmapInfo.m_pBitmap = plotBitmap.Create1BPPBitmap(bitmapInfo.m_iTransparent,bitmapInfo.m_iBKColor,bitmapInfo.m_iWidth,bitmapInfo.m_iHeight, - // bitmapInfo.m_iStride,bitmapInfo.m_iPixelFormat, pUnCompressData.data()); + unzipDir.setFilter(QDir::Files | QDir::NoDotAndDotDot); //设置过滤 + QFileInfoList fileList = unzipDir.entryInfoList(); // 获取所有的文件信息 + + QString unzipFilePath; + foreach (QFileInfo file, fileList) + { + if (file.isFile()) + { + // 解压的文件 + unzipFilePath = file.filePath(); + QFile uncompressedFile(unzipFilePath); + if (!uncompressedFile.open(QIODevice::ReadOnly)) + { + qDebug() << "Failed to open the uncompressedFile file"; + return false; + } + + pUnCompressData = uncompressedFile.readAll(); + uncompressedFile.close(); + break; + } + } + + if(pUnCompressData.length() <= 0) + { + qDebug() << "pUnCompressData.length() <= 0"; + return false; + } + +// bitmapInfo.m_pBitmap = plotBitmap.Create1BPPBitmap(bitmapInfo.m_iTransparent,bitmapInfo.m_iBKColor,bitmapInfo.m_iWidth,bitmapInfo.m_iHeight, +// bitmapInfo.m_iStride,bitmapInfo.m_iPixelFormat, pUnCompressData.data()); bitmapInfo.m_pBitmap = plotBitmap.Create1BPPBitmap(bitmapInfo.m_iWidth,bitmapInfo.m_iHeight, (unsigned char*)pUnCompressData.data()); - QString reStr = zipPath + apppath.separator() + fileInfo.filePath; - QFile::remove(reStr); + + //正向旋转90度 + if(m_rotateAngle != 0) + { + QImage rotatedBitmap = bitmapInfo.m_pBitmap.toImage().transformed(QTransform().rotate(90)); + // 将旋转后的QImage转换回QBitmap + QBitmap rotatedBitmapQt(bitmapInfo.m_pBitmap.height(),bitmapInfo.m_pBitmap.width()); + rotatedBitmapQt.fill(Qt::color0); + QPainter painter(&rotatedBitmapQt); + painter.drawPixmap(0, 0, QPixmap::fromImage(rotatedBitmap)); + painter.end(); + bitmapInfo.m_pBitmap = rotatedBitmapQt; + //rotatedBitmap.save("D:\\1.bmp"); + } + + QFile::remove(stePathName); QFile::remove(zipFile); + QFile::remove(unzipFilePath); + delete pBmpData; RPPolyline.m_nDrawingType = 1; @@ -1650,6 +1764,20 @@ bool ImportHPGL::ReadSecretFile(QString stePathName, Marker *pMarker) //qrPixmap.save("D:\\1.bmp"); bitmapInfo.m_pBitmap = qrPixmap; + //正向旋转90度 + if(m_rotateAngle != 0) + { + QImage rotatedBitmap = bitmapInfo.m_pBitmap.toImage().transformed(QTransform().rotate(90)); + // 将旋转后的QImage转换回QBitmap + QBitmap rotatedBitmapQt(bitmapInfo.m_pBitmap.height(),bitmapInfo.m_pBitmap.width()); + rotatedBitmapQt.fill(Qt::color0); + QPainter painter(&rotatedBitmapQt); + painter.drawPixmap(0, 0, QPixmap::fromImage(rotatedBitmap)); + painter.end(); + bitmapInfo.m_pBitmap = rotatedBitmapQt; + //rotatedBitmap.save("D:\\1.bmp"); + } + if (code.m_nSizeY <= code.m_nSizeX) { nPixelsDot = (int)((double)code.m_nSizeY / (double)pCode->width + 0.5); @@ -1687,6 +1815,26 @@ bool ImportHPGL::ReadSecretFile(QString stePathName, Marker *pMarker) bitmapInfo.m_ptAbPostRD.setX(bitmapInfo.m_ptPostRD.x() + m_ptOrigin.x() + m_nLength); bitmapInfo.m_ptAbPostRD.setY(bitmapInfo.m_ptPostRD.y() + m_ptOrigin.y()); + if(m_rotateAngle != 0) + { + double angle,sina,cosa,rcx1,rcy1,rcx2,rcy2; + angle = (m_rotateAngle * PI) / 180.0; + sina = (double)qSin(angle); + cosa = (double)qCos(angle); + + rcx1 = (bitmapInfo.m_ptAbPostLD.x()*cosa - bitmapInfo.m_ptAbPostLD.y()*sina); + rcy1 = (bitmapInfo.m_ptAbPostLD.x()*sina + bitmapInfo.m_ptAbPostLD.y()*cosa); + bitmapInfo.m_ptAbPostLD.setX(rcx1); + bitmapInfo.m_ptAbPostLD.setY(rcy1); + bitmapInfo.m_ptAbPostLU = bitmapInfo.m_ptAbPostLD; + + rcx2 = (bitmapInfo.m_ptAbPostRU.x()*cosa - bitmapInfo.m_ptAbPostRU.y()*sina); + rcy2 = (bitmapInfo.m_ptAbPostRU.x()*sina + bitmapInfo.m_ptAbPostRU.y()*cosa); + bitmapInfo.m_ptAbPostRU.setX(rcx2); + bitmapInfo.m_ptAbPostRU.setY(rcy2); + bitmapInfo.m_ptAbPostRD = bitmapInfo.m_ptAbPostRU; + } + bitmapInfo.m_iTransparent = 0; bitmapInfo.m_iBKColor = qRgb(255,255,255); @@ -2079,8 +2227,6 @@ bool ImportHPGL::L_Code() connect(&vectorFont, SIGNAL(siLineTo(bool,QPoint)), this, SLOT(AddTextPointToLine(bool,QPoint))); connect(&vectorFont, SIGNAL(siMoveTo(bool,QPoint)), this, SLOT(AddTextPointToLine(bool,QPoint))); - CRPPolyline crppolylineTemp; - bOk=GetChar(&cCh1); if (bOk) { @@ -2094,6 +2240,8 @@ bool ImportHPGL::L_Code() break; case 'B': case 'b': + { + CRPPolyline crppolylineTemp; AddPolylineToMarker(); bOk = SearchChar(m_chTerminator,strText); m_ptCurrentPos = GetTextOrigin(m_ptCurrentPos,strText); @@ -2118,7 +2266,7 @@ bool ImportHPGL::L_Code() //qDebug()<m_listPolyline.append(crppolylineTemp);//用文本方法绘制 - + } break; case 'O': case 'o': diff --git a/datafile/hpgl/importhpgl.h b/datafile/hpgl/importhpgl.h index 2fb6b28..fed9d9b 100644 --- a/datafile/hpgl/importhpgl.h +++ b/datafile/hpgl/importhpgl.h @@ -13,13 +13,14 @@ #include #include #include +#include #include "marker.h" #include "plotbitmap.h" #include "QtGui/private/qzipreader_p.h" //#include "QtGui/private/qzipwriter_p.h" #include "datafile/qrencode/qrencode.h" -#define DEFCMD_IN 0x8A //IN +#define DEFCMD_IN 0x8A //IN #define DEFCMD_SP 0x7C //SP #define DEFCMD_LT 0xE6 //LT 0:PS_SOLID; 1:PS_DASH; 2:PS_DOT; 3:PS_DASHDOT #define DEFCMD_PG 0x97 //PG @@ -50,6 +51,8 @@ #define PixelFormatGDI 0x00020000 // Is a GDI-supported format #define PixelFormat1bppIndexed (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI) +#pragma pack(1) //设定为1字节对齐 + struct SC { double dXMin; @@ -205,6 +208,7 @@ protected: Marker *m_pMarker; //当前使用的唛架,仅能在读文件时使用 double m_dScale; //读入文件时将切割数据文件的单位转换成内部数据单位时的比例 + double m_rotateAngle;//旋转角度 QPen m_penPen;//笔绘画笔 QPen m_cutPen;//切割画笔 QPen m_halfCutPen;//半透切割画笔 @@ -250,6 +254,7 @@ public: //初始化参数,读取参数前,需将参数值重置,避免造成参数值读取错误 void IniPara(); + inline void setRotateAngle(double angle){m_rotateAngle = angle;} QPoint GetTextOrigin(QPoint pt,QString strText); double GetTextAngle(double dX,double dY); diff --git a/datafile/hpgl/marker.h b/datafile/hpgl/marker.h index f1ce10d..03a5e00 100644 --- a/datafile/hpgl/marker.h +++ b/datafile/hpgl/marker.h @@ -12,6 +12,8 @@ #define CONST_PI 3.14159265359 +#pragma pack(1) //设定为1字节对齐 + struct LineType { //具体参照HPGL英文版手册216页 当LT没有设置值时,线型为实线 @@ -21,7 +23,6 @@ struct LineType int nMode;//0相对模式 缺省值 解释为P1、P2距离的百分比 1绝对模式,以毫米解释图案长度 }; - class CBitmapInfo { public: diff --git a/datafile/hpgl/plotbitmap.cpp b/datafile/hpgl/plotbitmap.cpp index ff441ad..243e7ba 100644 --- a/datafile/hpgl/plotbitmap.cpp +++ b/datafile/hpgl/plotbitmap.cpp @@ -18,7 +18,7 @@ QBitmap PlotBitmap::Create1BPPBitmap(int iWidth,int iHeight,unsigned char *pBmp pen.setColor(QColor(Qt::black)); //QImage::Format_RGBA8888 代表彩色图 - QImage image = QImage(pBmpData, iWidth, iHeight, QImage::Format_RGBA8888); + QImage image = QImage(pBmpData, iWidth, iHeight,QImage::Format_RGBA8888); //image.save("D:\\1.png"); QBitmap pixmap = QBitmap(iWidth,iHeight); diff --git a/datafile/hpgl/vectorfont.cpp b/datafile/hpgl/vectorfont.cpp index e9befaf..4a10944 100644 --- a/datafile/hpgl/vectorfont.cpp +++ b/datafile/hpgl/vectorfont.cpp @@ -118,7 +118,6 @@ void VectorFont::IniVectorFont() Chinese_char1.m_wBytes=(WORD)byte[2] | ((WORD)byte[3] << 8); Chinese_char1.m_dwPosition=(DWORD)byte[4] | ((DWORD)byte[5] << 8) | ((DWORD)byte[6] << 16) | ((DWORD)byte[7] << 24); - m_pChinese_char[nCharCount_C-nCountChar] = Chinese_char1; //m_aChinese_char.append(Chinese_char1); nCountChar--; @@ -129,7 +128,6 @@ void VectorFont::IniVectorFont() m_dFontHeight = 0.375 * 10 * m_iDPMM; } - //输入参数: // ptPointLU 显示字符串的左上角坐标(即TextOut(...)的x,y值) // pbyData 字符的描述数据 @@ -411,12 +409,15 @@ void VectorFont::PlotChar(QPoint ptPointLU,BYTE *pbyData,WORD wBytes,int nLeft,i if (bPenUp) MoveTo(ptPoint1); else LineTo(ptPoint1); } - else { - if (bClockwise) { + else + { + if (bClockwise) + { dx2=-dy1; dy2=dx1; } - else { + else + { dx2=dy1; dy2=-dx1; } @@ -459,10 +460,12 @@ void VectorFont::PlotChar(QPoint ptPointLU,BYTE *pbyData,WORD wBytes,int nLeft,i bVerTextCommand=false; break; case 0xD: - if (bVerTextCommand) { + if (bVerTextCommand) + { wIndex1=wIndex1+4; } - else { + else + { wIndex1++; while ((pbyData[wIndex1] != 0) || (pbyData[wIndex1+1] != 0)) { dx1=(double)((char)pbyData[wIndex1]) * (double)nFontScale; @@ -476,7 +479,8 @@ void VectorFont::PlotChar(QPoint ptPointLU,BYTE *pbyData,WORD wBytes,int nLeft,i dD=sqrt(dx1*dx1 + dy1*dy1); dH=fabs(dBulge) * dD / 127.0 / 2.0; - if (((char)pbyData[wIndex1]) == 0) { + if (((char)pbyData[wIndex1]) == 0) + { ptCurrentPos.setX(ptCurrentPos.x() + (int)dx1); ptCurrentPos.setY(ptCurrentPos.y() - (int)dy1); ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale); @@ -486,12 +490,15 @@ void VectorFont::PlotChar(QPoint ptPointLU,BYTE *pbyData,WORD wBytes,int nLeft,i else LineTo(ptPoint1); } - else { - if (bClockwise) { + else + { + if (bClockwise) + { dx2=-dy1; dy2=dx1; } - else { + else + { dx2=dy1; dy2=-dx1; } @@ -571,6 +578,7 @@ QPoint VectorFont::CPToLP(QPoint ptCP,int nHeight,QPoint ptPointLU,double dSin,d return ptPoint1; } + //抬笔移动到点(x,y) void VectorFont::MoveTo(long x, long y) { @@ -584,7 +592,6 @@ void VectorFont::MoveTo(QPoint ptPoint) emit siMoveTo(true,ptPoint); } - //从当前位置画线到点(x,y), void VectorFont::LineTo(long x, long y) { @@ -732,6 +739,7 @@ void VectorFont::TextOutString(int x, int y, const char* lpszString, int nCount) fileEnglish.close(); fileChinese.close(); } + //画弧,从Start逆时针画到End void VectorFont::Arc(int nLeftRect,int nTopRect,int nRightRect,int nBottomRect, int nXStartArc,int nYStartArc,int nXEndArc,int nYEndArc) @@ -775,14 +783,14 @@ void VectorFont::Arc(int nLeftRect,int nTopRect,int nRightRect,int nBottomRect, dy=dRadius * dSin + dYC; LineTo(dx+0.5,dy+0.5); } - } QPoint VectorFont::GetNextCoodinate(WORD wDirection,WORD wLength,QPoint ptPoint) { QPoint ptPoint1; - switch (wDirection) { + switch (wDirection) + { case 0: ptPoint1.setX( ptPoint.x() + (int)wLength); ptPoint1.setY(ptPoint.y()); diff --git a/datafile/view/drawdata.cpp b/datafile/view/drawdata.cpp new file mode 100644 index 0000000..7852518 --- /dev/null +++ b/datafile/view/drawdata.cpp @@ -0,0 +1,183 @@ +#include "drawdata.h" + +QPicture creatPictureByData(Marker marker, QPainterPath &painterPath, int penWidth) +{ + CBitmapInfo bitmapInfo; + QRect rect = marker.GetRect(); + int minX = rect.left(); + int maxY = rect.bottom(); + + int nLineCount = marker.m_listPolyline.size(); + for(int i = 0; i < nLineCount; i++) + { + CRPPolyline polyLine = marker.m_listPolyline.at(i); + int type = polyLine.m_nDrawingType; + // if(polyLine.m_nDrawingType == 3)//文字 + // { + // CRPText text = polyLine->m_text; + // } + + if(type == 0)//直线 + { + int nPointCount = polyLine.m_listPoint.size(); + for(int j = 0; j < nPointCount; j++) + { + double x = (polyLine.m_listPoint.at(j).x() - minX)/(double)M_IDPMM*MMPIXELY; + double y = (maxY - polyLine.m_listPoint.at(j).y())/(double)M_IDPMM*MMPIXELY; + QPointF point(x,y); + + if(j == 0) + { + painterPath.moveTo(point); + } + else + { + painterPath.lineTo(point); + } + } + } + else if(type == 1)//位图 + { + bitmapInfo = polyLine.m_bitmapInfo; + + int lux = bitmapInfo.m_ptAbPostLU.x(); + int luy = bitmapInfo.m_ptAbPostLU.y(); + int nlux = (lux - minX)/M_IDPMM*MMPIXELY; + int nluy = (maxY-luy)/M_IDPMM*MMPIXELY; + bitmapInfo.m_ptAbPostLU.setX(nlux); + bitmapInfo.m_ptAbPostLU.setY(nluy); + + int rdx = bitmapInfo.m_ptAbPostRD.x(); + int rdy = bitmapInfo.m_ptAbPostRD.y(); + int nrdx = (rdx - minX)/M_IDPMM*MMPIXELY; + int nrdy = (maxY-rdy)/M_IDPMM*MMPIXELY; + bitmapInfo.m_ptAbPostRD.setX(nrdx); + bitmapInfo.m_ptAbPostRD.setY(nrdy); + } + } + + if(painterPath.isEmpty()) + { + qDebug()<<"painterPath.isEmpty"; + } + + //将路径画在picture上 + QPicture pic; + QPen pen(Qt::black, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin); + //pen.setCosmetic(true); // 对于固定宽度的笔划很有用 + + QPainter painter; + painter.begin(&pic); + painter.setPen(pen); + painter.drawPath(painterPath); + if(bitmapInfo.m_iBytes > 0)//有位图 + { + int startx = bitmapInfo.m_ptAbPostLU.x(); + int starty = bitmapInfo.m_ptAbPostLU.y(); + //bitmapInfo.m_pBitmap.save("D:\\1.bmp"); + int targetWidth = abs(bitmapInfo.m_ptAbPostRD.x() - bitmapInfo.m_ptAbPostLU.x()); + int targetHeight = abs(bitmapInfo.m_ptAbPostRD.y() - bitmapInfo.m_ptAbPostLU.y()); + painter.drawPixmap(startx,starty,targetWidth,targetHeight,bitmapInfo.m_pBitmap, + startx,starty, bitmapInfo.m_pBitmap.width(), bitmapInfo.m_pBitmap.height()); +// painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap); + } + painter.end(); + return pic; +} + +QPicture creatPictureByBmp(QPixmap pixmap,int penWidth) +{ + //将图片画在picture上 + QPicture pic; + QPen pen; + pen.setWidth(penWidth);//设置笔号 + pen.setColor(QColor(Qt::black)); + + QPainter painter; + painter.begin(&pic); + painter.setPen(pen); + painter.drawPixmap(0,0,pixmap); + painter.end(); + return pic; +} + +void creatMarkerDat(McFilesInfo &curFilesInfo, QString printDir, QString filePath, int fileIdx, double angle) +{ + QFileInfo fileInfo(filePath); + curFilesInfo.m_marker.Initialize(); + + if(fileInfo.suffix().toUpper() == "DXF") + { + DxfHelper dxfHelper; + if(dxfHelper.generateDxf(filePath)) + { + dxfHelper.getDxfPaths(); // 获取转换出来的dxf所有类型图形的点集 + QImage img = dxfHelper.generateDXFImage(); // 获取预览图像 + img.save("D:\\1.png"); + } + } + else if(fileInfo.suffix().toUpper() == "PLT") + { + ImportHPGL importHPGL; + curFilesInfo.m_fileType = TYPE_FILE; + + //判断是否为加密文件 + if (importHPGL.IsSecretFile(filePath) == true) + { + QString strSecretFile; + if(fileIdx == -1) + { + // 文件路径 + QDir apppath(qApp->applicationDirPath()); + strSecretFile = apppath.path() + apppath.separator() + "Secret.plt"; + } + else + { + // 文件路径 + strSecretFile = printDir + QString::number(fileIdx+1) ; + + QDir fileDir(strSecretFile);//对应每台机器的每个文件打印目录 + if(!fileDir.exists()) + { + fileDir.mkdir(strSecretFile); + } + strSecretFile = strSecretFile + fileDir.separator() + "Secret.plt"; + } + //qDebug()<<"strSecretFile"< +#include "datafile/dxf/dxfhelper.h" +#include "datafile/hpgl/importhpgl.h" +#include "machine/printinfo/mcfiles.h" + +#define TYPE_FILE 0 +#define TYPE_IMAGE 1 + +QPicture creatPictureByData(Marker marker, QPainterPath &painterPath,int penWidth = 1); +QPicture creatPictureByBmp(QPixmap pixmap,int penWidth = 1); +void creatMarkerDat(McFilesInfo &curFilesInfo, QString printDir, QString filePath, int fileIdx = -1, double angle = 0);//创建Marker数据 + +#endif // DRAWDATA_H diff --git a/datafile/view/mygraphicsitem.cpp b/datafile/view/mygraphicsitem.cpp index 888fe8a..fb7349a 100644 --- a/datafile/view/mygraphicsitem.cpp +++ b/datafile/view/mygraphicsitem.cpp @@ -4,6 +4,7 @@ MyGraphicsItem::MyGraphicsItem() { m_point.setX(0); m_point.setY(0); + m_fileType = TYPE_FILE; //使item可以被选择 //this->setFlag(QGraphicsItem::ItemIsSelectable); @@ -32,89 +33,58 @@ void MyGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) return QGraphicsItem::mouseReleaseEvent(event); } -QPicture MyGraphicsItem::getPicture(Marker marker,int penWidth) +QPicture MyGraphicsItem::getPictureByDat(Marker marker,int penWidth) { + m_fileType = TYPE_FILE; if(penWidth != 1) { QPicture pic; - CBitmapInfo bitmapInfo; - QPainterPath painterPath; - QRect rect = marker.GetRect(); - int minX = rect.left(); - int minY = rect.top(); - int maxY = rect.bottom(); - - int nLineCount = marker.m_listPolyline.size(); - for(int i = 0; i < nLineCount; i++) - { - CRPPolyline polyLine = marker.m_listPolyline.at(i); - int type = polyLine.m_nDrawingType; - - if(type == 0)//直线 - { - int nPointCount = polyLine.m_listPoint.size(); - for(int j = 0; j < nPointCount; j++) - { - double x = (polyLine.m_listPoint.at(j).x() - minX)/(double)M_IDPMM*MMPIXELY; - double y = ((0 - (polyLine.m_listPoint.at(j).y() - minY))+(maxY-minY))/(double)M_IDPMM*MMPIXELY; - QPointF point(x,y); - - if(j == 0) - { - painterPath.moveTo(point); - } - else - { - painterPath.lineTo(point); - } - } - } - else if(type == 1)//位图 - { - bitmapInfo = polyLine.m_bitmapInfo; - int x = bitmapInfo.m_ptAbPostLU.x(); - int y = bitmapInfo.m_ptAbPostLU.y(); - - int nx = (x - minX)/M_IDPMM*MMPIXELY; - int ny = ((0 - (y - minY))+(maxY-minY))/M_IDPMM*MMPIXELY; - - bitmapInfo.m_ptAbPostLU.setX(nx); - bitmapInfo.m_ptAbPostLU.setY(ny); - } - } - - if(painterPath.isEmpty()) - { - qDebug()<<"painterPath isEmpty"; - } - - //将路径画在picture上 - QPen pen; - pen.setWidth(penWidth);//设置笔号 - pen.setColor(QColor(Qt::black)); - - QPainter painter; - painter.begin(&pic); - painter.setPen(pen); - painter.drawPath(painterPath); - if(bitmapInfo.m_iBytes > 0)//有位图 - { - painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap); - } - painter.end(); + pic = creatPictureByData(marker,m_drawPath,penWidth); + m_boundingRect = pic.boundingRect(); return pic; } return m_picture; } +QPicture MyGraphicsItem::getPictureByBmp(QPixmap pixmap,int penWidth) +{ + m_fileType = TYPE_IMAGE; + m_picture = creatPictureByBmp(pixmap,penWidth); + m_boundingRect = m_picture.boundingRect(); + return m_picture; +} + +QPainterPath MyGraphicsItem::getDrawPath() +{ + return m_drawPath; +} + void MyGraphicsItem::setPicture(QPicture pic) { + m_fileType = TYPE_IMAGE; m_picture = pic; // 外矩形 m_boundingRect = m_picture.boundingRect(); update(); } +void MyGraphicsItem::setPaintPath(QPainterPath path) +{ + m_fileType = TYPE_FILE; + m_drawPath = path; + m_boundingRect = m_drawPath.boundingRect(); + update(); +} + +void MyGraphicsItem::setPaintPathAndPic(QPainterPath path, QPicture pic) +{ + m_fileType = TYPE_FILE; + m_drawPath = path; + m_picture = pic; + m_boundingRect = m_drawPath.boundingRect(); + update(); +} + void MyGraphicsItem::reflushBlockPos(QPoint p) { m_point = p; @@ -145,7 +115,12 @@ void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op QBrush brush; brush.setStyle(Qt::SolidPattern); pen.setWidth(1); - double scaleFactor = painter->matrix().m11(); + + // 获取当前的变换矩阵 + QTransform transform = painter->worldTransform(); + double scaleFactor = std::sqrt(transform.m11() * transform.m11() + + transform.m22() * transform.m22()); + double width = pen.width()/scaleFactor; pen.setWidthF(width); // 线段保持原来的线宽 pen.setColor(QColor(Qt::black)); @@ -158,104 +133,15 @@ void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op // painter->setRenderHint(QPainter::Antialiasing, true); // painter->setRenderHint(QPainter::SmoothPixmapTransform, true); - painter->drawPicture(0,0,m_picture); + //用MyGraphicsItem画图缩放时如果笔宽不为1,直接画QPicture时线条会很轻,所以用m_drawPath绘制,pic就为原笔宽pic + //文件类型用m_drawPath,图片类型为m_picture + if(m_fileType == TYPE_FILE) + { + painter->drawPath(m_drawPath); + } + else if(m_fileType == TYPE_IMAGE) + { + painter->drawPicture(0,0,m_picture); + } painter->drawPixmap(m_point.x(),m_point.y(),m_blockPixmap); } - -void MyGraphicsItem::creatPicture(Marker marker) -{ - CBitmapInfo bitmapInfo; - QPainterPath painterPath; - QRect rect = marker.GetRect(); - int minX = rect.left(); - int minY = rect.top(); - int maxY = rect.bottom(); - - int nLineCount = marker.m_listPolyline.size(); - for(int i = 0; i < nLineCount; i++) - { - CRPPolyline polyLine = marker.m_listPolyline.at(i); - int type = polyLine.m_nDrawingType; - // if(polyLine.m_nDrawingType == 3)//文字 - // { - // CRPText text = polyLine.m_text; - // } - - if(type == 0)//直线 - { - int nPointCount = polyLine.m_listPoint.size(); - for(int j = 0; j < nPointCount; j++) - { - double x = (polyLine.m_listPoint.at(j).x() - minX)/(double)M_IDPMM*MMPIXELY; - double y = ((0 - (polyLine.m_listPoint.at(j).y() - minY))+(maxY-minY))/(double)M_IDPMM*MMPIXELY; - QPointF point(x,y); - - if(j == 0) - { - painterPath.moveTo(point); - } - else - { - painterPath.lineTo(point); - } - } - } - else if(type == 1)//位图 - { - bitmapInfo = polyLine.m_bitmapInfo; - int x = bitmapInfo.m_ptAbPostLU.x(); - int y = bitmapInfo.m_ptAbPostLU.y(); - - int nx = (x - minX)/M_IDPMM*MMPIXELY; - int ny = ((0 - (y - minY))+(maxY-minY))/M_IDPMM*MMPIXELY; - - bitmapInfo.m_ptAbPostLU.setX(nx); - bitmapInfo.m_ptAbPostLU.setY(ny); - } - } - - if(painterPath.isEmpty()) - { - qDebug()<<"painterPath.isEmpty"; - } - - //将路径画在picture上 - QPicture pic; - QPen pen; - pen.setWidth(1);//设置笔号 - pen.setColor(QColor(Qt::black)); - - QPainter painter; - painter.begin(&pic); - painter.setPen(pen); - painter.drawPath(painterPath); - if(bitmapInfo.m_iBytes > 0)//有位图 - { - //bitmapInfo.m_pBitmap.save("D:\\1.bmp"); - painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap); - } - painter.end(); - m_picture = pic; - - // 外矩形 - m_boundingRect = m_picture.boundingRect(); -} - -void MyGraphicsItem::creatPicture(QPixmap pixmap) -{ - //将图片画在picture上 - QPicture pic; - QPen pen; - pen.setWidth(1);//设置笔号 - pen.setColor(QColor(Qt::black)); - - QPainter painter; - painter.begin(&pic); - painter.setPen(pen); - painter.drawPixmap(0,0,pixmap); - painter.end(); - m_picture = pic; - - // 外矩形 - m_boundingRect = m_picture.boundingRect(); -} diff --git a/datafile/view/mygraphicsitem.h b/datafile/view/mygraphicsitem.h index a86915e..3d994b4 100644 --- a/datafile/view/mygraphicsitem.h +++ b/datafile/view/mygraphicsitem.h @@ -11,7 +11,7 @@ #include #include #include "machine/bmp/creatprintbmp.h" -#include "datafile/hpgl/importhpgl.h" +#include "datafile/view/drawdata.h" class MyGraphicsItem : public QObject, public QGraphicsItem { @@ -29,9 +29,6 @@ public: const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - void creatPicture(Marker marker); - void creatPicture(QPixmap pixmap); - protected: //事件 void mousePressEvent(QGraphicsSceneMouseEvent* event); void mouseMoveEvent(QGraphicsSceneMouseEvent* event); @@ -39,13 +36,19 @@ protected: //事件 private: QPicture m_picture; + QPainterPath m_drawPath; QPixmap m_blockPixmap; QPoint m_point; QRectF m_boundingRect;//返回形状 + int m_fileType; public: - QPicture getPicture(Marker marker,int penWidth = 1); + QPicture getPictureByDat(Marker marker,int penWidth = 1); + QPicture getPictureByBmp(QPixmap pixmap,int penWidth = 1); + QPainterPath getDrawPath(); void setPicture(QPicture pic); + void setPaintPath(QPainterPath path); + void setPaintPathAndPic(QPainterPath path,QPicture pic); void reflushBlockPos(QPoint p);//更显打印块位置 public slots: diff --git a/datafile/view/mygraphicsscene.cpp b/datafile/view/mygraphicsscene.cpp index e12bbf2..39dccc4 100644 --- a/datafile/view/mygraphicsscene.cpp +++ b/datafile/view/mygraphicsscene.cpp @@ -29,19 +29,18 @@ void MyGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) return QGraphicsScene::mouseReleaseEvent(mouseEvent); } -void MyGraphicsScene::createScene(Marker marker) +void MyGraphicsScene::createScenePathAndPic(QPainterPath path, QPicture pic) { - m_myGraphicsItem->creatPicture(marker); - //绘制留边 - this->setSceneRect(0,0,m_myGraphicsItem->boundingRect().width()+DRAWMARGINS,m_myGraphicsItem->boundingRect().height()+DRAWMARGINS); - //如果scene未超过graphicsView的范围,图形就是居中显示的 - this->addItem(m_myGraphicsItem); - m_myGraphicsItem->moveBy(DRAWMARGINS/2.0,DRAWMARGINS/2.0);//item居中显示 + if(m_myGraphicsItem != NULL) + { + this->clear(); + m_myGraphicsItem->setPaintPathAndPic(path,pic); + this->addItem(m_myGraphicsItem); + } } -void MyGraphicsScene::createScene(QPixmap pixmap) +void MyGraphicsScene::addItemToScene() { - m_myGraphicsItem->creatPicture(pixmap); //绘制留边 this->setSceneRect(0,0,m_myGraphicsItem->boundingRect().width()+DRAWMARGINS,m_myGraphicsItem->boundingRect().height()+DRAWMARGINS); //如果scene未超过graphicsView的范围,图形就是居中显示的 @@ -57,25 +56,56 @@ void MyGraphicsScene::cleanScene() } } -QPicture MyGraphicsScene::getPicture(Marker marker,int penWidth) +QPicture MyGraphicsScene::getPictureByDat(Marker marker,int penWidth) { QPicture pic; if(m_myGraphicsItem != NULL) { - pic = m_myGraphicsItem->getPicture(marker,penWidth); + pic = m_myGraphicsItem->getPictureByDat(marker,penWidth); } return pic; } -void MyGraphicsScene::swithScene(QPicture pic) +QPicture MyGraphicsScene::getPictureByBmp(QPixmap pixmap,int penWidth) +{ + QPicture pic; + if(m_myGraphicsItem != NULL) + { + pic = m_myGraphicsItem->getPictureByBmp(pixmap,penWidth); + } + return pic; +} + +QPainterPath MyGraphicsScene::getDrawPath() +{ + QPainterPath path; + if(m_myGraphicsItem != NULL) + { + path = m_myGraphicsItem->getDrawPath(); + } + return path; +} + +void MyGraphicsScene::swithSceneByPic(QPicture pic) { if(m_myGraphicsItem != NULL) { + this->clear(); m_myGraphicsItem->setPicture(pic); this->addItem(m_myGraphicsItem); } } +void MyGraphicsScene::swithSceneByPath(QPainterPath path) +{ + if(m_myGraphicsItem != NULL) + { + this->clear(); + m_myGraphicsItem->setPaintPath(path); + this->addItem(m_myGraphicsItem); + } +} + void MyGraphicsScene::ReflushBlockScene(QPoint p) { if(m_myGraphicsItem != NULL) diff --git a/datafile/view/mygraphicsscene.h b/datafile/view/mygraphicsscene.h index 17c37c8..d5758a3 100644 --- a/datafile/view/mygraphicsscene.h +++ b/datafile/view/mygraphicsscene.h @@ -23,11 +23,14 @@ private: MyGraphicsItem *m_myGraphicsItem; public: - void createScene(Marker marker); - void createScene(QPixmap pixmap); + void createScenePathAndPic(QPainterPath path,QPicture pic); + void addItemToScene(); void cleanScene(); - QPicture getPicture(Marker marker,int penWidth = 1); - void swithScene(QPicture pic); + QPicture getPictureByDat(Marker marker,int penWidth = 1); + QPicture getPictureByBmp(QPixmap pixmap,int penWidth = 1); + QPainterPath getDrawPath(); + void swithSceneByPic(QPicture pic); + void swithSceneByPath(QPainterPath path); void ReflushBlockScene(QPoint p); signals: diff --git a/datafile/view/mygraphicsview.cpp b/datafile/view/mygraphicsview.cpp index 07bb8be..c0e875c 100644 --- a/datafile/view/mygraphicsview.cpp +++ b/datafile/view/mygraphicsview.cpp @@ -120,8 +120,12 @@ void MyGraphicsView::mouseMoveEvent(QMouseEvent *event) QPoint viewPoint = event->pos(); //QGraphicsScene坐标 QPointF scenePoint = mapToScene(viewPoint); - double x = scenePoint.x() / MMPIXELY; - double y = abs(abs(scenePoint.y()) - m_scene->itemsBoundingRect().height()) / MMPIXELY; +// double x = scenePoint.x() / MMPIXELY; +// double y = abs(abs(scenePoint.y()) - m_scene->itemsBoundingRect().height()) / MMPIXELY; + + double x = (scenePoint.x() - DRAWMARGINS/2.0) / MMPIXELY; + double y = (m_scene->itemsBoundingRect().height() - scenePoint.y() + DRAWMARGINS/2.0) / MMPIXELY; + scenePoint.setX(x); scenePoint.setY(y); setMouseTracking(true); @@ -179,31 +183,47 @@ void MyGraphicsView::wheelEvent(QWheelEvent *event) verticalScrollBar()->setValue(int(viewPoint.y() - viewHeight * vScale)); } -QPicture MyGraphicsView::getPicture(Marker marker,int penWidth) +QPicture MyGraphicsView::getPictureByDat(Marker marker,int penWidth) { QPicture pic; if(m_scene != NULL) { - pic = m_scene->getPicture(marker,penWidth); + pic = m_scene->getPictureByDat(marker,penWidth); + m_scene->addItemToScene(); + QRectF rectItem = m_scene->itemsBoundingRect(); + this->fitInView(rectItem, Qt::KeepAspectRatio); } return pic; } -void MyGraphicsView::creatView(Marker marker) +QPicture MyGraphicsView::getPictureByBmp(QPixmap pixmap,int penWidth) { + QPicture pic; if(m_scene != NULL) { - m_scene->createScene(marker); + pic = m_scene->getPictureByBmp(pixmap,penWidth); + m_scene->addItemToScene(); QRectF rectItem = m_scene->itemsBoundingRect(); this->fitInView(rectItem, Qt::KeepAspectRatio); } + return pic; } -void MyGraphicsView::creatView(QPixmap pixmap) +QPainterPath MyGraphicsView::getDrawPath() +{ + QPainterPath path; + if(m_scene != NULL) + { + path = m_scene->getDrawPath(); + } + return path; +} + +void MyGraphicsView::creatViewPathAndPic(QPainterPath path,QPicture pic) { if(m_scene != NULL) { - m_scene->createScene(pixmap); + m_scene->createScenePathAndPic(path,pic); QRectF rectItem = m_scene->itemsBoundingRect(); this->fitInView(rectItem, Qt::KeepAspectRatio); } @@ -221,11 +241,21 @@ void MyGraphicsView::cleanView() } } -void MyGraphicsView::swithView(QPicture pic) +void MyGraphicsView::swithViewByPic(QPicture pic) { if(m_scene != NULL) { - m_scene->swithScene(pic); + m_scene->swithSceneByPic(pic); + QRectF rectItem = m_scene->itemsBoundingRect(); + this->fitInView(rectItem, Qt::KeepAspectRatio); + } +} + +void MyGraphicsView::swithViewByPath(QPainterPath path) +{ + if(m_scene != NULL) + { + m_scene->swithSceneByPath(path); QRectF rectItem = m_scene->itemsBoundingRect(); this->fitInView(rectItem, Qt::KeepAspectRatio); } diff --git a/datafile/view/mygraphicsview.h b/datafile/view/mygraphicsview.h index 375de9e..5292c96 100644 --- a/datafile/view/mygraphicsview.h +++ b/datafile/view/mygraphicsview.h @@ -34,11 +34,13 @@ protected: void wheelEvent(QWheelEvent *event); public: - QPicture getPicture(Marker marker,int penWidth = 1); - void creatView(Marker marker); - void creatView(QPixmap pixmap); + QPicture getPictureByDat(Marker marker,int penWidth = 1); + QPicture getPictureByBmp(QPixmap pixmap,int penWidth = 1); + QPainterPath getDrawPath(); + void creatViewPathAndPic(QPainterPath path,QPicture pic); void cleanView(); - void swithView(QPicture pic); + void swithViewByPic(QPicture pic); + void swithViewByPath(QPainterPath path); void reflushBlockView(QPoint p); signals: diff --git a/drawingsetdialog.cpp b/drawingsetdialog.cpp index 3e5161b..e2cccb7 100644 --- a/drawingsetdialog.cpp +++ b/drawingsetdialog.cpp @@ -8,9 +8,90 @@ DrawingSetDialog::DrawingSetDialog(QWidget *parent) : ui->setupUi(this); setWindowModality(Qt::ApplicationModal); setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); + + QIntValidator *validator1 = new QIntValidator(1, 10, this); + ui->lineEdit_lineWidth->setValidator(validator1); + + QIntValidator *validator2 = new QIntValidator(50, 3030, this); + ui->lineEdit_paperWidth->setValidator(validator2); + + QIntValidator *validator3 = new QIntValidator(0, 1300, this); + ui->lineEdit_right->setValidator(validator3); + + QIntValidator *validator4 = new QIntValidator(0, 500, this); + ui->lineEdit_mark->setValidator(validator4); + + QIntValidator *validator5 = new QIntValidator(20, 1000, this); + ui->lineEdit_butt->setValidator(validator5); } DrawingSetDialog::~DrawingSetDialog() { delete ui; } + +void DrawingSetDialog::refreshLanguage() +{ + ui->retranslateUi(this); +} + +void DrawingSetDialog::refreshConfigPara(QString filePath) +{ + m_configfile = filePath; + QSettings settings(filePath, QSettings::IniFormat); + + bool rotate90 = settings.value("DrawSet/rotate90").toBool();//是否正向旋转90度 + bool vecfont = settings.value("DrawSet/vecfont").toBool();//是否使用矢量字体 + QString lineWidth = settings.value("DrawSet/linewidth").toString();//线宽 + QString paperWidth = settings.value("DrawSet/paperwidth").toString();//纸张宽度 + QString rightMargin = settings.value("DrawSet/rightmargin").toString();//右边距 + QString markMargin = settings.value("DrawSet/markmargin").toString();//马克间距 + QString buttMargin = settings.value("DrawSet/buttmargin").toString();//对接符间距 + + ui->checkBox_angle->setChecked(rotate90); + ui->checkBox_font->setChecked(vecfont); + ui->lineEdit_lineWidth->setText(lineWidth); + ui->lineEdit_paperWidth->setText(paperWidth); + ui->lineEdit_right->setText(rightMargin); + ui->lineEdit_mark->setText(markMargin); + ui->lineEdit_butt->setText(buttMargin); +} + +double DrawingSetDialog::getRotateAngle() +{ + double angle = 0; + bool bl = ui->checkBox_angle->isChecked(); + if(bl == true) + { + angle = 270; + } + return angle; +} + +void DrawingSetDialog::on_pushButton_cancel_clicked() +{ + done(0); +} + +void DrawingSetDialog::on_pushButton_ok_clicked() +{ + QSettings settings(m_configfile, QSettings::IniFormat); + + int rotate90 = ui->checkBox_angle->isChecked();//是否正向旋转90度 + int vecfont = ui->checkBox_font->isChecked();//是否使用矢量字体 + QString lineWidth = ui->lineEdit_lineWidth->text();//线宽 + QString paperWidth = ui->lineEdit_paperWidth->text();//纸张宽度 + QString rightMargin = ui->lineEdit_right->text();//右边距 + QString markMargin = ui->lineEdit_mark->text();//马克间距 + QString buttMargin = ui->lineEdit_butt->text();//对接符间距 + + settings.setValue("DrawSet/rotate90",rotate90); + settings.setValue("DrawSet/vecfont",vecfont); + settings.setValue("DrawSet/linewidth",lineWidth); + settings.setValue("DrawSet/paperwidth",paperWidth); + settings.setValue("DrawSet/rightmargin",rightMargin); + settings.setValue("DrawSet/markmargin",markMargin); + settings.setValue("DrawSet/buttmargin",buttMargin); + + done(1); +} diff --git a/drawingsetdialog.h b/drawingsetdialog.h index 73bc423..94f67cd 100644 --- a/drawingsetdialog.h +++ b/drawingsetdialog.h @@ -2,6 +2,8 @@ #define DRAWINGSETDIALOG_H #include +#include +#include namespace Ui { class DrawingSetDialog; @@ -14,9 +16,18 @@ class DrawingSetDialog : public QDialog public: explicit DrawingSetDialog(QWidget *parent = 0); ~DrawingSetDialog(); + void refreshLanguage(); + void refreshConfigPara(QString filePath);//刷新配置参数 + double getRotateAngle(); + +private slots: + void on_pushButton_cancel_clicked(); + void on_pushButton_ok_clicked(); private: Ui::DrawingSetDialog *ui; + QString m_configfile; + }; #endif // DRAWINGSETDIALOG_H diff --git a/drawingsetdialog.ui b/drawingsetdialog.ui index 4f0e267..2d2c348 100644 --- a/drawingsetdialog.ui +++ b/drawingsetdialog.ui @@ -23,7 +23,7 @@ - Use vector fonts + Use vector fonts @@ -36,7 +36,7 @@ - Graph positive rotation angle + Graph positive rotation 90 angle @@ -62,7 +62,7 @@ - Boundary and alignment spacing + Boundary and alignment spacing @@ -100,7 +100,7 @@ - Right margin: + Right margin: @@ -139,7 +139,7 @@ - Mark margin: + Mark margin: @@ -152,7 +152,7 @@ - Butt joint margin: + Butt joint margin: @@ -240,13 +240,13 @@ - Paper Width + Paper Width 170 - 24 + 28 54 12 @@ -259,7 +259,7 @@ 70 - 20 + 25 91 20 @@ -272,7 +272,7 @@ 10 - 20 + 24 42 20 @@ -308,26 +308,26 @@ - Lineweight settings + Lineweight settings 13 - 20 + 24 91 20 - Lineweight: + Lineweight: 110 - 20 + 24 91 20 @@ -340,13 +340,13 @@ 210 - 19 + 24 61 21 - pixel + pixel diff --git a/english.ts b/english.ts new file mode 100644 index 0000000..a4f4958 --- /dev/null +++ b/english.ts @@ -0,0 +1,1089 @@ + + + + + AddMachineDialog + + + Dialog + + + + + Ok + + + + + Cancel + + + + + IP: + + + + + Name: + + + + + + Prompt + + + + + Please enter the correct IP! + + + + + Please enter the correct machine name! + + + + + DrawingSetDialog + + + Dialog + + + + + Use vector fonts + 使用矢量字体 + + + + + Graph positive rotation 90 angle + Graph positive rotation angle + 图形正向旋转90度 + + + + + Ok + + + + + Boundary and alignment spacing + 边界及对位间距 + + + + + + + + mm + + + + + + 0 + + + + + Right margin: + 右边距: + + + + + Mark margin: + 马克间距: + + + + + Butt joint margin: + 对接符间距: + + + + + 1000 + + + + + Paper Width + 纸张宽度 + + + + + 2400 + + + + + Cancel + + + + + Lineweight settings + 线宽设置 + + + + + Lineweight: + 线宽: + + + + + 2 + + + + + pixel + 像素 + + + + + HistoryDialog + + + Dialog + + + + + Clear + + + + + Cancel + + + + + Draw + + + + + ImportHPGL + + + Encrypted file parsing error! + + + + + MainWindow + + + MainWindow + + + + + Print Info + + + + + Total Files: + + + + + Total Length: + + + + + Progress: + + + + + File(F) + + + + + Testing + + + + + Connect Manage(C) + + + + + Setting(S) + + + + + Language(L) + + + + + About(A) + + + + + toolBar + + + + + Open File + + + + + + Ctrl+O + + + + + Open Image + + + + + + Ctrl+I + + + + + + Start + + + + + + Pause + + + + + + + Delete + + + + + Ctrl+Del + + + + + Exit + + + + + USB + + + + + NetWork + + + + + Delete Link + + + + + Auto Print Dir + + + + + log + + + + + Parameter Import + + + + + Parameter Export + + + + + Drawing Setting + + + + + Plotter Setting View + + + + + Chinese + + + + + English + + + + + OpenFileIcon + + + + + OpenFile + + + + + OpenImageIcon + + + + + OpenImage + + + + + StartIcon + + + + + PauseIcon + + + + + DrawingSetIcon + + + + + DrawingSetting + + + + + Add Machine + + + + + Delete Machine + + + + + test1.plt + + + + + + + + + + + + + + Prompt + + + + + Printing this file, it cannot be moved! + + + + + + Connnecting... + + + + + + Connected + + + + + + + NotConnected + + + + + + Idle + + + + + + Working + + + + + + + Waitting + + + + + + + Printting + + + + + + FileName + + + + + + Length + + + + + + Width + + + + + + Printed + + + + + + Progress + + + + + + Numbers + + + + + + State + + + + + + FilePath + + + + + + StartPoint + + + + + + McName + + + + + + McIp + + + + + + McConState + + + + + + McState + + + + + + McProgress + + + + + Print preview + + + + + Number of modified print + + + + + Modify the starting print point + + + + + View print information + + + + + Do you want to delete this drawing? + + + + + Printing this file, it cannot be deleted! + + + + + After deletion, the machine cannot be controlled. Do you want to delete this machine? + + + + + Complete + + + + + + Please select a machine! + + + + + + Loading file, please wait! + + + + + + Open File Dialog + + + + + File(*.plt *.dxf) + + + + + Image File(*.png *.bmp *.jpg) + + + + + Please select the machine you want to set the directory! + + + + + Select Folder + + + + + The maximum number of connections has been reached and cannot be added again! + + + + + PlotterSetDialog + + + Dialog + + + + + Print startup mode selection + 打印启动方式选择 + + + + + Auto Print + 自动打印 + + + + + Print mode selection + 打印模式选择 + + + + + Single + 单向 + + + + + Double + 双向 + + + + + Graphic error correction + 图形误差修正 + + + + + + 1000 + + + + + + + + + mm + + + + + + 1 meter actual output: + 1米实际输出: + + + + + Drawing 1 meter Square + 绘1米正方形 + + + + + Two way print error setting + 双向打印误差设置 + + + + + + + + + + + + 0 + + + + + Two way print error: + 双向打印错位误差: + + + + + Print drawing width: + 打印图形宽度: + + + + + 1600 + + + + + Print Error Correction + 打印误差修正图 + + + + + Error setting between nozzles + 喷头间误差设置 + + + + + + + + + + pixel + 像素 + + + + + 1、2 error between nozzles: + 1、2喷头间错误误差: + + + + + 2、3 error between nozzles: + 2、3喷头间错误误差: + + + + + 3、4 error between nozzles: + 3、4喷头间错误误差: + + + + + 1、2 overlap between nozzles: + 1、2喷头间重叠误差: + + + + + 2、3 overlap between nozzles: + 2、3喷头间重叠误差: + + + + + 3、4 overlap between nozzles: + 3、4喷头间重叠误差: + + + + + Correction diagram between nozzles + 打印喷头间误差修正图 + + + + + Paper feeding error correction + 走纸误差修正 + + + + + Paper feeding error set: + 走纸误差设置: + + + + + Print paper feed error + 打印走纸误差 + + + + + Ok + 确定 + + + + + Cancel + 取消 + + + + + Sprinkler selection + 喷头选择 + + + + + Nozzle 1 + 1号喷头 + + + + + Nozzle 2 + 2号喷头 + + + + + Nozzle 3 + 3号喷头 + + + + + Nozzle 4 + 4号喷头 + + + + + PrintInfoDialog + + + Dialog + + + + + Working Info + + + + + File Name: + + + + + Width/Height: + + + + + Print Number: + + + + + Start Print Point: + + + + + Total Blocks: + + + + + Current Print Block: + + + + + Printed Block Number: + + + + + Leave Block Number: + + + + + Select Block Number: + + + + + Back + + + + + piece + + + + + PrintNumberSetDialog + + + Dialog + + + + + (1-255) + + + + + 1 + + + + + Number: + 份数: + + + + + Ok + + + + + Cancel + + + + + Prompt + + + + + Unreasonable value input! + + + + + PrintViewWindow + + + Print View + + + + + mm + + + + + + + 0 + + + + + Draw + + + + + Y: + + + + + 1 + + + + + Start point: + + + + + X: + + + + + Number: + + + + + Prompt + + + + + Unreasonable value input! + + + + + StartSetDialog + + + Dialog + + + + + Ok + + + + + Cancel + + + + + 0 + + + + + Start: + + + + + (range) + + + + + Prompt + + + + + Unreasonable value input! + + + + diff --git a/historydialog.cpp b/historydialog.cpp index b258d05..0103406 100644 --- a/historydialog.cpp +++ b/historydialog.cpp @@ -14,3 +14,8 @@ HistoryDialog::~HistoryDialog() { delete ui; } + +void HistoryDialog::refreshLanguage() +{ + ui->retranslateUi(this); +} diff --git a/historydialog.h b/historydialog.h index 51f838a..c0bf6f4 100644 --- a/historydialog.h +++ b/historydialog.h @@ -14,6 +14,7 @@ class HistoryDialog : public QDialog public: explicit HistoryDialog(QWidget *parent = 0); ~HistoryDialog(); + void refreshLanguage(); private: Ui::HistoryDialog *ui; diff --git a/machine/bmp/bwbmp.cpp b/machine/bmp/bwbmp.cpp index a3dd146..83de46b 100644 --- a/machine/bmp/bwbmp.cpp +++ b/machine/bmp/bwbmp.cpp @@ -70,33 +70,36 @@ int BWBmp::SavePrBmp(QString filename) return 0; } +/* + 这段C++代码实现了一个名为BWBmp的类的成员函数Compress,该函数的作用是对黑白位图数据进行压缩处理,以便减少喷墨绘图仪的数据传输量。按照注释所描述的压缩算法,算法主要针对的是单个墨盒(假设宽度固定为300像素)的位图数据,其高度可变,最多支持4个墨盒。 + 整个函数通过对图像数据进行逐行扫描,统计连续相同颜色像素的数量,并利用特殊的编码规则进行压缩,从而达到减小数据体积的目的。当遇到不适合压缩的情况时,会选择直接复制原始数据,以保证不会因压缩反而增大数据量。 + 为了减少喷墨绘图仪的数据传输量,对黑白位图数据进行压缩。 + 压缩算法如下: -int BWBmp::Compress(int dir) + 每个墨盒的位图数据宽度为300像素,高度不确定,墨盒数量支持1--4个 + + 每个字节分为两段 + 用属性+值 的方式表示 + __________________________________________________ + | bit7 bit6 | bit5 bit4 bit3 bit2 bit1 bit0 | + -------------------------------------------------- + | 属性 | 值 | + -------------------------------------------------- + | 0 0 | 原始数据 | + -------------------------------------------------- + | 0 1 | 连续数据1的个数 | + -------------------------------------------------- + | 1 0 | 连续65个数据0的个数 | + -------------------------------------------------- + | 1 1 | 连续数据0的个数 | + -------------------------------------------------- +*/ +int BWBmp::Compress(int idx, int dir, int segWidth, int segHeight) { - /* - 为了减少喷墨绘图仪的数据传输量,对黑白位图数据进行压缩。 - 压缩算法如下: - - 每个墨盒的位图数据宽度为300像素,高度不确定 - - 每个字节分为两段 - 用属性+值 的方式表示 - __________________________________________________ - | bit7 bit6 | bit5 bit4 bit3 bit2 bit1 bit0 | - -------------------------------------------------- - | 属性 | 值 | - -------------------------------------------------- - | 0 0 | 原始数据 | - -------------------------------------------------- - | 0 1 | 连续数据1的个数 | - -------------------------------------------------- - | 1 0 | 连续10个数据0的个数 | - -------------------------------------------------- - | 1 1 | 连续数据0的个数 | - -------------------------------------------------- - */ + // qint64 startTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + // 确保dir参数正确设置为1或-1,表示读取图像数据的方向(从上到下或从下到上)。 if (dir < 0) { dir = -1; @@ -106,6 +109,7 @@ int BWBmp::Compress(int dir) dir = 1; } + // 清理目标压缩数据缓冲区,并检查源位图数据是否为空,若为空则返回错误码-1。 m_prDdat.clear(); if (m_bwDdat.isEmpty() == 1) { @@ -113,6 +117,489 @@ int BWBmp::Compress(int dir) return -1; } + // 初始化临时压缩数据缓冲区tmppr,并从源位图数据中获取图像的基本信息,如宽度、高度、实际占用的字节数(行字节数),并检查这些信息的有效性,如有问题则返回错误码-2。 + + BitmapHead * pHead = (BitmapHead *)(m_bwDdat.data()); + + int width = pHead->biWidth; // 文件宽度 + int height = pHead->biHeight; // 文件高度 + int widthBytes = (int)((width + (32-1)) / 32) * 4; // 文件每行字节数 + + int wsegnum = (int)((width + segWidth - 1) / segWidth); // 宽分块数量 + int hsegnum = (int)((height + segHeight - 1) / segHeight); // 高分块数量 + int fill = (int)((segWidth + (8-1)) / 8) * 8 - segWidth; // 分块后每行补充Bit数 + int msegnum = (segWidth + fill) * segHeight; // 每块字节数 + + if (0) + { + qDebug() << "Img dir"<bitDatOffset; + } + + if (widthBytes <= 0 || height < 1 || width > 0x1000000) + { + qDebug() << "bit dat error"; + return -2; + } + + const unsigned char * pBitDatBeg = (unsigned char *)(m_bwDdat.data() + pHead->bitDatOffset); + + //--------------------------------------------------------- + // 读取位图信息,对数组赋值 + unsigned char sta,tmpdat,mod; + const unsigned char * pBitDat; + int i, j, k, l, m, n; + int addr; + int x, y; + + //------------------------------------ + int * segdat = new int [msegnum]; + + //------------------------------------ + unsigned char tgtdat; + QVector compType(wsegnum); // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩(分段压缩); + QVector compSegOffset(wsegnum); // 分段数据起始位置 + + if (dir < 0) // 反向 + { + pBitDatBeg += widthBytes * (height -1); + } + + for (i = 0; i < wsegnum; i++) + {// 分块 + addr = m_prDdat.size(); // 压缩前的字节数 + compType[i] = 1; // 按字节压缩(分段压缩); + compSegOffset[i] = m_prDdat.size(); // 数据地址 + + if (1) + { + for (j = 0; j < hsegnum; j++) + {// 分块 + if (dir > 0) // 正向 + { + y = j * segHeight; // 起始坐标点 Y + m = 0; // 分割后数组的索引 + + for (l = 0; l < segHeight; l++,y++) + {// Y扫描 + + x = i * segWidth; // 起始坐标点 X + + for (k = 0; k < segWidth; k++,x++) + {// x扫描赋值 + if ((x < width) && (y < height)) + {// 采集当前点数据 + pBitDat = pBitDatBeg + (widthBytes * (height-y-1)) + (x / 8); + + tmpdat = *pBitDat; + mod = 0x80 >> (x % 8); + if ((tmpdat & mod) == 0) + { + sta = 0; + } + else + { + sta = 1; + // qDebug() << "x =" << x << ",y =" << y + // << ",[i =" << i << ",j =" << j + // << ",l =" << l << ",k =" << k + // << ",m =" << m << "]"; + } + } + else + {// X,Y超出最大范围后,使用默认值:0 + sta = 0; + } + + segdat[m++] = sta; + } + + for (k = 0; k < fill; k++) + {// x结尾处 字节对齐 + segdat[m++] = sta; + } + } + } + else//if (dir > 0) + {// 反向 + y = (hsegnum - j) * segHeight - 1; // 起始坐标点 Y + m = 0; // 分割后数组的索引 + + for (l = 0; l < segHeight; l++,y--) + {// Y反向扫描 + x = i * segWidth; // 起始坐标点 X + + for (k = 0; k < segWidth; k++,x++) + {// x扫描赋值 + if ((x < width) && (y < height)) + {// 采集当前点数据 + pBitDat = pBitDatBeg - (widthBytes * y) + (x / 8); + + tmpdat = *pBitDat; + mod = 0x80 >> (x % 8); + if ((tmpdat & mod) == 0) + { + sta = 0; + } + else + { + sta = 1; + // qDebug() << "x =" << x << ",y =" << y + // << ",[i =" << i << ",j =" << j + // << ",l =" << l << ",k =" << k + // << "]"; + } + } + else + {// X,Y超出最大范围后,使用默认值:0 + sta = 0; + } + segdat[m++] = sta; + } + + for (k = 0; k < fill; k++) + {// x结尾处 字节对齐 + segdat[m++] = sta; + } + } + } + + //--------------------------------------------------------- + // 对数据进行压缩 + for (k = 0; k < msegnum; k = l) + { + n = 0; // 连续的个数 + sta = segdat[k]; // 前一次的状态 + tgtdat = 0; + + // 求连续相同状态的个数 + for (l = k; l < msegnum; l++) + { + n++; + if (n <= 6) + {// 预先计算原始数据 + tgtdat <<= 1; + + if (segdat[l] != 0) + { + tgtdat |= 0x01; + } + + if (n == 6) + {// 判断前六个位图是否相同 + if (((sta == 0) && (tgtdat != 0)) || + ((sta != 0) && (tgtdat != 0x3f)) || + 0) + { + l++; + break; + } + } + } + else// if (n > 6) + { + if (segdat[l] != sta) + { + n--; + break; + } + else + { + if (sta == 0) + {// 连续0 (最多 4160) + if (n == 4160) + { + l++; + break; + } + } + else + {// 连续1 (最多64) + if (n == 64) + { + l++; + break; + } + } + } + } + } + + for ( ;n<6;n++) + {// 原始位图时,如果结尾不足6位,低位补零 + tgtdat <<= 1; + // qDebug() << "for ( ;n<6;n++) n =" << n << ",l =" << l ; + } + + {// 生成压缩数据 + if (n == 6) + { + m_prDdat.append(tgtdat); // 添加原始位图数据 + } + else if (sta == 0) + { + if (n <= 64) + { + tgtdat = 0xC0 | (n & 0x3f); + m_prDdat.append(tgtdat); // 添加连续数据0的个数数据 + } + else if (n == 4160) + { + tgtdat = 0x80; + m_prDdat.append(tgtdat); // 添加连续 65 个数据0的个数数据 + } + else // (64 < n < 4160) + { + tgtdat = 0x80 | (n / 65); + m_prDdat.append(tgtdat); // 添加连续 65 个数据0的个数数据 + + tgtdat = n % 65; + if (tgtdat != 0) + { + tgtdat = 0xC0 | tgtdat; + m_prDdat.append(tgtdat); // 添加连续数据0的个数数据 + } + } + } + else // if (sta == 1) + { + tgtdat = 0x40 | (n & 0x3f); + m_prDdat.append(tgtdat); // 添加 连续数据1的个数 数据 + } + } + } + } // for (j = 0; j < hsegnum; j++) + } + + //--------------------------------------------------------- + // 判断压缩后的数据是否比压缩前的小 + if ((m_prDdat.size() - addr) > (msegnum * hsegnum / 7)) + {// 使用原始数据 + m_prDdat.truncate(addr); // 删除当前段的压缩数据 + compType[i] = 0; // 不压缩,使用原始数据; + + for (j = 0; j < hsegnum; j++) + {// 分块 + if (dir > 0) // 正向 + { + y = j * segHeight; // 起始坐标点 Y + m = 0; // 分割后数组的索引 + + for (l = 0; l < segHeight; l++,y++) + {// Y扫描 + + x = i * segWidth; // 起始坐标点 X + + for (k = 0; k < segWidth; k++,x++) + {// x扫描赋值 + if ((x < width) && (y < height)) + {// 采集当前点数据 + pBitDat = pBitDatBeg + (widthBytes * (height-y-1)) + (x / 8); + + tmpdat = *pBitDat; + mod = 0x80 >> (x % 8); + if ((tmpdat & mod) == 0) + { + sta = 0; + } + else + { + sta = 1; + } + } + else + {// X,Y超出最大范围后,使用默认值:0 + sta = 0; + } + segdat[m++] = sta; + } + + for (k = 0; k < fill; k++) + {// x结尾处 字节对齐 + segdat[m++] = sta; + } + } + } + else//if (dir > 0) + {// 反向 + y = (hsegnum - j) * segHeight - 1; // 起始坐标点 Y + m = 0; // 分割后数组的索引 + + for (l = 0; l < segHeight; l++,y--) + {// Y反向扫描 + x = i * segWidth; // 起始坐标点 X + + for (k = 0; k < segWidth; k++,x++) + {// x扫描赋值 + if ((x < width) && (y < height)) + {// 采集当前点数据 + pBitDat = pBitDatBeg - (widthBytes * y) + (x / 8); + + tmpdat = *pBitDat; + mod = 0x80 >> (x % 8); + if ((tmpdat & mod) == 0) + { + sta = 0; + } + else + { + sta = 1; + } + } + else + {// X,Y超出最大范围后,使用默认值:0 + sta = 0; + } + segdat[m++] = sta; + } + + for (k = 0; k < fill; k++) + {// x结尾处 字节对齐 + segdat[m++] = sta; + } + } + } + + // 生成原始数据 + n = 0; + for (m = 0; m < msegnum; m++) + { + tgtdat <<= 1; + if (segdat[m] != 0) + { + tgtdat |= 0x01; + } + + n++; + if ((n % 8) == 0) + { + m_prDdat.append(tgtdat); // 添加 连续数据1的个数 数据 + } + } + } + + } + } // for (i = 0; i < wsegnum; i++) + + // qint64 time1 = QDateTime::currentDateTime().toMSecsSinceEpoch(); + // qDebug() << "time1:" << time1 - startTime; + + delete []segdat; + + //--------------------------------------------------------- + // 构造压缩位图头部信息CompBmpHead,包含块索引、压缩方向、压缩类型以及压缩后的数据大小等信息。 + // 添加文件头 + CompBmpHead prHead; + memset(&prHead, 0, sizeof(CompBmpHead)); + + prHead.fileId = 0; // 整个位图文件标识 + prHead.blkIdx = idx; // 当前位图块号(位图分块后的编号) + prHead.datSize = m_prDdat.size(); // 本块位图数据区的大小(字节数) + prHead.biHeight = segHeight * hsegnum; // 本块位图有效宽度,以像素为单位 + prHead.biWidth = segWidth * wsegnum; // 本块位图有效高度,以像素为单位 + prHead.dataChecksum = 0; // 本块位图数据累加校验和 + + if (dir < 0) // 本块位图压缩方向, =0, 从上到下; =1, 从下到上;(喷墨方向) + { + prHead.compDir = 1; + } + else + { + prHead.compDir = 0; + } + prHead.compSegWidth = segWidth; // 分段宽度(0,默认整个宽度,分段宽度必须能被本块位图有效宽度整除) + prHead.compSegHeight = segHeight; // 分段高度(0,默认1行的高度) + prHead.compFillWidth = fill; // 压缩填充位数 + + for (i=0;i<4;i++) + { + if (i < wsegnum) + { + prHead.compType[i] = compType[i]; // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩(分段压缩); + prHead.compSegOffset[i] = compSegOffset[i]; // 分段数据起始位置 + } + } + +// {// 打印压缩数据 +// j = m_prDdat.size(); +// const unsigned char * pPrint = (unsigned char *)(m_prDdat.data()); + +// for (i=0;ibiWidth; @@ -125,15 +612,25 @@ int BWBmp::Compress(int dir) return -2; } - const unsigned char * pBitDat = (unsigned char *)(m_bwDdat.data() + pHead->bitDatOffset); + qDebug() << "Img dir"<bitDatOffset; + + const unsigned char * pBitDatBeg = (unsigned char *)(m_bwDdat.data() + pHead->bitDatOffset); const unsigned char * pTmpDat; + // 按照给定的dir值定位到位图数据的起始位置。 if (dir == -1) { - pBitDat += widthBytes * (height -1); + pBitDatBeg += widthBytes * (height -1); } + const unsigned char * pBitDat = pBitDatBeg; + + // 使用一个整数数组 countBuff 来记录每行中连续的0和1的个数,初始化各种计数器。 int * countBuff = new int [width]; if (countBuff == NULL) { @@ -148,6 +645,7 @@ int BWBmp::Compress(int dir) int count1 = 0; int i, j, k, l; + for (i = 0; i < height; i++) // 行计数 { pTmpDat = pBitDat; @@ -155,24 +653,20 @@ int BWBmp::Compress(int dir) count0 = 0; count1 = 0; + // 遍历图像的每一行,统计当前行中连续0和1的个数,并将其存入countBuff数组。 for (j = 0, k = 0; (j < widthBytes) && (k < width); j++) // 行内扫描,检测出每段连续0和1的个数 { tmpdat = *pTmpDat++; -// if(j+i*widthBytes > 12879) -// { -// qDebug()<> (8 - (width - k )); + // tmpdat = tmpdat >> (8 - (width - k )); } - //for (mod = 0x80; (mod != 0) && (k < width); k++, mod /= 2) - for (mod = 0x01; (mod != 0) && (k < width); k++, mod *= 2) + for (mod = 0x80; (mod != 0) && (k < width); k++, mod /= 2) { if ((tmpdat & mod) == 0) { @@ -216,6 +710,7 @@ int BWBmp::Compress(int dir) } + // 对countBuff中的数据进行分析和编码,生成压缩数据并追加到tmppr中。根据算法描述,压缩数据是以每个字节的高两位作为“属性”位,低六位作为“值”位来表示连续0或1的个数,或者直接存放原始数据。 int psta = 0; int pcount = 0; unsigned char tgtdat = 0, pmod = 0x20, nums; @@ -237,15 +732,13 @@ int BWBmp::Compress(int dir) tgtdat |= pmod; pcount--; count1--; - //pmod /= 2; pmod *= 2; } if (pcount == 0) // 够一个位图 { tgtdat &= 0x3f; - m_prDdat.append(tgtdat); // 添加 - //qDebug()< 64) else if (count0 >= 64) { nums = (int)(count0/10); @@ -350,8 +841,8 @@ int BWBmp::Compress(int dir) tgtdat = psta; tgtdat |= (nums & 0x3f); - m_prDdat.append(tgtdat); // 添加 - //qDebug()<biHeight; + prHead.biWidth = pHead->biWidth; -// int size = m_prDdat.size(); -// for(int p = 0; p < size; p++) -// { -// unsigned char ch = m_prDdat[p]; -// qDebug()<= pHead->biBitmapDatSize) // 压缩率不足 + { + prHead.compType = 0; // 不压缩 + prHead.datSize = pHead->biBitmapDatSize; + + tmppr.clear(); + pBitDat = pBitDatBeg; + + for (i = 0; i < height; i++) // 行计数 + { + tmppr.append((const char*)pBitDat, widthBytes); + pBitDat += widthBytes * dir; + } + } + else + { + prHead.compType = 1; + prHead.datSize = prsize; + } + + m_prDdat.append((char*)(&prHead), sizeof(CompBmpHead)); + m_prDdat.append(tmppr); return 0; } - -int BWBmp::LoadPrBmp(QString filename) { - m_fileName = filename; - m_rbwDdat.clear(); - m_prDdat.clear(); - QFile file(filename); - int rslt = file.open(QFile::ReadOnly); - if (rslt == 0) - { - qDebug() << "open file error" << filename; - return -1; - } +#define VAL_OUTBMP 0xff // 位图之外的默认数据 - m_prDdat = file.readAll(); - if (m_prDdat.size() <= 0) - { - file.close(); - qDebug() << "file size error, size=" << m_prDdat.size(); - m_prDdat.clear(); - return -2; - } - - file.close(); - return 0; -} - -int BWBmp::Unpress() -{ - m_rbwDdat.clear(); - QByteArray arrdat; - arrdat.clear(); - - QByteArray barr; - barr.clear(); - QFileInfo file(m_fileName); - QString name = file.filePath().remove("."+file.suffix()); - - QFile bfile(name); - bfile.open(QFile::ReadOnly); - barr = bfile.readAll(); - BitmapHead * pHead = (BitmapHead *)(barr.data()); - - int widthBytes = (int)((pHead->biWidth + 31) / 32) * 4; - m_rbwDdat.append((char*)pHead,sizeof(BitmapHead)); - - if (m_prDdat.isEmpty() == 1) - { - qDebug() << "pr dat empty"; - return -1; - } + m_rbwDdat.append((char*)(&bmpHead), sizeof(BitmapHead)); unsigned char sdat = 0; int count0,count1,flag; count0 = count1 = 0; flag = -1; - int size = m_prDdat.size(); for(int i = 0; i < size; i++) { -// if(i > 3250) -// { -// int a = 0; -// a = 1; -// } count0 = count1 = 0; flag = -1; - sdat = m_prDdat[i]; + sdat = pPrDdat[i]; if((sdat & 0xC0) == 0xC0) // 连续0 { count0 = sdat & 0x3f; + if (count0 == 0) + { + count0 = 64; + } flag = 0; } - else + else if((sdat & 0xC0) == 0x40) // 连续1 { - if((sdat & 0x40) == 0x40) // 连续1 + count1 = sdat & 0x3f; + if (count1 == 0) { - count1 = sdat & 0x3f; - flag = 1; + count1 = 64; } - else if((sdat & 0x80) == 0x80) // 连续10个0 + flag = 1; + } + else if((sdat & 0xC0) == 0x80) // 连续10个0 + { + count0 = (sdat & 0x3f ) * 10; + if (count0 == 0) { - count0 = (sdat & 0x3f ) * 10; - flag = 0; + count0 = 640; } - else // 原始数据 + flag = 0; + } + else // 原始数据 + {//每行扫描时最后一个像素为原始数据时原始数据个数 + int pcount = 6; + int val = arrdat.size() % biWidth; + int cnt = biWidth - val; + int cnt1 = abs((int)biWidth - ((int)widthBytes-1) * 8); + if(cnt >= cnt1) { - //每行扫描时最后一个像素为原始数据时原始数据个数 - int pcount = 6; - int val = arrdat.size() % pHead->biWidth; - int cnt = pHead->biWidth - val; - int cnt1 = abs(pHead->biWidth - (widthBytes-1) * 8); - if(cnt >= cnt1) + pcount = 6; + } + else + { + if(cnt > 6) { pcount = 6; } else { - if(cnt > 6) - { - pcount = 6; - } - else - { - pcount = cnt; - } + pcount = cnt; } - - unsigned char sch = sdat & 0x3f; //够一个位图 - - unsigned char pmod = 0x01; - while (pcount != 0) - { - if((sch & pmod) != 0) // 为1 - { - arrdat.append((char)0x01); - } - else // 为0 - { - arrdat.append((char)0x00); - } - pcount--; - pmod *= 2; - } - - continue; } + + unsigned char sch = sdat & 0x3f; //够一个位图 + + unsigned char pmod = 0x01; + while (pcount != 0) + { + if((sch & pmod) != 0) // 为1 + { + arrdat.append((char)0x01); + } + else // 为0 + { + arrdat.append((char)0x00); + } + pcount--; + pmod *= 2; + } + + continue; } int count = 0; @@ -537,36 +1014,38 @@ int BWBmp::Unpress() } int num = 0; - unsigned char abyte = 0; - unsigned int cnt = 0; - for(unsigned int n = 0; n < pHead->biHeight; n++) + unsigned int lst = ((biWidth/8)*8+8); + + for(unsigned int n = 0; n < biHeight; n++) { for(int j = 0; j < widthBytes; j++) { - abyte = 0; - for(int i = 0; i < 8; i++) + unsigned int cnt = j*8; + unsigned char abyte = 0; + + int idx = n*biWidth+j*8; + for(int i = 0; i < 8; i++, idx++, cnt++) { - int idx = n*pHead->biWidth+j*8+i; //qDebug()<<"idx"<biWidth) + if (cnt < biWidth) { - abyte |= ch; + unsigned char ch = arrdat[idx]; + if (ch != 0) + { + abyte |= (ch << (7-i)); + } } - else if(cnt == pHead->biWidth) + else if(cnt >= lst) { - abyte = abyte << (8 - i); - } - else if(cnt >= ((pHead->biWidth/8)*8+8)) - { - abyte = 0; + abyte = VAL_OUTBMP; // 默认值 + break; } else { - continue; + abyte |= ((VAL_OUTBMP) >> (i)); // 默认值 + break; } } @@ -578,27 +1057,6 @@ int BWBmp::Unpress() num++; } } - - return 0; } +*/ -int BWBmp::SaveBiBmp(QString filename) -{ - QFile file(filename); - int rslt = file.open(QFile::ReadWrite | QFile::Truncate); - if (rslt == 0) - { - qDebug() << "open file error" << filename; - return -1; - } - - file.write(m_rbwDdat); - file.close(); - - return 0; -} - -QByteArray BWBmp::getPrBmpDat() -{ - return m_prDdat; -} diff --git a/machine/bmp/bwbmp.h b/machine/bmp/bwbmp.h index 6c3e9a6..3825698 100644 --- a/machine/bmp/bwbmp.h +++ b/machine/bmp/bwbmp.h @@ -3,6 +3,7 @@ #include #include +#include "machine/comm/protocol.h" #pragma pack(1) //设定为1字节对齐 @@ -37,8 +38,6 @@ typedef struct BmpRgbQuad palette[2]; // 调色板 }__attribute__ ((packed)) BitmapHead; -#pragma pack(4) - class BWBmp { @@ -48,26 +47,30 @@ public: public: int LoadBiBmp(QString filename); int SavePrBmp(QString filename); - int Compress(int dir = 1); - - int LoadPrBmp(QString filename); - int Unpress(); - int SaveBiBmp(QString filename); - + int Compress(int idx = 0, int dir = 1, int segWidth = 300, int segHeight = 50); QByteArray getPrBmpDat(); + /* + int CompressSeg(const unsigned char * pBitDatBeg, + unsigned int width, unsigned int height, + unsigned int segWidth, unsigned int segHeight, unsigned char fill, + int compDir, + QByteArray & prDat); + int UnpressSeg(const unsigned char * pBitDatBeg, + unsigned int width, unsigned int height, + unsigned int segWidth, unsigned int segHeight, unsigned char fill, + int compDir, + QByteArray & prDat); + +*/ + private: - QByteArray m_bwDdat; + QByteArray m_bwDdat; // 单色BMP QByteArray m_prDdat; QByteArray m_rbwDdat; QString m_fileName; }; - - - - - #endif // BWBMP_H diff --git a/machine/bmp/creatprintbmp.cpp b/machine/bmp/creatprintbmp.cpp index 0c770a8..285663a 100644 --- a/machine/bmp/creatprintbmp.cpp +++ b/machine/bmp/creatprintbmp.cpp @@ -3,18 +3,19 @@ CreatPrintBmp::CreatPrintBmp(QObject *parent) : QObject(parent) { m_savePath.clear(); - m_workState = PAUSE; - m_beginPrintFileIdx = -1; + m_workState = WORK_PAUSE; m_fileBegIdx = -1; m_fileEndIdx = -1; m_deleteFileIdx = -1; - m_curFileIdx = -1;//当前生成数据的文件索引 + m_listFileIdx = -1;//当前生成数据的文件索引 m_curBmpBlockIdx = -1;//当前生成数据的位图块数索引 m_mcPrintInfo = NULL; m_conpressDir = 1; m_printFileDir.clear(); m_moveFileIdx = -1;//上下移动打印文件索引 m_moveDir = 0;//-1,上移 1,下移 + m_rotateAngle = 0; + m_autoDirFilesList.clear(); } CreatPrintBmp::~CreatPrintBmp() @@ -26,216 +27,61 @@ CreatPrintBmp::~CreatPrintBmp() } } -int CreatPrintBmp::creatFileListMarker() +int CreatPrintBmp::creatFileListMarker(int idx) { + if(m_workState == WORK_PAUSE) + { + return -1; + } + if(m_mcPrintInfo->m_loadFileFinishFlag < 0) { - QString iniName = "MachineNo" + QString::number(m_mcPrintInfo->m_mcNum) + ".ini"; - QDir apppath(qApp->applicationDirPath()); - QString iniPath = apppath.path() + apppath.separator() + iniName; - QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来 - QString dirPath = setting.value("AutoPrintDir/fileDir").toString(); - QDir dir(dirPath); - if(dir.exists()) + if(idx >= m_autoDirFilesList.size()) { - QStringList filter; - filter << QString("*.plt") << QString("*.PLT") - << QString("*.png") << QString("*.PNG") - << QString("*.bmp") << QString("*.BMP") - << QString("*.jpg") << QString("*.JPG"); - QFileInfoList fileList = dir.entryInfoList(filter, QDir::Files | QDir::NoSymLinks); + return -1; + } - for(int i = 0; i < fileList.size(); i++) + QFileInfo fileInfo(m_autoDirFilesList[idx]); + QString filePath = fileInfo.filePath(); + + int creatDataFlag = 0;//是否已经生成Marker数据的标志 + if(idx < m_mcPrintInfo->m_filesList.size()) + { + if(m_mcPrintInfo->m_filesList[idx].m_creatDataFlag != 0) { - if(m_workState == WORK_PAUSE) - { - return -1; - } - - //QCoreApplication::processEvents(QEventLoop::AllEvents); - - QFileInfo fileInfo(fileList[i]); - QString filePath = fileInfo.filePath(); - - if(m_mcPrintInfo->m_filesList.size() > i) - { - //已经生成数据的跳过 - if(m_mcPrintInfo->m_filesList[i].m_creatDataFlag != 1) - { - McFilesInfo curFilesInfo;//当前文件信息 - creatMarkerDat(curFilesInfo,filePath,i); - long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM; - m_mcPrintInfo->m_fileNums = i+1; - m_mcPrintInfo->m_fileTotalLength += fileTotalLength; - m_mcPrintInfo->m_filesList.append(curFilesInfo); - } - } - else - { - McFilesInfo curFilesInfo;//当前文件信息 - creatMarkerDat(curFilesInfo,filePath,i); - long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM; - m_mcPrintInfo->m_fileNums = i+1; - m_mcPrintInfo->m_fileTotalLength += fileTotalLength; - m_mcPrintInfo->m_filesList.append(curFilesInfo); - } + creatDataFlag = 1; } + } + + //已经生成数据的跳过 + if(creatDataFlag == 0) + { + McFilesInfo curFilesInfo;//当前文件信息 + creatMarkerDat(curFilesInfo,m_printFileDir,filePath,m_listFileIdx,m_rotateAngle); + long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM; + m_mcPrintInfo->m_fileNums += 1; + m_mcPrintInfo->m_fileTotalLength += fileTotalLength; + m_mcPrintInfo->m_filesList.append(curFilesInfo); + } + } + + if(m_mcPrintInfo->m_loadFileFinishFlag < 0) + { + //全部文件Marker数据加载完成 + if(m_mcPrintInfo->m_filesList.size() == m_autoDirFilesList.size()) + { m_mcPrintInfo->m_loadFileFinishFlag = 1; } } - QDir apppath(qApp->applicationDirPath()); - QString printPath = apppath.path() + apppath.separator() + PRINTDIR; - QDir printDir(printPath);//总的打印目录 - if(!printDir.exists()) - { - printDir.mkdir(printPath); - } - QString mcFile = printPath + printDir.separator() + PRINTMCDIR + QString::number(m_mcPrintInfo->m_mcNum); - QDir mcDir(mcFile);//对应每台机器打印目录 - if(!mcDir.exists()) - { - mcDir.mkdir(mcFile); - } - return 0; } -void CreatPrintBmp::creatMarkerDat(McFilesInfo &curFilesInfo, QString filePath, int fileIdx) -{ - QFileInfo fileInfo(filePath); - curFilesInfo.m_marker.Initialize(); - - if(fileInfo.suffix().toUpper() == "PLT") - { - ImportHPGL importHPGL; - curFilesInfo.m_fileType = TYPE_FILE; - - //判断是否为加密文件 - if (importHPGL.IsSecretFile(filePath) == true) - { - // 文件路径 - QString strSecretFile = m_printFileDir + QString::number(fileIdx+1) ; - - QDir fileDir(strSecretFile);//对应每台机器的每个文件打印目录 - if(!fileDir.exists()) - { - fileDir.mkdir(strSecretFile); - } - strSecretFile = strSecretFile + fileDir.separator() + "Secret.plt"; - //qDebug()<<"strSecretFile"< 0)//有位图 - { - painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap); - } - painter.end(); - return pic; -} - int CreatPrintBmp::creatFileListDatAndSend(int idx) { if(idx >= m_mcPrintInfo->m_filesList.size()) { - return 1; + return -1; } McFilesInfo curFilesInfo; @@ -246,7 +92,7 @@ int CreatPrintBmp::creatFileListDatAndSend(int idx) } curFilesInfo = m_mcPrintInfo->m_filesList[idx]; - QString filePath = m_printFileDir + QString::number(idx+1); + QString filePath = m_printFileDir + QString::number(m_listFileIdx+1); QDir fileDir(filePath);//对应每台机器的每个文件打印目录 if(!fileDir.exists()) { @@ -256,7 +102,7 @@ int CreatPrintBmp::creatFileListDatAndSend(int idx) if(curFilesInfo.m_creatDataFlag < 0) { - creatMarkerDat(curFilesInfo,m_mcPrintInfo->m_filesList[idx].m_filePath,idx); + creatMarkerDat(curFilesInfo,m_printFileDir,m_mcPrintInfo->m_filesList[idx].m_filePath,m_listFileIdx,m_rotateAngle); m_mcPrintInfo->m_filesList[idx] = curFilesInfo; } @@ -268,16 +114,7 @@ int CreatPrintBmp::creatFileListDatAndSend(int idx) int oft = 0;//起始打印位置的偏移 if(curFilesInfo.m_fileType == TYPE_FILE) { - //画笔宽度不为1时重画 - if(PENWIDTH != 1) - { - pic = getPicture(curFilesInfo.m_marker,PENWIDTH); - } - else - { - pic = m_mcPrintInfo->m_filesList[idx].m_pic; - } - + pic = m_mcPrintInfo->m_filesList[idx].m_pic; oft = (int)(m_mcPrintInfo->m_filesList[idx].m_startPoint*MMPIXELY); //将picture保存为多个宽度为PIXMAPWIDTH像素的bmp m_mcPrintInfo->m_totalNums = (pic.width() - oft) / PIXMAPWIDTH; @@ -304,34 +141,51 @@ int CreatPrintBmp::creatFileListDatAndSend(int idx) m_mcPrintInfo->m_totalNums += 1; } } - m_mcPrintInfo->m_filesList[idx].m_pic = pic; m_mcPrintInfo->m_filesList[idx].m_totalBlocks = (pic.width() - oft)/ PIXMAPWIDTH; + int lwidth = (pic.width() - oft) % PIXMAPWIDTH; + if(lwidth != 0) + { + m_mcPrintInfo->m_filesList[idx].m_totalBlocks += 1; + } + + m_mcPrintInfo->m_filesList[idx].m_totalBlocks *= m_mcPrintInfo->m_filesList[idx].m_printNum; + + m_mcPrintInfo->m_filesList[idx].m_printState = Printting; + //发送文件列表数据 emit siSendFileListDatToMc(idx); return 0; } -int CreatPrintBmp::creatBmpBlockDatAndSend(int idx) +int CreatPrintBmp::creatBmpBlockDatAndSend(int fileidx, int idx) { + if(m_workState == WORK_PAUSE) + { + return -1; + } + QPen pen; pen.setWidth(1); pen.setColor(QColor(Qt::black)); - int nextNum = idx / m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks; - if((idx % m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks) == 0) + if(m_mcPrintInfo->m_filesList[fileidx].m_printNum <= 0) { - idx = 0; + m_mcPrintInfo->m_filesList[fileidx].m_printNum = 1; } + int oneNumCount = m_mcPrintInfo->m_filesList[fileidx].m_totalBlocks / m_mcPrintInfo->m_filesList[fileidx].m_printNum; - QPicture pic = m_mcPrintInfo->m_filesList[m_curFileIdx].m_pic; - int oft = (int)(m_mcPrintInfo->m_filesList[m_curFileIdx].m_startPoint*MMPIXELY); + int nextNum = idx / oneNumCount; + idx = idx - nextNum * oneNumCount; + + QPicture pic = m_mcPrintInfo->m_filesList[fileidx].m_pic; + int oft = (int)(m_mcPrintInfo->m_filesList[fileidx].m_startPoint*MMPIXELY); //将picture保存为多个宽度为PIXMAPWIDTH像素的bmp int num = (pic.width() - oft) / PIXMAPWIDTH; int lwidth = (pic.width() - oft) % PIXMAPWIDTH; int height = pic.height(); - int offset = 0 - idx * PIXMAPWIDTH + oft;//将picture画在bmp上每次的偏移量,bmp的最大尺寸为u16 + int offset = 0 - idx * PIXMAPWIDTH - oft;//将picture画在bmp上每次的偏移量,bmp的最大尺寸为u16 if(lwidth != 0) { @@ -343,7 +197,7 @@ int CreatPrintBmp::creatBmpBlockDatAndSend(int idx) pixPainter->begin(pixmap); pixPainter->setPen(pen); - QString filePath = m_printFileDir + QString::number(m_curFileIdx+1); + QString filePath = m_printFileDir + QString::number(m_listFileIdx+1); QDir fileDir(filePath);//对应每台机器的每个文件打印目录 if(!fileDir.exists()) { @@ -354,7 +208,8 @@ int CreatPrintBmp::creatBmpBlockDatAndSend(int idx) pixmap->fill(Qt::white);//用白色填充 pixPainter->drawPicture(offset,0,pic); - QString path = filePath+QString::number(idx+nextNum*m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks+1)+".bmp"; + int cidx = idx + nextNum*oneNumCount; + QString path = filePath+QString::number(cidx+1)+".bmp"; bool bls = pixmap->save(path); while(bls == false) { @@ -372,7 +227,7 @@ int CreatPrintBmp::creatBmpBlockDatAndSend(int idx) qDebug() << "open file error" << path; return -1; } - rslt = bwBmp.Compress(m_conpressDir); + rslt = bwBmp.Compress(cidx,m_conpressDir); if (rslt != 0) { qDebug() << "Compress error"; @@ -386,25 +241,32 @@ int CreatPrintBmp::creatBmpBlockDatAndSend(int idx) return -1; } QByteArray dat = bwBmp.getPrBmpDat(); + emit siSendDatToMc(dat); + m_mcPrintInfo->m_filesList[fileidx].m_curPrintBlock = cidx + 1; + m_mcPrintInfo->m_filesList[fileidx].m_printedBlockNum = cidx; + m_mcPrintInfo->m_filesList[fileidx].m_leaveBlockNum = m_mcPrintInfo->m_filesList[fileidx].m_totalBlocks - m_mcPrintInfo->m_filesList[fileidx].m_printedBlockNum; - //发送文件 - BmpDatInfo bmpInfo; - memset(&bmpInfo,0,sizeof(BmpDatInfo)); - bmpInfo.blkIdx = idx; - bmpInfo.biWidth = pixmap->width(); - bmpInfo.biHeight = pixmap->height(); - bmpInfo.begPosY = idx * pixmap->width(); - bmpInfo.endPosY = (idx+1) * pixmap->width(); - if(m_conpressDir == -1) + //计算机器打印进度 + int fileNum = m_fileEndIdx - m_fileBegIdx; + int val = 1; + if(fileNum == 1)//每次只发送一个文件 { - bmpInfo.compDir = 0; + val = 0; } - else + double filePro = (1.0 / (double)fileNum)*m_listFileIdx*val;//发送到第m_listFileIdx个文件的进度 + double blockPro = (double)m_mcPrintInfo->m_filesList[fileidx].m_printedBlockNum / (double)m_mcPrintInfo->m_filesList[fileidx].m_totalBlocks;//发送到第idx个块的进度 + double fBlockPro = (1.0 / (double)fileNum) * blockPro;//发送到第idx个块的进度 + double totalPro = filePro + fBlockPro;//发送到第m_listFileIdx个文件的第idx个块的进度 + m_mcPrintInfo->m_mcSendProgress = totalPro*100.0; + + //单个文件打印完成 + if(m_mcPrintInfo->m_filesList[fileidx].m_printedBlockNum == m_mcPrintInfo->m_filesList[fileidx].m_totalBlocks) { - bmpInfo.compDir = 1; + m_mcPrintInfo->m_filesList[m_fileBegIdx].m_printState = Complete; } - //qDebug()<<"dat.size()"<m_mcNum,m_fileBegIdx); + m_mcPrintInfo->m_sendedlNums++; pixPainter->end(); @@ -424,13 +286,14 @@ int CreatPrintBmp::creatBmpBlockDatAndSend(int idx) void CreatPrintBmp::slotCreatBmp() { #if(1) - int val = creatFileListMarker(); + m_curBmpBlockIdx = -1;//当前生成数据的位图块数索引 + int val = creatFileListMarker(m_fileBegIdx); if(val < 0) { return; } - val = creatFileListDatAndSend(m_curFileIdx); + val = creatFileListDatAndSend(m_fileBegIdx); if(val < 0) { return; @@ -513,82 +376,12 @@ void CreatPrintBmp::slotCreatBmp() void CreatPrintBmp::slotCreatNextBmpBlockDat() { - //非正在打印的文件,正在发送文件时的删除操作 - if(m_deleteFileIdx != m_curFileIdx && m_deleteFileIdx != -1) + if(m_mcPrintInfo->m_filesList.size() <= m_fileBegIdx) { - int length = (m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.right() - m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.left())/M_IDPMM; - m_mcPrintInfo->m_fileTotalLength -= length; - m_mcPrintInfo->m_filesList[m_deleteFileIdx].clear(); - m_mcPrintInfo->m_filesList.removeAt(m_deleteFileIdx); - QString mcFile = m_printFileDir + QString::number(m_deleteFileIdx+1); - QDir fileDir(mcFile); - if(fileDir.exists())//理论上无此条件 - { - //删除位图文件夹 - QFileInfoList fileList = fileDir.entryInfoList(QDir::Files); - for(int i = 0; i < fileList.size(); i++) - { - QString fileStr = fileList[i].filePath(); - QFile::remove(fileStr); - } - fileDir.rmdir(mcFile); - } - - if(m_deleteFileIdx < m_curFileIdx)//理论上无此条件 - { - QString oldName = m_printFileDir + QString::number(m_curFileIdx+1); - QDir dir(oldName); - m_curFileIdx--; - QString newName = m_printFileDir + QString::number(m_curFileIdx+1); - dir.rename(oldName,newName); - } - - m_mcPrintInfo->m_fileNums = m_mcPrintInfo->m_filesList.size(); - m_deleteFileIdx = -1; - emit siDeleteFileFinish(); + return; } - //非正在打印的文件,正在发送文件时的上下移操作 - if(m_moveFileIdx != m_curFileIdx && m_moveFileIdx != -1 && m_moveDir != 0) - { - //交换列表 - McFilesInfo info = m_mcPrintInfo->m_filesList[m_moveFileIdx]; - McFilesInfo cInfo; - cInfo = m_mcPrintInfo->m_filesList[m_moveFileIdx+m_moveDir]; - m_mcPrintInfo->m_filesList[m_moveFileIdx+m_moveDir] = info; - m_mcPrintInfo->m_filesList[m_moveFileIdx] = cInfo; - - //更换位图文件夹的名称 - //判断当前交换的文件夹是否存在 - QString mcFile = m_printFileDir + QString::number(m_moveFileIdx+1); - QDir fileDir(mcFile); - if(fileDir.exists())//理论上无此条件 - { - //对当前选中文件夹重命名 - QString oldName = mcFile; - QString newName = mcFile.left(mcFile.size()-1); - fileDir.rename(oldName,newName); - - int cRow = m_moveFileIdx + m_moveDir; - QString mcFile1 = m_printFileDir + QString::number(cRow+1); - QDir fileDir1(mcFile1); - - //对要交换的文件夹重命名 - oldName = mcFile1; - newName = mcFile; - fileDir1.rename(oldName,newName); - - //再对选中的文件夹重命名 - QString mcFile2 = mcFile.left(mcFile.size()-1); - QDir fileDir2(mcFile1); - oldName = mcFile2; - newName = mcFile1; - fileDir2.rename(oldName,newName); - } - - m_moveFileIdx = -1; - m_moveDir = 0; - } + m_mcPrintInfo->m_mcWorkState = Busying; m_curBmpBlockIdx++;//一个文件可分为若干个位图块,位图块索引++ if(m_curBmpBlockIdx < 0) @@ -596,15 +389,65 @@ void CreatPrintBmp::slotCreatNextBmpBlockDat() m_curBmpBlockIdx = 0; } - if(m_curBmpBlockIdx >= m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks * m_mcPrintInfo->m_filesList[m_curFileIdx].m_printNum) + if(m_curBmpBlockIdx >= m_mcPrintInfo->m_filesList[m_fileBegIdx].m_totalBlocks) { - m_curFileIdx++;//文件索引++ - creatFileListDatAndSend(m_curFileIdx); - m_curBmpBlockIdx = -1; + m_listFileIdx++;//文件索引++ + int flag = 0; + if(m_listFileIdx >= m_fileEndIdx) + { + m_mcPrintInfo->m_mcWorkState = NotBusy;//机器完成打印 + m_mcPrintInfo->m_filesList[m_fileBegIdx].m_printedBlockNum = m_mcPrintInfo->m_filesList[m_fileBegIdx].m_totalBlocks; + m_mcPrintInfo->m_mcSendProgress = 100.0; + flag = 1; + } + emit siOneFilePrintFinished(m_mcPrintInfo->m_mcNum,m_fileBegIdx,flag); + //如果为自动绘图目录中的文件,删除自动绘图目录文件夹中已打印完成的文件 + QString filePath = m_mcPrintInfo->m_filesList[m_fileBegIdx].m_filePath; + QDir apppath(qApp->applicationDirPath()); + QString iniName = "MachineNo" + QString::number(m_mcPrintInfo->m_mcNum) + ".ini"; + QString iniPath = apppath.path() + apppath.separator() + iniName; + QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来 + QFileInfo info(filePath); + QString autoFilePath = setting.value("AutoPrintDir/fileDir").toString() + apppath.separator() + info.fileName(); + QFile file(autoFilePath); + if(file.exists()) + { + //文件存在 + QFile::remove(autoFilePath); + if(m_fileBegIdx < m_autoDirFilesList.size()) + { + m_autoDirFilesList.removeAt(m_fileBegIdx);//删除自动绘图目录文件列表中的文件 + } + } + + //m_mcPrintInfo->m_filesList.removeAt(m_fileBegIdx);//删除机器文件列表中已打印完成的文件 + +#if(0) + //删除此文件的位图存储文件夹 + QString bmpPath = m_printFileDir + QString::number(m_listFileIdx+1); + QDir bmpDir(bmpPath);//对应每台机器的每个文件打印目录 + if(bmpDir.exists()) + { + bmpDir.removeRecursively(); + } +#endif + + if(m_listFileIdx >= m_fileEndIdx) + { + return; + } + +// if(flag == 1) +// { +// return; +// } +// creatFileListMarker(m_fileBegIdx); +// creatFileListDatAndSend(m_fileBegIdx); +// m_curBmpBlockIdx = -1; return; } - creatBmpBlockDatAndSend(m_curBmpBlockIdx); + creatBmpBlockDatAndSend(m_fileBegIdx,m_curBmpBlockIdx); m_conpressDir *= -1; } @@ -653,8 +496,8 @@ void CreatPrintBmp::setMcPrintInfo(int fileIdx, McPrintInfo *printInfo) m_fileBegIdx = fileIdx; } - //自动打印 - int autoPrint = 1; + //是否自动打印 + int autoPrint = 0; if(autoPrint == 1) { @@ -665,75 +508,154 @@ void CreatPrintBmp::setMcPrintInfo(int fileIdx, McPrintInfo *printInfo) m_fileEndIdx = m_fileBegIdx + 1; } - m_curFileIdx = m_fileBegIdx; + m_listFileIdx = m_fileBegIdx; QDir apppath(qApp->applicationDirPath()); QString printPath = apppath.path() + apppath.separator() + PRINTDIR; QString mcFile = printPath + apppath.separator() + PRINTMCDIR + QString::number(m_mcPrintInfo->m_mcNum); m_printFileDir = mcFile + apppath.separator() + PRINTFILEDIR; + m_workState = WORK_START; + + m_autoDirFilesList.clear(); + if(m_mcPrintInfo->m_loadFileFinishFlag < 0) + { + QString iniName = "MachineNo" + QString::number(m_mcPrintInfo->m_mcNum) + ".ini"; + QString iniPath = apppath.path() + apppath.separator() + iniName; + QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来 + QString dirPath = setting.value("AutoPrintDir/fileDir").toString(); + QDir dir(dirPath); + if(dir.exists()) + { + QStringList filter; + filter << QString("*.plt") << QString("*.PLT") + << QString("*.png") << QString("*.PNG") + << QString("*.bmp") << QString("*.BMP") + << QString("*.jpg") << QString("*.JPG"); + m_autoDirFilesList = dir.entryInfoList(filter, QDir::Files | QDir::NoSymLinks); + } + } + + QDir printDir(printPath);//总的打印目录 + if(!printDir.exists()) + { + printDir.mkdir(printPath); + } + QDir mcDir(mcFile);//对应每台机器打印目录 + if(!mcDir.exists()) + { + mcDir.mkdir(mcFile); + } + m_curBmpBlockIdx = -1;//当前生成数据的位图块数索引 } -void CreatPrintBmp::setDeleteFile(int fileIdx) +void CreatPrintBmp::stopCreatPrintDat() { - if(fileIdx == m_curFileIdx) + m_workState = WORK_PAUSE; +} + +void CreatPrintBmp::setDeleteFile(McPrintInfo *printInfo, int fileIdx) +{ + if(m_mcPrintInfo == NULL) + { + m_mcPrintInfo = printInfo; + } + + if(fileIdx == m_fileBegIdx) { return; } m_deleteFileIdx = fileIdx; - //空闲时的删除文件操作 - if(m_mcPrintInfo->m_mcWorkState == NotBusy) + + if(m_deleteFileIdx != m_fileBegIdx && m_deleteFileIdx != -1) { int length = (m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.right() - m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.left())/M_IDPMM; m_mcPrintInfo->m_fileTotalLength -= length; - m_mcPrintInfo->m_filesList[m_deleteFileIdx].clear(); - m_mcPrintInfo->m_filesList.removeAt(m_deleteFileIdx); + QString mcFile = m_printFileDir + QString::number(m_deleteFileIdx+1); QDir fileDir(mcFile); if(fileDir.exists()) { //删除位图文件夹 - QFileInfoList fileList = fileDir.entryInfoList(QDir::Files); - for(int i = 0; i < fileList.size(); i++) - { - QString fileStr = fileList[i].filePath(); - QFile::remove(fileStr); - } - fileDir.rmdir(mcFile); + fileDir.removeRecursively(); } + //如果为自动绘图目录中的文件,删除自动绘图目录文件夹中已打印完成的文件 + QString filePath = m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_filePath; + QDir apppath(qApp->applicationDirPath()); + QString iniName = "MachineNo" + QString::number(m_mcPrintInfo->m_mcNum) + ".ini"; + QString iniPath = apppath.path() + apppath.separator() + iniName; + QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来 + QString dirPath = setting.value("AutoPrintDir/fileDir").toString(); + QDir dir(dirPath); + if(dir.exists(filePath)) + { + //文件存在 + QFile::remove(filePath); + if(m_deleteFileIdx < m_autoDirFilesList.size()) + { + m_autoDirFilesList.removeAt(m_deleteFileIdx);//删除自动绘图目录文件列表中的文件 + } + } + + m_mcPrintInfo->m_filesList[m_deleteFileIdx].clear(); + m_mcPrintInfo->m_filesList.removeAt(m_deleteFileIdx); + m_mcPrintInfo->m_fileNums = m_mcPrintInfo->m_filesList.size(); m_deleteFileIdx = -1; - emit siDeleteFileFinish(); } } -void CreatPrintBmp::setMoveFile(int fileIdx, int dir) +void CreatPrintBmp::setMoveFile(McPrintInfo *printInfo, int fileIdx, int dir) { - if(fileIdx == m_curFileIdx) + if(m_mcPrintInfo == NULL) + { + m_mcPrintInfo = printInfo; + } + + if(fileIdx == m_fileBegIdx) { return; } m_moveFileIdx = fileIdx;//上下移动打印文件索引 m_moveDir = dir;//-1,上移 1,下移 - //空闲时的移动文件操作 - if(m_mcPrintInfo->m_mcWorkState == NotBusy) + //非正在打印的文件,正在发送文件时的上下移操作 + if(m_moveFileIdx != m_fileBegIdx && m_moveFileIdx != -1 && m_moveDir != 0) { //交换列表 McFilesInfo info = m_mcPrintInfo->m_filesList[fileIdx]; + QFileInfo fileInfo; + if(fileIdx < m_autoDirFilesList.size()) + { + fileInfo = m_autoDirFilesList[fileIdx]; + } McFilesInfo cInfo; + QFileInfo cFileInfo; if(dir == -1) { cInfo = m_mcPrintInfo->m_filesList[fileIdx-1]; m_mcPrintInfo->m_filesList[fileIdx-1] = info; + + cFileInfo = m_autoDirFilesList[fileIdx-1]; + m_autoDirFilesList[fileIdx-1] = fileInfo; } else { cInfo = m_mcPrintInfo->m_filesList[fileIdx+1]; m_mcPrintInfo->m_filesList[fileIdx+1] = info; + + if(fileIdx+1 < m_autoDirFilesList.size()) + { + cFileInfo = m_autoDirFilesList[fileIdx+1]; + m_autoDirFilesList[fileIdx+1] = fileInfo; + } } m_mcPrintInfo->m_filesList[fileIdx] = cInfo; + if(fileIdx < m_autoDirFilesList.size()) + { + m_autoDirFilesList[fileIdx] = cFileInfo; + } m_moveFileIdx = -1;//上下移动打印文件索引 m_moveDir = 0;//-1,上移 1,下移 diff --git a/machine/bmp/creatprintbmp.h b/machine/bmp/creatprintbmp.h index 33e86fd..007e4cf 100644 --- a/machine/bmp/creatprintbmp.h +++ b/machine/bmp/creatprintbmp.h @@ -14,30 +14,15 @@ #include "bwbmp.h" #include "machine/printinfo/mcfiles.h" #include "datafile/hpgl/importhpgl.h" +#include "datafile/view/drawdata.h" -#define TYPE_FILE 0 -#define TYPE_IMAGE 1 #define PIXMAPWIDTH 1200 #define PENWIDTH 5 -#define START 1 -#define PAUSE 0 - #define PRINTDIR "print" #define PRINTMCDIR "mc" #define PRINTFILEDIR "file" -typedef struct -{ - u32 blkIdx; // 当前位图块号(位图分块后的编号) - u32 biWidth; // 本块位图有效宽度,以像素为单位 - u32 biHeight; // 本块位图有效高度,以像素为单位 - u32 begPosY; // 本块起始位置(像素单位) - u32 endPosY; // 本块结束位置(像素单位) - u8 compType; // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩; - u8 compDir; // 本块位图压缩方向, =0, 从上到下; =1, 从下到上;(喷墨方向) -}__attribute__ ((packed)) BmpDatInfo; - class CreatPrintBmp : public QObject { Q_OBJECT @@ -49,26 +34,25 @@ private: QPicture m_picture;//绘图路径-线段 QString m_savePath; int m_workState; - int m_beginPrintFileIdx;//开始打印文件索引 int m_deleteFileIdx;//删除打印文件索引 McPrintInfo *m_mcPrintInfo;//机器信息 - int m_fileBegIdx; + int m_fileBegIdx;//开始打印和正在打印文件索引(因为打印完成一个就要删掉一个,所以正在打印的文件永远是起始文件索引) int m_fileEndIdx; - int m_curFileIdx;//当前生成数据的文件索引 + int m_listFileIdx;//初始文件列表时将要生成文件数据的文件索引 int m_curBmpBlockIdx;//当前生成数据的位图块数索引 int m_conpressDir;//压缩方向 QString m_printFileDir;//打印文件目录 int m_moveFileIdx;//上下移动打印文件索引 s16 m_moveDir;//-1,上移 1,下移 + double m_rotateAngle; + + QFileInfoList m_autoDirFilesList;//自动绘图目录中文件列表 private: - int creatFileListMarker();//加载文件列表marker数据 - void creatMarkerDat(McFilesInfo &curFilesInfo, QString filePath, int fileIdx);//创建Marker数据 - QPicture getPicture(Marker marker,int penWidth = 1); - + int creatFileListMarker(int idx);//加载文件列表marker数据 int creatFileListDatAndSend(int idx);//创建文件列表数据并发送 - int creatBmpBlockDatAndSend(int idx);//创建位图块数据并发送 + int creatBmpBlockDatAndSend(int fileidx, int idx);//创建位图块数据并发送 public: void setPicture(QPicture pic); @@ -76,14 +60,17 @@ public: void setSavePath(QString path); QString getSavePath(); void setMcPrintInfo(int fileIdx,McPrintInfo *printInfo);//设置机器信息 - void setDeleteFile(int fileIdx);//删除文件 - void setMoveFile(int fileIdx, int dir = -1);//上下移动文件 + void stopCreatPrintDat();//停止生成打印数据 + void setDeleteFile(McPrintInfo *printInfo, int fileIdx);//删除文件 + void setMoveFile(McPrintInfo *printInfo, int fileIdx, int dir = -1);//上下移动文件 + inline void setRotateAngle(double angle){m_rotateAngle = angle;}//设置旋转角度 signals: void siCreatOneBmpFinished(int mcIdx,unsigned char *dat,int datSize); void siSendFileListDatToMc(int idx); - void siSendDatToMc(QByteArray dat, BmpDatInfo bmpInfo); - void siDeleteFileFinish();//删除文件完成 + void siSendDatToMc(QByteArray dat); + void siOneFilePrintFinished(int mcNum,int fileIdx,int refreshFlag);//一个文件打印完成 + void siRefreshPrintProgress(int mcNum,int fileIdx);//刷新打印进度 public slots: void slotCreatBmp(); diff --git a/machine/comm/protocol.h b/machine/comm/protocol.h index bf4e492..ac80efc 100644 --- a/machine/comm/protocol.h +++ b/machine/comm/protocol.h @@ -76,6 +76,7 @@ #define WORK_START 0x0001 // 启动工作 #define WORK_PAUSE 0x0002 // 暂停工作 +#pragma pack(1)//设定为1字节对齐 // 喷墨图像按照黑白位图的格式存储 @@ -100,39 +101,77 @@ typedef struct u32 rev[16-5]; }__attribute__ ((packed)) PlotFileList; -// 自定义压缩位图文件头 +// 压缩位图文件头 typedef struct { // 0 - u32 fileId; // 整个位图文件标识 - u32 blkIdx; // 当前位图块号(位图分块后的编号) - u32 datSize; // 本块位图数据区的大小(字节数) - u32 biWidth; // 本块位图有效宽度,以像素为单位 - u32 biHeight; // 本块位图有效高度,以像素为单位 - u32 dataChecksum; // 本块位图数据累加校验和 - u32 begPosY; // 本块起始位置(像素单位) - u32 endPosY; // 本块结束位置(像素单位) + u32 fileId; // 整个位图文件标识 + u32 blkIdx; // 当前位图块号(位图分块后的编号) + u32 datSize; // 本块位图数据区的大小(字节数) + u32 biWidth; // 本块位图有效宽度,以像素为单位 + u32 biHeight; // 本块位图有效高度,以像素为单位 + u32 dataChecksum; // 本块位图数据累加校验和 + u32 begPosY; // 本块位图起始位置(像素单位) + u32 endPosY; // 本块位图结束位置(像素单位) // 32 - u8 compType; // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩; - u8 compDir; // 本块位图压缩方向, =0, 从上到下; =1, 从下到上;(喷墨方向) + u16 compDir; // 本块位图压缩方向, =0, 从上到下; =1, 从下到上;(喷墨方向) + u16 compSegWidth; // 分段宽度(0,默认整个宽度,分段宽度必须能被本块位图有效宽度整除) + u16 compSegHeight; // 分段高度(0,默认1行的高度) + u16 compFillWidth; // 压缩填充位数 + u8 compType[4]; // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩(分段压缩); + u32 compSegOffset[4]; // 分段数据起始位置 - // 34 - u8 rev[64-2-34]; // 保留 +#if (1) + // 60 + u8 rev[128-2-60]; // 保留 +#else + // 保存原图中BMP头文件(算法测试用) + // 60 + u8 rev[64-60]; // 保留 - // 62 - u16 checkCrc; // 前面字段的CRC校验 + // 64 + u16 identifier; // 类型 一般为 "BM" + u32 fileSize; // 文件大小 + u32 reserved; // 保留 + u32 bitDatOffset; // 位图数据偏移,一般为 0x3E + // 78 + u32 biSize; // 位图信息头大小, 一般为 0x28 + u32 biWidth2; // 位图宽度,以像素为单位 + u32 biHeight2; // 位图高度,以像素为单位 + u16 biPlanes; // 位图的位面数,必须为1 + + // 92 + u16 biBitPerPixel; // 每个像素的位数, =1, 单色位图; =4, 16色; = 8, 256色; = 24 真彩色 + u32 biCompression; // 位图压缩类型, =0, 不压缩(BI_RGB); =1, BI_RLE8; = 2, BI_RLE4; = 3 BI_BITFIELDS; = 4, BI_JPEG; = 5, BI_PNG + u32 biBitmapDatSize;// 位图数据区的大小(字节数), 必须是4的整数倍 + + // 102 + u32 biHResolution; // 水平分辨率, 像素/米 + u32 biVResolution; // 垂直分辨率, 像素/米 + u32 biColors; // 颜色数 + u32 biImpColors; // 重要颜色数 + + // 118 + BmpRgbQuad palette[2]; // 调色板 + + // 126 + //u8 rev2[128-2-126]; // 保留 + +#endif + // 126 + u16 checkCrc; // 前面字段的CRC校验 }__attribute__ ((packed)) CompBmpHead; // 机器信息结构定义 typedef struct { // 0 - char softwareVerStr[32]; // 软件版本 + char softwareVerStr[32]; // 软件版本 // 32 - char rev[1024-32]; + char rev[1024-32]; } __attribute__ ((packed)) MCInfo; @@ -190,29 +229,29 @@ typedef struct { // 0 u32 workStatus; // 工作状态位图 - // .0 允许时限。=0,使用时限已到,不允许下位机工作;=1,允许下位机工作; - // .1 允许状态。=0,界面钳制,不允许下位机工作;=1,允许下位机工作; - // .2 机器状态。=0,手动工作状态; =1,自动工作状态 - // .3 钥匙状态。=0,关闭状态; =1,打开状态 - // .4 文件接收标志。= 0,初始状态。= 1,收到了文件 - // .5 参数接收标志。= 0,初始状态。= 1,收到了参数 - // .6 正在忙标志。= 0,空闲(可以接收文件和参数)。= 1,工作中(不会接收文件和参数) - // .7 上料状态。=0,手动上料状态; =1,自动上料状态 - // .8 参数更新标志。 =1,下位机更新了参数 - // .9 模拟工作标志。=1, 处于模拟工作状态 - // .10 允许扫描条码状态。=1, 允许 - // .11 允许拍照状态。=1, 允许 - // .12 正在工作标志 - // .13 传感信号扫描中标志 - // .14 相机校准模式中标志 - // .15 - // .16 - // .17 - // .18 - // .19 取模板框状态 - // .20 放模板框状态 - // .21 匹绣, 0:退出匹绣,主轴归零 1:进入匹绣,扎针,允许移框 - // .22 断线检测, 0:退出断线检测状态, 1:进入断线检测状态 + // .0 允许时限。=0,使用时限已到,不允许下位机工作;=1,允许下位机工作; + // .1 允许状态。=0,界面钳制,不允许下位机工作;=1,允许下位机工作; + // .2 机器状态。=0,手动工作状态; =1,自动工作状态 + // .3 钥匙状态。=0,关闭状态; =1,打开状态 + // .4 文件接收标志。= 0,初始状态。= 1,收到了文件 + // .5 参数接收标志。= 0,初始状态。= 1,收到了参数 + // .6 正在忙标志。= 0,空闲(可以接收文件和参数)。= 1,工作中(不会接收文件和参数) + // .7 上料状态。=0,手动上料状态; =1,自动上料状态 + // .8 参数更新标志。 =1,下位机更新了参数 + // .9 模拟工作标志。=1, 处于模拟工作状态 + // .10 允许扫描条码状态。=1, 允许 + // .11 允许拍照状态。=1, 允许 + // .12 正在工作标志 + // .13 传感信号扫描中标志 + // .14 相机校准模式中标志 + // .15 + // .16 + // .17 + // .18 + // .19 取模板框状态 + // .20 放模板框状态 + // .21 匹绣, 0:退出匹绣,主轴归零 1:进入匹绣,扎针,允许移框 + // .22 断线检测, 0:退出断线检测状态, 1:进入断线检测状态 // 1 u32 errorCode; // 错误代码 diff --git a/machine/machine.cpp b/machine/machine.cpp index 2742b2f..8d3bd2e 100644 --- a/machine/machine.cpp +++ b/machine/machine.cpp @@ -99,8 +99,6 @@ Machine::Machine(QObject *parent) : QObject(parent) m_pSendTimer->setInterval(100); // 设置定时间隔100毫秒 connect(m_pSendTimer, SIGNAL(timeout()), this, SLOT(onSendTimer())); initDataExFuns(); - - qRegisterMetaType("BmpDatInfo");//对自定义类型注册 } Machine::~Machine() @@ -400,12 +398,12 @@ void Machine::mcWorkCmd(int workcode, int para1, int para2) void Machine::deleteFilePrintDat(int fileIdx) { - m_pCreatPrintDat->setDeleteFile(fileIdx); + m_pCreatPrintDat->setDeleteFile(&m_mcPrintInfo,fileIdx); } void Machine::moveFilePrintDat(int fileIdx,int dir) { - m_pCreatPrintDat->setMoveFile(fileIdx,dir); + m_pCreatPrintDat->setMoveFile(&m_mcPrintInfo,fileIdx,dir); } void Machine::invalidateWorkFile(int idx) @@ -413,12 +411,21 @@ void Machine::invalidateWorkFile(int idx) setMcStatus(MC_INVALID_FILE, idx); } -void Machine::creatPrintDat(int fileIdx) +void Machine::creatPrintDat(int fileIdx,int setFlag) { - m_pCreatPrintDat->setMcPrintInfo(fileIdx,&m_mcPrintInfo); + if(setFlag == 1) + { + m_pCreatPrintDat->setMcPrintInfo(fileIdx,&m_mcPrintInfo); + } emit siCreatData(); } +void Machine::stopPrint() +{ + m_pCreatPrintDat->stopCreatPrintDat(); + m_transBreak = 1; +} + void Machine::setIpAndPort(QString mcName, QString serverIp, quint16 serverPort, QString localIp, quint16 localPort) { m_mcName = mcName; @@ -445,18 +452,21 @@ void Machine::startCommunication() m_pCreatPrintDat->moveToThread(m_pTcpBmpThread); connect(m_pTcpBmpThread, SIGNAL(finished()), m_pCreatPrintDat, SLOT(deleteLater()) ); // 退出删除对象 connect(this, SIGNAL(siCreatData()), - m_pCreatPrintDat, SLOT(slotCreatBmp()), Qt::QueuedConnection); // 发送数据的槽 + m_pCreatPrintDat, SLOT(slotCreatBmp()), Qt::QueuedConnection); // 开始创建位图的槽 connect(this, SIGNAL(siSendDataDone()), - m_pCreatPrintDat, SLOT(slotCreatNextBmpBlockDat()), Qt::QueuedConnection); // 发送数据的槽 + m_pCreatPrintDat, SLOT(slotCreatNextBmpBlockDat()), Qt::QueuedConnection); // 创建位图块并发送的槽 connect(this, SIGNAL(siCreatBmpBlockDatAndSend()), - m_pCreatPrintDat, SLOT(slotCreatNextBmpBlockDat()), Qt::QueuedConnection); // 发送数据的槽 + m_pCreatPrintDat, SLOT(slotCreatNextBmpBlockDat()), Qt::QueuedConnection); // 创建位图块并发送的槽 connect(m_pCreatPrintDat, SIGNAL(siSendFileListDatToMc(int)), - this, SLOT(slotSendPlotFileListToMc(int)), Qt::QueuedConnection); // 发送数据的槽 - connect(m_pCreatPrintDat, SIGNAL(siSendDatToMc(QByteArray,BmpDatInfo)), - this, SLOT(slotSendDatToMc(QByteArray,BmpDatInfo)), Qt::QueuedConnection); // 发送数据的槽 - connect(m_pCreatPrintDat, SIGNAL(siDeleteFileFinish()), - this, SIGNAL(siDeleteFileFinish())); // 删除文件 + this, SLOT(slotSendPlotFileListToMc(int)), Qt::QueuedConnection); // 发送文件列表的槽 + connect(m_pCreatPrintDat, SIGNAL(siSendDatToMc(QByteArray)), + this, SLOT(slotSendDatToMc(QByteArray)), Qt::QueuedConnection); // 发送数据的槽 + + connect(m_pCreatPrintDat, SIGNAL(siOneFilePrintFinished(int,int,int)), + this, SIGNAL(siOneFilePrintFinished(int,int,int)), Qt::AutoConnection); // 完成一个文件的打印 + connect(m_pCreatPrintDat, SIGNAL(siRefreshPrintProgress(int,int)), + this, SIGNAL(siRefreshPrintProgress(int,int)), Qt::AutoConnection); // 刷新打印进度 m_pTcpBmpThread->start(); // 启动线程 } @@ -957,7 +967,7 @@ void Machine::onSendTimer() } } -void Machine::slotSendDatToMc(QByteArray dat, BmpDatInfo bmpInfo) +void Machine::slotSendDatToMc(QByteArray dat) { if(m_connected == Connected) { @@ -970,6 +980,11 @@ void Machine::slotSendDatToMc(QByteArray dat, BmpDatInfo bmpInfo) int counter = 0; delayTime.start(); + if (m_transCtrl.filetransing != 0) // 已经有文件在传输 + { + return; + } + while (m_transCtrl.filetransing != 0) // 已经有文件在传输 { if (delayTime.elapsed() > 1000) @@ -984,18 +999,9 @@ void Machine::slotSendDatToMc(QByteArray dat, BmpDatInfo bmpInfo) qDebug()<<"dat.size()"<fileId = m_pPlotFileList->fileId; - m_pCompBmpHead->blkIdx = bmpInfo.blkIdx; - m_pCompBmpHead->datSize = dat.size(); - m_pCompBmpHead->biWidth = bmpInfo.biWidth; - m_pCompBmpHead->biHeight = bmpInfo.biHeight; - m_pCompBmpHead->begPosY = bmpInfo.begPosY; - m_pCompBmpHead->endPosY = bmpInfo.endPosY; - m_pCompBmpHead->compType = bmpInfo.compType; - m_pCompBmpHead->compDir = bmpInfo.compDir; - m_pCompBmpHead->dataChecksum = calcCheckSum32((u8*)dat.data() , dat.size()); // 数据累加校验和 - int len = sizeof(m_pCompBmpHead)-sizeof(m_pCompBmpHead->checkCrc); - m_pCompBmpHead->checkCrc = calcCrc16((u8*)m_pCompBmpHead, len); // 前面字段的CRC校验 if (m_pCompBmpHead->datSize <= 0 || m_pCompBmpHead->datSize > MAX_FILE_SIZE) { @@ -1008,7 +1014,7 @@ void Machine::slotSendDatToMc(QByteArray dat, BmpDatInfo bmpInfo) m_transCtrl.fileType = (u8)FILE_TYPE_PLOT; m_transCtrl.fileId = m_pCompBmpHead->fileId; memcpy(m_transCtrl.pBmpHead, m_pCompBmpHead, sizeof(CompBmpHead)); - memcpy(m_transCtrl.pDatBuff, dat, m_pCompBmpHead->datSize); + memcpy(m_transCtrl.pDatBuff, dat.data()+sizeof(CompBmpHead), m_pCompBmpHead->datSize); m_transCtrl.packetSize = MAX_EXDP_LEN; m_transCtrl.packetNum = (m_pCompBmpHead->datSize + MAX_EXDP_LEN - 1) / MAX_EXDP_LEN; @@ -1034,8 +1040,8 @@ void Machine::slotSendPlotFileListToMc(int idx) u32 id =qrand() % (UINT16_MAX);//产生0到UINT16_MAX的随机数 m_pPlotFileList->fileId = id; m_pPlotFileList->totalWidth = (m_mcPrintInfo.m_filesList[idx].m_pic.width() - oft) * m_mcPrintInfo.m_filesList[idx].m_printNum; - m_pPlotFileList->totalHeight = m_mcPrintInfo.m_filesList[idx].m_pic.height() * m_mcPrintInfo.m_filesList[idx].m_printNum; - m_pPlotFileList->blkNums = m_mcPrintInfo.m_filesList[idx].m_totalBlocks * m_mcPrintInfo.m_filesList[idx].m_printNum; + m_pPlotFileList->totalHeight = m_mcPrintInfo.m_filesList[idx].m_pic.height(); + m_pPlotFileList->blkNums = m_mcPrintInfo.m_filesList[idx].m_totalBlocks; m_pPlotFileList->blkWidth = PIXMAPWIDTH; int rslt; diff --git a/machine/machine.h b/machine/machine.h index e46aeb2..2a407df 100644 --- a/machine/machine.h +++ b/machine/machine.h @@ -104,7 +104,9 @@ public: // 机器工作命令 void mcWorkCmd(int workcode, int para1 = 0 , int para2 = 0); - void creatPrintDat(int fileIdx); //生成打印数据 + void creatPrintDat(int fileIdx,int setFlag = 1); //生成打印数据 + void stopPrint(); //停止打印 + void deleteFilePrintDat(int fileIdx);//删除文件打印数据 void moveFilePrintDat(int fileIdx,int dir = -1);//移动(上下移)文件打印数据 @@ -122,15 +124,15 @@ signals: void siTransProgress(u8 fileType, int send, int total); // 文件传输结果信号 void siCreatData(); //生成要发送的数据 void siCreatBmpBlockDatAndSend();//生成位图数据块数据并发送 - void siDeleteFileFinish(); - void siMoveFileFinish(); + void siOneFilePrintFinished(int mcNum, int fileIdx, int refreshFlag);//完成一个文件的打印 + void siRefreshPrintProgress(int mcNum, int fileIdx);//刷新打印进度 private slots: void slotConnectSta(int sta); // 连接状态改变的槽函数 void slotConnectErr(QString errinfo); // 接收到通讯错误槽函数 void slotReceiveData(QByteArray dat); // 接收到数据的槽函数 void onSendTimer(void); - void slotSendDatToMc(QByteArray dat, BmpDatInfo bmpInfo);//发送打印数据 + void slotSendDatToMc(QByteArray dat);//发送打印数据 void slotSendPlotFileListToMc(int idx);//发送设置文件列表 public slots: diff --git a/machine/printinfo/mcfiles.h b/machine/printinfo/mcfiles.h index e3f6792..634bb27 100644 --- a/machine/printinfo/mcfiles.h +++ b/machine/printinfo/mcfiles.h @@ -23,6 +23,16 @@ enum WorkState Busying = 1 //工作中 }; +//打印状态 +enum PrintState +{ + Waitting = 0,//等待打印 + Printting = 1, //打印中 + Pause = 2, //暂停打印 + Complete = 3//打印完成 +}; + + class McFilesInfo { public: @@ -34,8 +44,9 @@ public: QRect m_fileRect;//图形被包络的矩形区域 s16 m_printNum;//打印份数 s16 m_startPoint;//打印起始点 - QString m_printState;//打印状态 - QPicture m_pic;//文件-图片 + s16 m_printState;//打印状态 + QPicture m_pic;//文件-发送的图片-实际笔宽绘制的pic + QPainterPath m_drawPath;//文件-数据绘图路径-用MyGraphicsItem画图时如果笔宽不为1,直接画QPicture时线条会很轻,所以用m_drawPath绘制 QBitmap m_pixmap;//图片-图片 s16 m_totalBlocks;//总块数 s16 m_curPrintBlock;//当前打印块数 @@ -47,6 +58,7 @@ public: void clear() { QPicture pic; + QPainterPath path; m_creatDataFlag = -1; m_creatBmpFlag = -1;//是否已经生成bmp的标志 @@ -55,8 +67,9 @@ public: m_fileType = 0;//文件类型 m_printNum = 0;//打印份数 m_startPoint = 0;//打印起始点 - m_printState.clear();//打印状态 + m_printState = Waitting;//打印状态 m_pic = pic; + m_drawPath = path; m_pixmap.clear(); m_totalBlocks = 0;//总块数 m_curPrintBlock = 0;//当前打印块数 @@ -75,7 +88,7 @@ public: m_fileType = 0;//文件类型 m_printNum = 0;//打印份数 m_startPoint = 0;//打印起始点 - m_printState.clear();//打印状态 + m_printState = Waitting;//打印状态 m_totalBlocks = 0;//总块数 m_curPrintBlock = 0;//当前打印块数 m_printedBlockNum = 0;//已打印块数 @@ -95,6 +108,7 @@ public: m_startPoint = item.m_startPoint;//打印起始点 m_printState = item.m_printState;//打印状态 m_pic = item.m_pic; + m_drawPath = item.m_drawPath; m_pixmap = item.m_pixmap; m_totalBlocks = item.m_totalBlocks;//总块数 m_curPrintBlock = item.m_curPrintBlock;//当前打印块数 @@ -116,6 +130,7 @@ public: m_startPoint = item.m_startPoint;//打印起始点 m_printState = item.m_printState;//打印状态 m_pic = item.m_pic; + m_drawPath = item.m_drawPath; m_pixmap = item.m_pixmap; m_totalBlocks = item.m_totalBlocks;//总块数 m_curPrintBlock = item.m_curPrintBlock;//当前打印块数 @@ -136,13 +151,12 @@ public: QString m_mcName;//机器名称 int m_mcConnState;//机器连接状态 int m_mcWorkState;//机器工作状态 - int m_mcSendProgress;//机器文件发送进度 + double m_mcSendProgress;//机器打印进度 int m_totalNums;//要发送的总块数 int m_sendedlNums;//已发送的总块数 QString m_ip;//机器ip s16 m_port;//机器端口 s16 m_fileNums;//文件数量 - s16 m_curCreatPrintDatFileIdx;//当前正在生成打印数据的文件索引 long long m_fileTotalLength;//文件总长度 QList m_filesList;//图片列表 @@ -160,7 +174,6 @@ public: m_port = 0; m_fileNums = 0; m_fileTotalLength = 0; - m_curCreatPrintDatFileIdx = -1; for(int i = 0; i < m_filesList.size(); i++) { m_filesList[i].clear(); @@ -183,7 +196,6 @@ public: m_port = 0; m_fileNums = 0; m_fileTotalLength = 0; - m_curCreatPrintDatFileIdx = -1; m_filesList.clear(); } @@ -201,7 +213,6 @@ public: m_port = item.m_port; m_fileNums = item.m_fileNums; m_fileTotalLength = item.m_fileTotalLength; - m_curCreatPrintDatFileIdx = -1; m_filesList = item.m_filesList; } @@ -221,7 +232,6 @@ public: m_port = item.m_port; m_fileNums = item.m_fileNums; m_fileTotalLength = item.m_fileTotalLength; - m_curCreatPrintDatFileIdx = -1; m_filesList = item.m_filesList; return *this; } diff --git a/main.cpp b/main.cpp index 78f03e2..bced116 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,25 @@ #include "main.h" #include "mainwindow.h" +QString switchLanguage(int language,QDir appPath) +{ + QString languagePath; + switch (language) + { + case chinese://中文 + languagePath = appPath.path() + appPath.separator() + "chinese.qm"; + break; + case english://英文 + languagePath = appPath.path() + appPath.separator() + "english.qm"; + break; + default://中文 + languagePath = appPath.path() + appPath.separator() + "chinese.qm"; + break; + } + + return languagePath; +} + int main(int argc,char *argv[]) { QApplication app(argc, argv); @@ -27,6 +46,14 @@ int main(int argc,char *argv[]) { settings.setValue("Local/ip","192.168.16.41"); settings.setValue("Local/port",5001); + + settings.setValue("DrawSet/rotate90",0);//是否正向旋转90度 + settings.setValue("DrawSet/vecfont",0);//是否使用矢量字体 + settings.setValue("DrawSet/linewidth",2);//线宽 + settings.setValue("DrawSet/paperwidth",2400);//纸张宽度 + settings.setValue("DrawSet/rightmargin",0);//右边距 + settings.setValue("DrawSet/markmargin",20);//马克间距 + settings.setValue("DrawSet/buttmargin",100);//对接符间距 } else { @@ -64,6 +91,14 @@ int main(int argc,char *argv[]) } } + //多语言翻译 + int language = 0; + language = settings.value("HMI/language").toInt(); + QString languageFile = switchLanguage(language,apppath); + g_pTranslator = new QTranslator(); + g_pTranslator->load(languageFile); + qApp->installTranslator(g_pTranslator); + MainWindow mainWi; mainWi.initAllWinForm(); mainWi.show(); diff --git a/main.h b/main.h index 46e4cd1..5addffa 100644 --- a/main.h +++ b/main.h @@ -11,16 +11,16 @@ //语言 enum Language { - LANGUAGE_CHINESE = 1, - LANGUAGE_ENGLISH = 2 + chinese = 1, + english = 2 }; #ifdef _IN_MAIN_CPP QList g_machineList; -int g_language; +QTranslator *g_pTranslator; #else extern QList g_machineList; -extern int g_language; +extern QTranslator *g_pTranslator; #endif #endif // MAIN_H diff --git a/mainwidget.ui b/mainwidget.ui deleted file mode 100644 index de18f75..0000000 --- a/mainwidget.ui +++ /dev/null @@ -1,24 +0,0 @@ - - - MainWidget - - - - 0 - 0 - 800 - 480 - - - - III PlotCenter - - - - File(F) - - - - - - diff --git a/mainwindow.cpp b/mainwindow.cpp index 3854bd5..9db5321 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -41,11 +41,6 @@ MainWindow::~MainWindow() delete m_printViewWi; } - if(m_sendTimer != NULL) - { - delete m_sendTimer; - } - if(m_pTimer != NULL) { delete m_pTimer; @@ -72,7 +67,17 @@ MainWindow::~MainWindow() void MainWindow::closeEvent(QCloseEvent *e) { - e->accept(); + if(QMessageBox::warning(this, + tr("Prompt"), + tr("Do you want to exit the program?"),//是否退出程序? + QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok) + { + e->accept(); + } + else + { + e->ignore(); + } } void MainWindow::reflushPreview(int row) @@ -82,19 +87,19 @@ void MainWindow::reflushPreview(int row) return; } - if(m_curFileRow >= g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList.size()) + if(row >= g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList.size()) { m_preView->cleanView(); m_tabelViewModelFile->removeRows(0,m_tabelViewModelFile->rowCount()); return; } - if(m_curFileRow < 0) + if(row < 0) { return; } - g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_selectBlockNum = 0;//上次查看的文件的块数选择置为0 + g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_selectBlockNum = 0;//上次查看的文件的块数选择置为0 m_curBlockRow = -1; ui->tableView_fileList->selectRow(row); @@ -103,10 +108,12 @@ void MainWindow::reflushPreview(int row) ui->tableView_fileList->setEnabled(false); ui->tableView_Connection->setEnabled(false); - //生成绘制图 - g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic = creatFilePicture(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row]); + int penWidth = m_pSettings->value("DrawSet/linewidth").toInt(); - //将picture保存为多个宽度为2400像素的bmp + //生成绘制图 + g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic = creatFilePicture(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row],penWidth); + + //将picture保存为多个宽度为PIXMAPWIDTH像素的bmp int num = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic.width() / PIXMAPWIDTH; int lwidth = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic.width() % PIXMAPWIDTH; if(lwidth != 0) @@ -122,9 +129,17 @@ void MainWindow::reflushPreview(int row) } //刷新图形 - QPicture pic = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic; m_preView->cleanView(); - m_preView->swithView(pic); + if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_fileType == TYPE_FILE) + { + QPainterPath path = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_drawPath; + m_preView->swithViewByPath(path); + } + else if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_fileType == TYPE_IMAGE) + { + QPicture pic = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic; + m_preView->swithViewByPic(pic); + } m_curFilesInfo = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row]; } @@ -142,6 +157,16 @@ void MainWindow::changeRowData(int move) return ; } + //判断是否正在打印,如果正在打印时不可移动 + if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_curPrintBlock != 0) + { + QMessageBox::warning(this, + tr("Prompt"), + tr("Printing this file, it cannot be moved!"),//正在打印此文件,不可移动! + QMessageBox::Ok); + return; + } + if(move == 1) { //下移需要判断最后一行,不移动 @@ -195,27 +220,6 @@ bool MainWindow::deleteDir(QString path) return dir.rmdir(dir.absolutePath()); // 删除文件夹 } -void MainWindow::setButtonEnable(bool bl) -{ - ui->actionOpen_File->setEnabled(bl); - ui->actionOpen_Image->setEnabled(bl); - ui->actiontest1_plt->setEnabled(bl); - ui->actionStart->setEnabled(bl); - ui->actionPause->setEnabled(bl); - ui->actionDelete->setEnabled(bl); - ui->actionDrawing_Setting->setEnabled(bl); - ui->actionPlotter_Setting->setEnabled(bl); - ui->actionOpenFileIcon->setEnabled(bl); - ui->actionOpenImageIcon->setEnabled(bl); - ui->actionStartIcon->setEnabled(bl); - ui->actionPauseIcon->setEnabled(bl); - ui->actionDrawingSetIcon->setEnabled(bl); - ui->pushButton_up->setEnabled(bl); - ui->pushButton_down->setEnabled(bl); - ui->pushButton_delete->setEnabled(bl); - ui->pushButton_preview->setEnabled(bl); -} - void MainWindow::startCreatBmpAndSend(int mcIdx) { int mcBegIdx, mcEndIdx; @@ -237,7 +241,8 @@ void MainWindow::startCreatBmpAndSend(int mcIdx) for(int i = mcBegIdx; i < mcEndIdx; i++) { - if(m_workState == WORK_PAUSE) + //全部启动的情况下,全部暂停时m_workState = WORK_PAUSE时返回 + if(m_workState == WORK_PAUSE && mcIdx == -1) { return; } @@ -255,6 +260,68 @@ void MainWindow::startCreatBmpAndSend(int mcIdx) mcDir.mkdir(mcFile); } g_machineList[i]->creatPrintDat(m_curFileRow); + + if(m_curFileRow > 0) + { + QString strPro = QString::number(0,'f',2)+"%"; + m_tabelViewModelConn->setData(m_tabelViewModelConn->index(i,CONN_COLUMN_MCPROGRESS),strPro); + } + } + + if(m_curFileRow > 0) + { + ui->progressBar_print->setValue(0); + ui->progressBar_print->setFormat(QString("%1%").arg(QString::number(0,'f',2))); + } + +// if(m_curMcIdx >= 0) +// { +// ui->tableView_fileList->selectRow(0); +// reflushPreview(0); +// } +} + +void MainWindow::stopPrint(int mcIdx) +{ + int mcBegIdx, mcEndIdx; + mcBegIdx = mcEndIdx = 0; + + //自动打印时mcIdx为-1 + //mcIdx = -1; + + if(mcIdx == -1) + { + mcBegIdx = 0; + mcEndIdx = g_machineList.size(); + } + else + { + mcBegIdx = mcIdx; + mcEndIdx = mcIdx + 1; + } + + for(int i = mcBegIdx; i < mcEndIdx; i++) + { + g_machineList[i]->stopPrint(); + } + + if(mcIdx >= 0) + { + if(mcIdx < g_machineList.size()) + { + g_machineList[mcIdx]->m_mcPrintInfo.m_mcWorkState = NotBusy; + QString str = tr("Idle");//空闲中 + m_tabelViewModelConn->setData(m_tabelViewModelConn->index(mcIdx,CONN_COLUMN_MCWORKSTATE),str); + } + if(m_curFileRow >= 0 && mcIdx < g_machineList.size()) + { + if(m_curFileRow < g_machineList[mcIdx]->m_mcPrintInfo.m_filesList.size()) + { + g_machineList[mcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_printState = Pause; + QString str = tr("Pause print");//暂停打印 + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(m_curFileRow,COLUMN_STATE),str); + } + } } } @@ -262,91 +329,19 @@ QPicture MainWindow::creatFilePicture(McFilesInfo & mcFileInfo, s16 penWidth) { //将图片画在picture上 QPicture pic; - QPen pen; - if(mcFileInfo.m_fileType == TYPE_FILE) - { - pen.setWidth(penWidth);//设置笔号 - } - else if(mcFileInfo.m_fileType == TYPE_IMAGE) - { - pen.setWidth(1);//设置笔号 - } - pen.setColor(QColor(Qt::black)); - - QPainter painter; - painter.begin(&pic); - painter.setPen(pen); - if(mcFileInfo.m_fileType == TYPE_IMAGE) { - painter.drawPixmap(0,0,mcFileInfo.m_pixmap); + pic = creatPictureByBmp(mcFileInfo.m_pixmap,penWidth); } else { - CBitmapInfo bitmapInfo; - QPainterPath painterPath; - QRect rect = mcFileInfo.m_marker.GetRect(); - int minX = rect.left(); - int minY = rect.top(); - int maxY = rect.bottom(); - - int nLineCount = mcFileInfo.m_marker.m_listPolyline.size(); - for(int i = 0; i < nLineCount; i++) - { - CRPPolyline polyLine = mcFileInfo.m_marker.m_listPolyline.at(i); - int type = polyLine.m_nDrawingType; - // if(polyLine.m_nDrawingType == 3)//文字 - // { - // CRPText text = polyLine.m_text; - // } - - if(type == 0)//直线 - { - int nPointCount = polyLine.m_listPoint.size(); - for(int j = 0; j < nPointCount; j++) - { - double x = (polyLine.m_listPoint.at(j).x() - minX)/(double)M_IDPMM*MMPIXELY; - double y = ((0 - (polyLine.m_listPoint.at(j).y() - minY))+(maxY-minY))/(double)M_IDPMM*MMPIXELY; - QPointF point(x,y); - - if(j == 0) - { - painterPath.moveTo(point); - } - else - { - painterPath.lineTo(point); - } - } - } - else if(type == 1)//位图 - { - bitmapInfo = polyLine.m_bitmapInfo; - int x = bitmapInfo.m_ptAbPostLU.x(); - int y = bitmapInfo.m_ptAbPostLU.y(); - - int nx = (x - minX)/M_IDPMM*MMPIXELY; - int ny = ((0 - (y - minY))+(maxY-minY))/M_IDPMM*MMPIXELY; - - bitmapInfo.m_ptAbPostLU.setX(nx); - bitmapInfo.m_ptAbPostLU.setY(ny); - } - } - - if(painterPath.isEmpty()) + pic = creatPictureByData(mcFileInfo.m_marker,mcFileInfo.m_drawPath,penWidth); + if(mcFileInfo.m_drawPath.isEmpty()) { qDebug()<<"painterPath.isEmpty"; } - - painter.drawPath(painterPath); - if(bitmapInfo.m_iBytes > 0)//有位图 - { - //bitmapInfo.m_pBitmap.save("D:\\1.bmp"); - painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap); - } } - painter.end(); return pic; } @@ -412,11 +407,13 @@ void MainWindow::refreshMcListShow() str = tr("Working");//工作中 } m_tabelViewModelConn->setData(m_tabelViewModelConn->index(row,CONN_COLUMN_MCWORKSTATE),str); - QString strPro = QString::number(g_machineList[i]->m_mcPrintInfo.m_mcSendProgress) + "%"; + QString strPro = QString::number(g_machineList[i]->m_mcPrintInfo.m_mcSendProgress,'f',2)+"%"; m_tabelViewModelConn->setData(m_tabelViewModelConn->index(row,CONN_COLUMN_MCPROGRESS),strPro); - connect(g_machineList[i], SIGNAL(siDeleteFileFinish()), - this, SLOT(slotDeleteFileFinish())); // 发送数据的槽 + connect(g_machineList[i], SIGNAL(siOneFilePrintFinished(int,int,int)), + this, SLOT(slotDeleteFileFromList(int,int,int)), Qt::AutoConnection); // 完成一个文件的打印 + connect(g_machineList[i], SIGNAL(siRefreshPrintProgress(int,int)), + this, SLOT(slotRefreshPrintProgress(int,int)), Qt::AutoConnection); // 刷新打印进度 } // m_curMcIdx = 0; // ui->tableView_Connection->selectRow(m_curMcIdx); @@ -448,7 +445,7 @@ void MainWindow::refreshOneMcShow(int row,int idx) str = tr("Working");//工作中 } m_tabelViewModelConn->setData(m_tabelViewModelConn->index(row,CONN_COLUMN_MCWORKSTATE),str); - QString strPro = QString::number(g_machineList[idx]->m_mcPrintInfo.m_mcSendProgress) + "%"; + QString strPro = QString::number(g_machineList[idx]->m_mcPrintInfo.m_mcSendProgress,'f',2)+"%"; m_tabelViewModelConn->setData(m_tabelViewModelConn->index(row,CONN_COLUMN_MCPROGRESS),strPro); } @@ -504,18 +501,38 @@ int MainWindow::refreshMcFileListShow(int idx) m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_PRINTEDLENGTH),"0mm"); + double val = 0; + if(filesList[i].m_totalBlocks != 0) + { + val = (double)filesList[i].m_printedBlockNum / (double)filesList[i].m_totalBlocks; + } + QString progress = QString::number(val,'f',2)+"%"; + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_PRINTPROGRESS),progress); + QString number = QString::number(filesList[i].m_printNum); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_NUMBERS),number); - //QString state = tr("Waitting"); - m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_STATE),filesList[i].m_printState); + QString str; + if(filesList[i].m_printState == Waitting) + { + str = tr("Waitting");//未打印 + } + else if(filesList[i].m_printState == Printting) + { + str = tr("Printting");//打印中 + } + + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_STATE),str); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_FILEPATH),filesList[i].m_filePath); } reflushMcFileInfo(); qDebug()<<"reflushMcFileInfo();"; - m_curFileRow = 0; + if(m_curFileRow < 0) + { + m_curFileRow = 0; + } ui->tableView_fileList->selectRow(m_curFileRow);//选中 reflushPreview(m_curFileRow); } @@ -538,14 +555,25 @@ void MainWindow::initAllWinForm() m_curPrintFileIdx = -1; m_curBlockRow = -1; m_preView = NULL; + m_rotateAngle = 0; - m_workState = PAUSE; + m_workState = WORK_PAUSE; m_printMode = NOAUTOPRINT; m_breakAutoLoadThread = 0; QDir apppath(qApp->applicationDirPath()); m_printPath = apppath.path() + apppath.separator() + "print"; + QString configfile; + configfile = apppath.path() + apppath.separator() + "config.ini"; + m_pSettings = new QSettings(configfile,QSettings::IniFormat); + bool rotate90 = m_pSettings->value("DrawSet/rotate90").toBool();//是否正向旋转90度 + if(rotate90 == true) + { + //90度为逆时针旋转,270度为顺时针旋转 + m_rotateAngle = 270; + } + m_preView = new MyGraphicsView(); ui->verticalLayout_drawing->addWidget(m_preView); @@ -557,11 +585,6 @@ void MainWindow::initAllWinForm() m_printInfoDlg = new PrintInfoDialog(); - m_sendTimer = new QTimer(this); - m_sendTimer->setInterval(100); // 设置定时间隔100毫秒 - connect(m_sendTimer, SIGNAL(timeout()), this, SLOT(onSendTimer())); - m_sendTimer->start(); - //定时器 m_pTimer = new QTimer(this); m_pTimer->setInterval(1000); // 设置定时间隔1秒 @@ -576,7 +599,7 @@ void MainWindow::initAllWinForm() //删除位图文件夹 deleteDir(m_printPath); - //setButtonEnable(false); + refreshBtnEnable(); } void MainWindow::iniViewModel() @@ -585,7 +608,7 @@ void MainWindow::iniViewModel() m_tabelViewModelFile = new QStandardItemModel(0, COLUMN_NUM, ui->tableView_fileList); QStringList header; //QString类型的List容器 header<setHorizontalHeaderLabels(header); ui->tableView_fileList->setModel(m_tabelViewModelFile); ui->tableView_fileList->setSelectionBehavior(QAbstractItemView::SelectRows);//单击选择一行 @@ -646,6 +669,7 @@ void MainWindow::slotAddNewFileToList(int newFlag) } else //新文件 { + s16 state = Waitting; int row = m_tabelViewModelFile->rowCount();//当前表格的行数 m_tabelViewModelFile->insertRow(row);//在最后一行的后面插入一行 m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_FILENAME),m_curFilesInfo.m_fileName); @@ -663,28 +687,46 @@ void MainWindow::slotAddNewFileToList(int newFlag) m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_PRINTEDLENGTH),"0mm"); + double val = 0; + if(m_curFilesInfo.m_totalBlocks != 0) + { + val = (double)m_curFilesInfo.m_printedBlockNum / (double)m_curFilesInfo.m_totalBlocks; + } + QString progress = QString::number(val,'f',2)+"%"; + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_PRINTPROGRESS),progress); + QString number = QString::number(m_printViewWi->getPrintNumber()); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_NUMBERS),number); - QString state = tr("Waitting"); - m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_STATE),state); + QString str; + if(state == Waitting) + { + str = tr("Waitting");//未打印 + } + else if(state == Printting) + { + str = tr("Printting");//打印中 + } + + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_STATE),str); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_FILEPATH),m_curFilesInfo.m_filePath); - m_preView->cleanView(); - if(m_curFilesInfo.m_fileType == TYPE_FILE) - { - m_preView->creatView(m_curFilesInfo.m_marker);//刷新显示 - } - else if(m_curFilesInfo.m_fileType == TYPE_IMAGE) - { - m_preView->creatView(m_curFilesInfo.m_pixmap);//刷新显示 - } + //m_preView->cleanView(); +// int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽 +// if(m_curFilesInfo.m_fileType == TYPE_FILE) +// { +// //刷新显示 +// m_curFilesInfo.m_pic = m_preView->getPictureByDat(m_curFilesInfo.m_marker,penWidth); +// m_curFilesInfo.m_drawPath = m_preView->getDrawPath(); +// } +// else if(m_curFilesInfo.m_fileType == TYPE_IMAGE) +// { +// m_curFilesInfo.m_pic = m_preView->getPictureByBmp(m_curFilesInfo.m_pixmap); +// } - //将view的图片添加到列表中 - m_curFilesInfo.m_pic = m_preView->getPicture(m_curFilesInfo.m_marker); m_curFilesInfo.m_creatBmpFlag = 1; - //将picture保存为多个宽度为2400像素的bmp + //将picture保存为多个宽度为PIXMAPWIDTH像素的bmp int num = m_curFilesInfo.m_pic.width() / PIXMAPWIDTH; int lwidth = m_curFilesInfo.m_pic.width() % PIXMAPWIDTH; if(lwidth != 0) @@ -707,42 +749,8 @@ void MainWindow::slotAddNewFileToList(int newFlag) McF.m_filesList.append(m_curFilesInfo); m_curFileRow = row; -#if(0) - //生成bmp块 - QDir printDir(m_printPath);//总的打印目录 - if(!printDir.exists()) - { - printDir.mkdir(m_printPath); - } - - QString mcFile = m_printPath + printDir.separator() + PRINTMCDIR + QString::number(m_curMcIdx+1); - QDir mcDir(mcFile);//对应每台机器打印目录 - if(!mcDir.exists()) - { - mcDir.mkdir(mcFile); - } - - QString filePath = mcFile + mcDir.separator() + PRINTFILEDIR + QString::number(row+1); - QDir fileDir(filePath);//对应每台机器的每个文件打印目录 - if(!fileDir.exists()) - { - fileDir.mkdir(filePath); - } - filePath = filePath + mcDir.separator(); - - m_creatBmpThread->setSavePath(filePath); - if(m_curFilesInfo.m_fileType == TYPE_FILE) - { - m_creatBmpThread->setPicture(m_preView->getPicture(m_curFilesInfo.m_marker,PENWIDTH)); - } - else if(m_curFilesInfo.m_fileType == TYPE_IMAGE) - { - m_creatBmpThread->setPicture(m_curFilesInfo.m_pixmap); - } - m_creatBmpThread->start(); -#endif - ui->tableView_fileList->selectRow(row);//选中 + ui->frame_fileBtn->setEnabled(true); if(g_machineList.size() <= 0) { @@ -755,6 +763,7 @@ void MainWindow::slotAddNewFileToList(int newFlag) g_machineList[m_curMcIdx]->m_mcPrintInfo.m_fileTotalLength += McF.m_fileTotalLength; g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList.append(m_curFilesInfo); } + reflushPreview(row); } reflushMcFileInfo(); } @@ -788,7 +797,6 @@ void MainWindow::slotFileListMenu(QPoint pos) if(m_curFileRow != row) { - m_curFileRow = row; reflushPreview(row); } m_curFileRow = row; @@ -818,8 +826,9 @@ void MainWindow::slotMcListMenu(QPoint pos) void MainWindow::slotPrintPreview() { + int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽 m_curFilesInfo = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow]; - m_printViewWi->refreshShow(m_curFilesInfo,0); + m_printViewWi->refreshShow(m_curFilesInfo,penWidth,0); } void MainWindow::slotPrintNumberSetDlgShow() @@ -871,40 +880,38 @@ void MainWindow::slotDeleteFile() return; } + //判断是否正在打印,如果正在打印时不可删除 + if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_curPrintBlock != 0 && + g_machineList[m_curMcIdx]->m_mcPrintInfo.m_mcWorkState == Busying) + { + QMessageBox::warning(this, + tr("Prompt"), + tr("Printing this file, it cannot be deleted!"),//正在打印此文件,不可删除! + QMessageBox::Ok); + return; + } + if(QMessageBox::warning(this, tr("Prompt"), tr("Do you want to delete this drawing?"),//是否删除该项绘图? QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok) { - //判断是否正在打印,如果正在打印时不可删除 - if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_curPrintBlock != 0) - { - QMessageBox::warning(this, - tr("Prompt"), - tr("Printing this file, it cannot be deleted!"),//正在打印此文件,不可删除! - QMessageBox::Ok); - return; - } - g_machineList[m_curMcIdx]->deleteFilePrintDat(m_curFileRow); + + m_tabelViewModelFile->removeRow(m_curFileRow); + m_preView->cleanView(); + + reflushMcFileInfo(); + + if(m_curFileRow >= g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList.size()) + { + m_curFileRow -= 1; + } + ui->tableView_fileList->selectRow(m_curFileRow); + reflushPreview(m_curFileRow); } } -void MainWindow::slotDeleteFileFinish() -{ - m_tabelViewModelFile->removeRow(m_curFileRow); - m_preView->cleanView(); - - reflushMcFileInfo(); - - if(m_curFileRow >= g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList.size()) - { - m_curFileRow -= 1; - } - ui->tableView_fileList->selectRow(m_curFileRow); - reflushPreview(m_curFileRow); -} - void MainWindow::slotDeleteMc() { if(QMessageBox::warning(this, @@ -945,57 +952,14 @@ void MainWindow::slotDeleteMc() //删除该机器的配置文件 QDir apppath(qApp->applicationDirPath()); - QString configfile; - configfile = apppath.path() + apppath.separator() + "config.ini"; - QSettings settings(configfile, QSettings::IniFormat); QString str = "MachineNo" + QString::number(m_curMcIdx+1); - settings.remove(str); + m_pSettings->remove(str); m_curMcIdx = -1; QString iniFilePath = apppath.path() + apppath.separator() + str + ".ini"; QFile::remove(iniFilePath); } } -void MainWindow::onSendTimer() -{ - //总块数或者已生成块数为0时返回 - // if(m_totalPieces <= 0 || g_createdPieces <= 0 || m_sendPiece == m_totalPieces) - // { - // return; - // } - - // if(m_workState == START) - // { - // ui->actionStart->setEnabled(false); - // ui->actionStartIcon->setEnabled(false); - // } - // else - // { - // ui->actionStart->setEnabled(true); - // ui->actionStartIcon->setEnabled(true); - // } - - //已生成的比发送的块数多 - //if(g_createdPieces > m_sendPiece) - { - //发送文件 - // if(g_pMachine != NULL) - // { - // if(g_pDatList.size() > m_sendPiece) - // { - // g_pMachine->sendFileProc(m_sendPiece, g_pDatList[m_sendPiece]); - // m_sendPiece++; - // } - // } - } - - // if(m_sendPiece == m_totalPieces) - // { - // ui->actionStart->setEnabled(true); - // ui->actionStartIcon->setEnabled(true); - // } -} - void MainWindow::slotLoadAutoPrintFiles() { QString iniName = "MachineNo" + QString::number(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_mcNum) + ".ini"; @@ -1047,6 +1011,7 @@ void MainWindow::slotLoadAutoPrintFiles() m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_WIDTH),width); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_START),start); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_PRINTEDLENGTH),"0mm"); + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_PRINTPROGRESS),"0.00%"); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_NUMBERS),number); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_STATE),state); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_FILEPATH),g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[i].m_filePath); @@ -1056,7 +1021,7 @@ void MainWindow::slotLoadAutoPrintFiles() } McFilesInfo curFilesInfo;//当前文件信息 - creatMarkerDat(curFilesInfo,filePath); + creatMarkerDat(curFilesInfo,m_printPath,filePath,-1,m_rotateAngle); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_FILENAME),curFilesInfo.m_fileName); QRect rect = curFilesInfo.m_fileRect; @@ -1066,6 +1031,7 @@ void MainWindow::slotLoadAutoPrintFiles() m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_WIDTH),width); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_START),start); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_PRINTEDLENGTH),"0mm"); + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_PRINTPROGRESS),"0.00%"); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_NUMBERS),number); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_STATE),state); m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_FILEPATH),curFilesInfo.m_filePath); @@ -1087,62 +1053,221 @@ void MainWindow::onOneSecondTimer() refConnectUi();//刷新连接 } -void MainWindow::creatMarkerDat(McFilesInfo &curFilesInfo, QString filePath) +void MainWindow::slotDeleteFileFromList(int mcNum, int fileIdx, int refreshFlag) { - QFileInfo fileInfo(filePath); - curFilesInfo.m_marker.Initialize(); + //是否自动打印 + int autoPrint = 0; - if(fileInfo.suffix().toUpper() == "PLT") + //刷新进度 + if(refreshFlag != 0) { - ImportHPGL importHPGL; - curFilesInfo.m_fileType = TYPE_FILE; + slotRefreshPrintProgress(mcNum,fileIdx); + } - //判断是否为加密文件 - if (importHPGL.IsSecretFile(filePath) == true) + for(int i = 0; i < g_machineList.size(); i++) + { + if(mcNum == g_machineList[i]->m_mcPrintInfo.m_mcNum) { - // 文件路径 - QDir apppath(qApp->applicationDirPath()); - QString strSecretFile = apppath.path() + apppath.separator() + "Secret.plt"; + if(fileIdx >= g_machineList[i]->m_mcPrintInfo.m_filesList.size()) + { + qDebug()<<"slotDeleteFileFromList return"<m_mcPrintInfo.m_filesList.size(); + //return; + } + if(i == m_curMcIdx)//当前删除文件的操作正为所选机器的预览显示 + { + //从列表中删除一行 + m_tabelViewModelFile->removeRow(fileIdx); + m_preView->cleanView(); + g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].clear(); + g_machineList[i]->m_mcPrintInfo.m_filesList.removeAt(fileIdx);//删除机器文件列表中已打印完成的文件 - importHPGL.BitMapDtat(filePath,strSecretFile); - importHPGL.IniPara(); - importHPGL.ReadSecretFile(strSecretFile,&curFilesInfo.m_marker); + //自动打印模式且打印起始文件为最后一个时,打印完此文件不再打印 + if(autoPrint == 1 && m_curFileRow == g_machineList[i]->m_mcPrintInfo.m_filesList.size()) + { + m_curFileRow = -1; + } + else if(m_curFileRow == g_machineList[i]->m_mcPrintInfo.m_filesList.size())//跳到上一个 + { + m_curFileRow -= 1; + reflushPreview(m_curFileRow); + } + + if(g_machineList[i]->m_mcPrintInfo.m_filesList.size() <= 0) + { + m_curFileRow = -1; + } + reflushPreview(m_curFileRow); + + //都不选中 + if(m_curFileRow == -1) + { + ui->tableView_fileList->clearSelection(); + } + + if(m_curFileRow >= 0 && autoPrint == 1) + { + g_machineList[i]->creatPrintDat(m_curFileRow,0); + } + } } - else + } +} + +void MainWindow::slotRefreshPrintProgress(int mcNum, int fileIdx) +{ + for(int i = 0; i < g_machineList.size(); i++) + { + QString str; + if(g_machineList[i]->m_mcPrintInfo.m_mcWorkState == NotBusy) { - importHPGL.IniPara(); - importHPGL.Read(filePath,&curFilesInfo.m_marker); + str = tr("Idle");//空闲中 } - curFilesInfo.m_fileRect = curFilesInfo.m_marker.GetRect(); + else if(g_machineList[i]->m_mcPrintInfo.m_mcWorkState == Busying) + { + str = tr("Working");//工作中 + } + m_tabelViewModelConn->setData(m_tabelViewModelConn->index(i,CONN_COLUMN_MCWORKSTATE),str); + QString strPro = QString::number(g_machineList[i]->m_mcPrintInfo.m_mcSendProgress,'f',2)+"%"; + m_tabelViewModelConn->setData(m_tabelViewModelConn->index(i,CONN_COLUMN_MCPROGRESS),strPro); + + if(mcNum == g_machineList[i]->m_mcPrintInfo.m_mcNum) + { + if(fileIdx >= g_machineList[i]->m_mcPrintInfo.m_filesList.size()) + { + return; + } + if(i == m_curMcIdx)//当前操作正为所选机器的预览显示 + { + //刷新进度显示 + double val = g_machineList[i]->m_mcPrintInfo.m_mcSendProgress; + ui->progressBar_print->setValue(round(val)); + ui->progressBar_print->setFormat(QString("%1%").arg(QString::number(val,'f',2))); + + int idx = 0; + if(m_curFileRow >= 0) + { + idx = m_curFileRow; + } + + val = (double)g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_printedBlockNum / (double)g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_totalBlocks * 100.0; + QString progress = QString::number(val,'f',2)+"%"; + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(idx,COLUMN_PRINTPROGRESS),progress); + + int printLen = (g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_printedBlockNum*PIXMAPWIDTH)/MMPIXELY; + QString str = QString::number(printLen) + "mm"; + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(idx, COLUMN_PRINTEDLENGTH),str); + + QString stateStr; + if(g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_printState == Waitting) + { + stateStr = tr("Waitting");//未打印 + } + else if(g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_printState == Printting) + { + stateStr = tr("Printting");//打印中 + } + else if(g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_printState == Pause) + { + stateStr = tr("Pause print");//暂停打印 + } + else if(g_machineList[i]->m_mcPrintInfo.m_filesList[fileIdx].m_printState == Complete) + { + stateStr = tr("Complete");//打印完成 + } + + m_tabelViewModelFile->setData(m_tabelViewModelFile->index(idx,COLUMN_STATE),stateStr); + } + } + } +} + +void MainWindow::refreshBtnEnable() +{ + if(m_curMcIdx < 0) + { + ui->actionDeletMachine->setEnabled(false); + ui->actionOpen_File->setEnabled(false); + ui->actionOpen_Image->setEnabled(false); + ui->menuTesting->setEnabled(false); + ui->actionAuto_Print_Dir->setEnabled(false); + ui->actionlog->setEnabled(false); + ui->menuSetting_S->setEnabled(false); + + ui->toolBar->setEnabled(false); + ui->frame_fileBtn->setEnabled(false); } else { - curFilesInfo.m_fileType = TYPE_IMAGE; - QBitmap pixmap; - pixmap.load(filePath); - QRect rect; - rect.setRect(0,0,pixmap.width()/MMPIXELY*M_IDPMM,pixmap.height()/MMPIXELY*M_IDPMM); + ui->actionDeletMachine->setEnabled(true); + ui->actionOpen_File->setEnabled(true); + ui->actionOpen_Image->setEnabled(true); + ui->menuTesting->setEnabled(true); + ui->actionAuto_Print_Dir->setEnabled(true); + ui->actionlog->setEnabled(true); + ui->menuSetting_S->setEnabled(true); - curFilesInfo.m_pixmap = pixmap; - curFilesInfo.m_fileRect = rect; + ui->toolBar->setEnabled(true); + ui->frame_fileBtn->setEnabled(true); } - curFilesInfo.m_filePath = filePath; - curFilesInfo.m_fileName = fileInfo.fileName(); - curFilesInfo.m_printNum = 1; - curFilesInfo.m_startPoint = 0; - curFilesInfo.m_printState = tr("Waitting"); - curFilesInfo.m_curPrintBlock = 0;//当前打印块数 - curFilesInfo.m_printedBlockNum = 0;//已打印块数 - curFilesInfo.m_selectBlockNum = 0;//当前选择块数 - curFilesInfo.m_creatDataFlag = 1; + if(m_curFileRow < 0) + { + ui->frame_fileBtn->setEnabled(false); + } + else + { + ui->frame_fileBtn->setEnabled(true); + } +} + +void MainWindow::switchLanguage(s16 languageType) +{ + QDir apppath(qApp->applicationDirPath()); + m_pSettings->setValue("HMI/language",languageType); + + QString languagePath; + switch (languageType) + { + case chinese://中文 + languagePath = apppath.path() + apppath.separator() + "chinese.qm"; + break; + case english://英文 + languagePath = apppath.path() + apppath.separator() + "english.qm"; + break; + default://中文 + languagePath = apppath.path() + apppath.separator() + "chinese.qm"; + break; + } + + //刷新翻译显示 + g_pTranslator->load(languagePath); + ui->retranslateUi(this); + m_drawingSetDlg->refreshLanguage(); + m_plotterSetDlg->refreshLanguage(); + m_historyDlg->refreshLanguage(); + m_printViewWi->refreshLanguage(); + m_printInfoDlg->refreshLanguage(); + + //重新设置一下tableview的头显示,否则翻译不会更新 + QStringList header; //QString类型的List容器 + header<setHorizontalHeaderLabels(header); + + QStringList headerConn; //QString类型的List容器 + headerConn<setHorizontalHeaderLabels(headerConn); } void MainWindow::on_actionDrawing_Setting_triggered() { if(m_drawingSetDlg!= NULL) { - m_drawingSetDlg->exec(); + m_drawingSetDlg->refreshConfigPara(m_pSettings->fileName()); + if(m_drawingSetDlg->exec() == 1) + { + m_rotateAngle = m_drawingSetDlg->getRotateAngle(); + } } } @@ -1182,10 +1307,7 @@ void MainWindow::on_actionOpen_File_triggered() return; } - QDir apppath(qApp->applicationDirPath()); - QString iniPath = apppath.path() + apppath.separator() + "config.ini"; - QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来 - QString lastPath = setting.value("LastFilePath/filePath").toString(); //获取上次的打开路径 + QString lastPath = m_pSettings->value("LastFilePath/filePath").toString(); //获取上次的打开路径 QString filePath; @@ -1199,10 +1321,12 @@ void MainWindow::on_actionOpen_File_triggered() QFileInfo fileInfo(filePath); QString fileName = fileInfo.fileName(); QString path = filePath; - setting.setValue("LastFilePath/filePath",path.remove(fileName)); //记录路径到QSetting中保存 + m_pSettings->setValue("LastFilePath/filePath",path.remove(fileName)); //记录路径到QSetting中保存 +#if(1) + creatMarkerDat(m_curFilesInfo,m_printPath,filePath,-1,m_rotateAngle); +#else m_curFilesInfo.m_marker.Initialize(); - if(fileInfo.suffix().toUpper() == "DXF") { DxfHelper dxfHelper; @@ -1240,9 +1364,10 @@ void MainWindow::on_actionOpen_File_triggered() m_curFilesInfo.m_fileType = TYPE_FILE; m_curFilesInfo.m_fileRect = m_curFilesInfo.m_marker.GetRect(); //m_curFilesInfo.m_painterPath = importHPGL.GetPolylinePainterPath(); - - m_printViewWi->refreshShow(m_curFilesInfo,1); } +#endif + int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽 + m_printViewWi->refreshShow(m_curFilesInfo,penWidth,1); } return; } @@ -1254,8 +1379,13 @@ void MainWindow::on_tableView_fileList_clicked(const QModelIndex &index) reflushPreview(row); //判断是否正在打印,如果正在打印时不可删除、移动、修改打印信息 + if(row >= g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList.size()) + { + return; + } ui->frame_fileBtn->setEnabled(true); - if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_curPrintBlock != 0) + if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow].m_curPrintBlock != 0 + && g_machineList[m_curMcIdx]->m_mcPrintInfo.m_mcWorkState == Busying) { ui->frame_fileBtn->setEnabled(false); } @@ -1314,10 +1444,7 @@ void MainWindow::on_actionOpen_Image_triggered() return; } - QDir apppath(qApp->applicationDirPath()); - QString iniPath = apppath.path() + apppath.separator() + "config.ini"; - QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来 - QString lastPath = setting.value("LastFilePath/filePath").toString(); //获取上次的打开路径 + QString lastPath = m_pSettings->value("LastFilePath/filePath").toString(); //获取上次的打开路径 QString filePath; @@ -1331,7 +1458,7 @@ void MainWindow::on_actionOpen_Image_triggered() QFileInfo fileInfo(filePath); QString fileName = fileInfo.fileName(); QString path = filePath; - setting.setValue("LastFilePath/filePath",path.remove(fileName)); //记录路径到QSetting中保存 + m_pSettings->setValue("LastFilePath/filePath",path.remove(fileName)); //记录路径到QSetting中保存 m_curFilesInfo.m_marker.Initialize(); m_curFilesInfo.m_filePath = filePath; @@ -1345,7 +1472,8 @@ void MainWindow::on_actionOpen_Image_triggered() m_curFilesInfo.m_pixmap = pixmap; m_curFilesInfo.m_fileRect = rect; - m_printViewWi->refreshShow(m_curFilesInfo,1); + int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽 + m_printViewWi->refreshShow(m_curFilesInfo,penWidth,1); } } @@ -1354,11 +1482,6 @@ void MainWindow::on_actionOpenImageIcon_triggered() on_actionOpen_Image_triggered(); } -void MainWindow::on_actionDelete_triggered() -{ - slotDeleteFile(); -} - void MainWindow::on_actionAuto_Print_Dir_triggered() { if(m_curMcIdx < 0) @@ -1392,26 +1515,67 @@ void MainWindow::on_actionAuto_Print_Dir_triggered() } } +//全部启动 void MainWindow::on_actionStart_triggered() { - m_workState = START; - startCreatBmpAndSend(m_curMcIdx); + if(m_workState == WORK_START) + { + return; + } + + if(QMessageBox::warning(this, + tr("Prompt"), + tr("Do you want to start printing on all machines?"),//是否启动所有机器打印? + QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok) + { + m_workState = WORK_START; + startCreatBmpAndSend(-1); + } } +//当前机器启动 void MainWindow::on_actionStartIcon_triggered() { - m_workState = START; + if(m_curMcIdx >= g_machineList.size()) + { + return; + } + + if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_mcWorkState == Busying) + { + return; + } + startCreatBmpAndSend(m_curMcIdx); } +//全部暂停 void MainWindow::on_actionPause_triggered() { - m_workState = PAUSE; + if(m_workState == WORK_PAUSE) + { + return; + } + + m_workState = WORK_PAUSE; + ui->frame_fileBtn->setEnabled(true); + stopPrint(-1); } +//当前机器暂停 void MainWindow::on_actionPauseIcon_triggered() { - m_workState = PAUSE; + if(m_curMcIdx >= g_machineList.size()) + { + return; + } + + if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_mcWorkState == NotBusy) + { + return; + } + + stopPrint(m_curMcIdx); } void MainWindow::on_actionAddMachine_triggered() @@ -1420,10 +1584,6 @@ void MainWindow::on_actionAddMachine_triggered() if(addMcDlg.exec() == 1) { //读取配置文件是否存在同名的机器名称 - QDir apppath(qApp->applicationDirPath()); - QString configfile; - configfile = apppath.path() + apppath.separator() + "config.ini"; - QSettings settings(configfile, QSettings::IniFormat); QString mcName = addMcDlg.getMcName(); QString serverIp = addMcDlg.getMcIp(); quint16 serverPort = 5000; @@ -1432,16 +1592,16 @@ void MainWindow::on_actionAddMachine_triggered() for(int i = 1; i <= MACHINE_NUM; i++) { QString str = "MachineNo" + QString::number(i); - QString keyStr = str + + "/name"; - bool bl = settings.contains(keyStr); + QString keyStr = str + "/name"; + bool bl = m_pSettings->contains(keyStr); if(bl == false) { QString strName = str + "/name"; - settings.setValue(strName,mcName); + m_pSettings->setValue(strName,mcName); QString strIp = str + "/ip"; - settings.setValue(strIp,serverIp); + m_pSettings->setValue(strIp,serverIp); QString strPort = str + "/port"; - settings.setValue(strPort,serverPort); + m_pSettings->setValue(strPort,serverPort); idx = i; break; } @@ -1457,8 +1617,8 @@ void MainWindow::on_actionAddMachine_triggered() } //本地IP和端口 - QString localIp = settings.value("Local/ip").toString(); - quint16 localPort = settings.value("Local/port").toInt(); + QString localIp = m_pSettings->value("Local/ip").toString(); + quint16 localPort = m_pSettings->value("Local/port").toInt(); Machine *pMachine = new Machine(); //建立连接 pMachine->setIpAndPort(mcName,serverIp,serverPort,localIp,localPort);//设置IP和端口 @@ -1496,4 +1656,19 @@ void MainWindow::on_tableView_Connection_clicked(const QModelIndex &index) { refreshMcFileListShow(index.row()); ui->tableView_Connection->selectRow(m_curMcIdx); + + double val = g_machineList[index.row()]->m_mcPrintInfo.m_mcSendProgress; + ui->progressBar_print->setValue(round(val)); + ui->progressBar_print->setFormat(QString("%1%").arg(QString::number(val,'f',2))); + refreshBtnEnable(); +} + +void MainWindow::on_actionChinese_triggered() +{ + switchLanguage(chinese); +} + +void MainWindow::on_actionEnglish_triggered() +{ + switchLanguage(english); } diff --git a/mainwindow.h b/mainwindow.h index bd83a2f..e4aa17d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,20 +27,20 @@ #include "printinfodialog.h" #include "addmachinedialog.h" #include "datafile/hpgl/importhpgl.h" -#include "datafile/dxf/dxfhelper.h" #include "machine/bmp/creatprintbmp.h" //文件列表 -#define COLUMN_NUM 8 //列数 +#define COLUMN_NUM 9 //列数 #define COLUMN_COLWIDTH 96 //列宽 #define COLUMN_FILENAME 0 //第1列-文件名称 #define COLUMN_LENGTH 1 //第2列-文件长度 #define COLUMN_WIDTH 2 //第3列-文件宽度 #define COLUMN_START 3 //第4列-文件起始打印点 #define COLUMN_PRINTEDLENGTH 4 //第5列-文件已打印长度 -#define COLUMN_NUMBERS 5 //第6列-文件打印数量 -#define COLUMN_STATE 6 //第7列-文件打印状态 -#define COLUMN_FILEPATH 7 //第8列-文件路径 +#define COLUMN_PRINTPROGRESS 5 //第6列-文件打印进度 +#define COLUMN_NUMBERS 6 //第7列-文件打印数量 +#define COLUMN_STATE 7 //第8列-文件打印状态 +#define COLUMN_FILEPATH 8 //第9列-文件路径 //机器连接列表 #define CONN_COLUMN_NUM 5 //列数 @@ -49,7 +49,7 @@ #define CONN_COLUMN_MCIP 1 //第2列-机器IP #define CONN_COLUMN_MCCONSTATE 2 //第3列-机器连接状态 #define CONN_COLUMN_MCWORKSTATE 3 //第4列-机器工作状态 -#define CONN_COLUMN_MCPROGRESS 4 //第5列-机器文件发送进度 +#define CONN_COLUMN_MCPROGRESS 4 //第5列-机器打印进度 #define AUTOPRINT 1 #define NOAUTOPRINT 0 @@ -74,7 +74,6 @@ private: PrintViewWindow *m_printViewWi; PrintInfoDialog *m_printInfoDlg; MyGraphicsView *m_preView; - QTimer *m_sendTimer; QTimer * m_pTimer;//建立连接的定时器 int m_curMcIdx;//列表所选机器索引 @@ -92,6 +91,8 @@ private: int m_breakAutoLoadThread;//打断自动加载文件线程 QFuture m_autoPrintLoadThread;//自动绘图目录加载线程 + double m_rotateAngle; + QSettings *m_pSettings; private: void closeEvent(QCloseEvent *e); @@ -99,8 +100,8 @@ private: void reflushMcFileInfo(); void changeRowData(int move); bool deleteDir(QString path); - void setButtonEnable(bool bl); void startCreatBmpAndSend(int mcIdx = -1);//开始创建位图并发送 + void stopPrint(int mcIdx = -1);//停止打印 QPicture creatFilePicture(McFilesInfo & mcFileInfo, s16 penWidth = 1); //刷新连接状态 void refConnectUi();//刷新连接状态(1秒) @@ -108,7 +109,8 @@ private: void refreshMcListShow();//刷新机器列表显示 void refreshOneMcShow(int row,int idx);//刷新单个机器信息显示 int refreshMcFileListShow(int idx); - void creatMarkerDat(McFilesInfo &curFilesInfo, QString filePath);//创建Marker数据 + void refreshBtnEnable();//刷新按钮可按状态 + void switchLanguage(s16 languageType); public: void initAllWinForm(); @@ -124,11 +126,11 @@ private slots: void slotStartSetDlgShow(); void slotViewPrintInfo(); void slotDeleteFile();//删除文件 - void slotDeleteFileFinish();//删除文件完成并刷新 void slotDeleteMc();//删除机器 - void onSendTimer(void); void slotLoadAutoPrintFiles(); void onOneSecondTimer();//1秒定时器 + void slotDeleteFileFromList(int mcNum, int fileIdx, int refreshFlag = 0);//从列表中删除已打印完成的文件 + void slotRefreshPrintProgress(int mcNum, int fileIdx); //刷新打印进度 private slots: void on_actionDrawing_Setting_triggered(); @@ -143,7 +145,6 @@ private slots: void on_actionOpenFileIcon_triggered(); void on_actionOpen_Image_triggered(); void on_actionOpenImageIcon_triggered(); - void on_actionDelete_triggered(); void on_actionAuto_Print_Dir_triggered(); void on_actionStart_triggered(); void on_actionStartIcon_triggered(); @@ -152,6 +153,8 @@ private slots: void on_actionAddMachine_triggered(); void on_actionDeletMachine_triggered(); void on_tableView_Connection_clicked(const QModelIndex &index); + void on_actionChinese_triggered(); + void on_actionEnglish_triggered(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 776ed09..f4736a6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -259,7 +259,7 @@ 0 0 1024 - 23 + 21 @@ -277,10 +277,8 @@ - - @@ -349,12 +347,12 @@ - Start + Start All - Pause + Pause All @@ -488,7 +486,7 @@ DrawingSetIcon - DrawingSetting + DrawingSetting diff --git a/plottersetdialog.cpp b/plottersetdialog.cpp index 9a98a1e..d7b6fb9 100644 --- a/plottersetdialog.cpp +++ b/plottersetdialog.cpp @@ -14,3 +14,13 @@ PlotterSetDialog::~PlotterSetDialog() { delete ui; } + +void PlotterSetDialog::refreshLanguage() +{ + ui->retranslateUi(this); +} + +void PlotterSetDialog::on_pushButton_cancel_clicked() +{ + done(0); +} diff --git a/plottersetdialog.h b/plottersetdialog.h index eff9e13..60a5739 100644 --- a/plottersetdialog.h +++ b/plottersetdialog.h @@ -14,6 +14,10 @@ class PlotterSetDialog : public QDialog public: explicit PlotterSetDialog(QWidget *parent = 0); ~PlotterSetDialog(); + void refreshLanguage(); + +private slots: + void on_pushButton_cancel_clicked(); private: Ui::PlotterSetDialog *ui; diff --git a/plottersetdialog.ui b/plottersetdialog.ui index 0bcb0aa..41dbce0 100644 --- a/plottersetdialog.ui +++ b/plottersetdialog.ui @@ -23,19 +23,19 @@ - Print startup mode selection + Print startup mode selection 20 - 22 + 25 241 16 - Auto Print + Auto Print @@ -49,32 +49,32 @@ - Print mode selection + Print mode selection 20 - 22 + 25 89 16 - Single + Single 200 - 22 + 25 89 16 - Double + Double @@ -88,13 +88,13 @@ - Graphic error correction + Graphic error correction 240 - 26 + 28 61 20 @@ -107,7 +107,7 @@ 310 - 30 + 32 30 12 @@ -120,20 +120,20 @@ 53 - 26 + 28 181 20 - 1 meter actual output: + 1 meter actual output: 310 - 60 + 62 30 12 @@ -146,20 +146,20 @@ 53 - 56 + 58 181 20 - 1 meter actual output: + 1 meter actual output: 240 - 56 + 58 61 20 @@ -172,20 +172,20 @@ 340 - 38 + 40 201 26 - Drawing 1 meter Square + Drawing 1 meter Square 6 - 26 + 28 42 20 @@ -201,7 +201,7 @@ 6 - 55 + 57 42 20 @@ -224,7 +224,7 @@ - Two way print error setting + Two way print error setting @@ -262,7 +262,7 @@ - Two way print error: + Two way print error: @@ -288,7 +288,7 @@ - Print drawing width: + Print drawing width: @@ -314,7 +314,7 @@ - Print Error Correction + Print Error Correction @@ -328,15 +328,15 @@ - Error setting between nozzles + Error setting between nozzles 10 - 21 + 10 501 - 94 + 106 @@ -346,7 +346,7 @@ 240 - 8 + 24 61 20 @@ -359,59 +359,59 @@ 310 - 8 + 24 51 20 - pixel + pixel 13 - 8 + 24 221 20 - 1、2 error between nozzles: + 1、2 error between nozzles: 310 - 36 + 52 51 20 - pixel + pixel 13 - 36 + 52 221 20 - 2、3 error between nozzles: + 2、3 error between nozzles: 240 - 36 + 52 61 20 @@ -424,20 +424,20 @@ 13 - 64 + 80 221 20 - 3、4 error between nozzles: + 3、4 error between nozzles: 240 - 64 + 80 61 20 @@ -450,20 +450,20 @@ 310 - 64 + 80 51 20 - pixel + pixel 390 - 23 + 39 65 48 @@ -480,9 +480,9 @@ 10 - 122 + 105 501 - 94 + 106 @@ -492,7 +492,7 @@ 240 - 8 + 25 61 20 @@ -505,59 +505,59 @@ 310 - 8 + 25 51 20 - pixel + pixel 13 - 8 + 25 221 20 - 1、2 overlap between nozzles: + 1、2 overlap between nozzles: 310 - 36 + 53 51 20 - pixel + pixel 13 - 36 + 53 221 20 - 2、3 overlap between nozzles: + 2、3 overlap between nozzles: 240 - 36 + 53 61 20 @@ -570,20 +570,20 @@ 13 - 64 + 81 221 20 - 3、4 overlap between nozzles: + 3、4 overlap between nozzles: 240 - 64 + 81 61 20 @@ -596,20 +596,20 @@ 310 - 64 + 81 51 20 - pixel + pixel 390 - 23 + 40 65 48 @@ -632,7 +632,7 @@ - Correction diagram between nozzles + Correction diagram between nozzles @@ -646,13 +646,13 @@ - Paper feeding error correction + Paper feeding error correction 240 - 26 + 31 61 20 @@ -665,7 +665,7 @@ 310 - 30 + 35 30 12 @@ -678,26 +678,26 @@ 36 - 26 + 31 201 20 - Paper feeding error set: + Paper feeding error set: 340 - 22 + 27 201 26 - Print paper feed error + Print paper feed error @@ -711,7 +711,7 @@ - Ok + Ok @@ -724,7 +724,7 @@ - Cancel + Cancel @@ -737,58 +737,58 @@ - Sprinkler selection + Sprinkler selection 20 - 22 + 25 91 16 - Nozzle 1 + Nozzle 1 130 - 22 + 25 91 16 - Nozzle 2 + Nozzle 2 240 - 22 + 25 91 16 - Nozzle 3 + Nozzle 3 350 - 22 + 25 91 16 - Nozzle 4 + Nozzle 4 diff --git a/printinfodialog.cpp b/printinfodialog.cpp index 12dcb20..f786dea 100644 --- a/printinfodialog.cpp +++ b/printinfodialog.cpp @@ -11,6 +11,8 @@ PrintInfoDialog::PrintInfoDialog(QWidget *parent) : //QListView ui->listView_blockList->setDragEnabled(false); //控件不允许拖动 + // 设置listView为不可编辑状态 + ui->listView_blockList->setEditTriggers(QAbstractItemView::NoEditTriggers); m_listViewModel = new QStringListModel(ui->listView_blockList); ui->listView_blockList->setModel(m_listViewModel); @@ -24,6 +26,11 @@ PrintInfoDialog::~PrintInfoDialog() delete ui; } +void PrintInfoDialog::refreshLanguage() +{ + ui->retranslateUi(this); +} + void PrintInfoDialog::on_listView_blockList_clicked(const QModelIndex &index) { QString str = "0 - "; @@ -101,11 +108,11 @@ void PrintInfoDialog::setFilesInfo(McFilesInfo info) m_preView->cleanView(); if(m_curFilesInfo.m_fileType == TYPE_FILE) { - m_preView->creatView(m_curFilesInfo.m_marker);//刷新显示 + m_preView->creatViewPathAndPic(m_curFilesInfo.m_drawPath,m_curFilesInfo.m_pic);//刷新显示 } else if(m_curFilesInfo.m_fileType == TYPE_IMAGE) { - m_preView->creatView(m_curFilesInfo.m_pixmap);//刷新显示 + m_preView->swithViewByPic(m_curFilesInfo.m_pic);//刷新显示 } reflushFileInfo(); diff --git a/printinfodialog.h b/printinfodialog.h index 4e12b72..a6dd493 100644 --- a/printinfodialog.h +++ b/printinfodialog.h @@ -18,6 +18,7 @@ class PrintInfoDialog : public QDialog public: explicit PrintInfoDialog(QWidget *parent = 0); ~PrintInfoDialog(); + void refreshLanguage(); private slots: void on_listView_blockList_clicked(const QModelIndex &index); diff --git a/printnumbersetdialog.ui b/printnumbersetdialog.ui index 7563ebc..3091e19 100644 --- a/printnumbersetdialog.ui +++ b/printnumbersetdialog.ui @@ -49,7 +49,7 @@ - Number: + Number: diff --git a/printviewwindow.cpp b/printviewwindow.cpp index e1bb3df..db28182 100644 --- a/printviewwindow.cpp +++ b/printviewwindow.cpp @@ -32,7 +32,12 @@ PrintViewWindow::~PrintViewWindow() delete ui; } -void PrintViewWindow::refreshShow(McFilesInfo mcFilesInfo,int flag) +void PrintViewWindow::refreshLanguage() +{ + ui->retranslateUi(this); +} + +void PrintViewWindow::refreshShow(McFilesInfo &mcFilesInfo,int penWidth,int flag) { m_startPoint = 0; m_printNumber = 1; @@ -56,11 +61,12 @@ void PrintViewWindow::refreshShow(McFilesInfo mcFilesInfo,int flag) m_view->cleanView(); if(mcFilesInfo.m_fileType == TYPE_FILE) { - m_view->creatView(mcFilesInfo.m_marker); + mcFilesInfo.m_pic = m_view->getPictureByDat(mcFilesInfo.m_marker,penWidth); + mcFilesInfo.m_drawPath = m_view->getDrawPath(); } else if(mcFilesInfo.m_fileType == TYPE_IMAGE) { - m_view->creatView(mcFilesInfo.m_pixmap); + mcFilesInfo.m_pic = m_view->getPictureByBmp(mcFilesInfo.m_pixmap); } //如果是最大化变为正常大小 @@ -104,6 +110,6 @@ void PrintViewWindow::on_pushButton_draw_clicked() return; } - siAddNewFile(m_addNewFileFlag); + emit siAddNewFile(m_addNewFileFlag); this->close(); } diff --git a/printviewwindow.h b/printviewwindow.h index 950b263..3e63ce3 100644 --- a/printviewwindow.h +++ b/printviewwindow.h @@ -20,6 +20,7 @@ class PrintViewWindow : public QMainWindow public: explicit PrintViewWindow(QWidget *parent = 0); ~PrintViewWindow(); + void refreshLanguage(); private: Ui::PrintViewWindow *ui; @@ -32,7 +33,7 @@ private: int m_length; public: - void refreshShow(McFilesInfo mcFilesInfo,int flag = 0); + void refreshShow(McFilesInfo &mcFilesInfo,int penWidth,int flag = 0); void setStartLineText(QString str); void setNumberLineText(QString str); inline int getStartPoint(){return m_startPoint;}