184 lines
6.1 KiB
C++
184 lines
6.1 KiB
C++
#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"<<strSecretFile;
|
|
|
|
importHPGL.BitMapDtat(filePath,strSecretFile);
|
|
importHPGL.IniPara();
|
|
importHPGL.setRotateAngle(angle);
|
|
importHPGL.ReadSecretFile(strSecretFile,&curFilesInfo.m_marker);
|
|
//qDebug()<<"importHPGL.IsSecretFile";
|
|
}
|
|
else
|
|
{
|
|
importHPGL.IniPara();
|
|
importHPGL.setRotateAngle(angle);
|
|
importHPGL.Read(filePath,&curFilesInfo.m_marker);
|
|
}
|
|
curFilesInfo.m_fileRect = curFilesInfo.m_marker.GetRect();
|
|
}
|
|
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);
|
|
|
|
curFilesInfo.m_pixmap = pixmap;
|
|
curFilesInfo.m_fileRect = rect;
|
|
}
|
|
|
|
curFilesInfo.m_filePath = filePath;
|
|
curFilesInfo.m_fileName = fileInfo.fileName();
|
|
curFilesInfo.m_printNum = 1;
|
|
curFilesInfo.m_startPoint = 0;
|
|
curFilesInfo.m_printState = Waitting;
|
|
curFilesInfo.m_curPrintBlock = 0;//当前打印块数
|
|
curFilesInfo.m_printedBlockNum = 0;//已打印块数
|
|
curFilesInfo.m_selectBlockNum = 0;//当前选择块数
|
|
curFilesInfo.m_creatDataFlag = 1;
|
|
}
|