EmbHMI/datafile/datafiledst.h
2024-02-06 14:27:07 +08:00

162 lines
4.9 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef DATAFILEDST_H
#define DATAFILEDST_H
#include <QFileInfo>
#include <QFile>
#include <QString>
#include <QByteArray>
#include <QImage>
#include <QDebug>
#include <QPainter>
#include <QRgb>
#include "math.h"
#include <QBrush>
#include <QLinearGradient>
#include "main.h"
#include "machine/comm/datadef.h"
#include "machine/comm/crc16.h"
#define DATAFACTOR 10 //dst绝对坐标数据转换为ds16前需要扩大10倍
#define DST_EMB_DATADIRX (1) // X向数据坐标与下位机坐标系统的差异
#define DST_EMB_DATADIRY (-1) // Y向数据坐标与下位机坐标系统的差异
#define DST_SHOWDIRX (-1) // X向显示坐标和数据坐标的差异
#define DST_SHOWDIRY (1) // Y向显示坐标和数据坐标的差异
#define DST_PREVIEW_SIDE (15) // 留边大小
#define DST_PREVIEW_WIDTH (156) // 默认预览图区域宽度
#define DST_PREVIEW_HEIGHT (164) // 默认预览图区域高度
// dst文件头
#pragma pack(1)//设定为1字节对齐
struct DstHead
{
// 0
char la[20];
char st[11];
char co[7];
char xp[9];
char xn[9];
char yp[9];
char yn[9];
char ax[10];
char ay[10];
char mx[10];
char my[10];
char pd[10];
char sub;
char reserved1[3];
// 128 // 自定义,存储色序
u8 switchTable[256-128]; //BYTE // 色序设定表, 支持128个色序设定缝绣机
// 256
s16 reserved2;
// 258
int anchorX; //定位点
int anchorY;
// 266
s32 startX; //起绣点
s32 startY;
// 274
u32 begWorkHead;//工作机头
//278
u32 offsetEn; // bit0,偏移点X向允许 0,不允许 1,允许
// // bit1,偏移点Y向允许 0,不允许 1,允许
// // bit2,平绣数据有无 0,无 1,有
// // bit3,激光数据有无 0,无 1,有
// // bit4,毛巾链式数据有无 0,无 1,有
// // bit5,缠绕锯齿盘带数据有无 0,无 1,有
//282
s32 offsetX; // 偏移点X
// 286
s32 offsetY;
//290
u8 reserved3[512-290]; //BYTE // 保留字节
};
#pragma pack(1)//恢复对齐状态
// 针步数据
typedef struct strDstStep
{
u8 c1; ////BYTE
u8 c2; ////BYTE
u8 c3; ////BYTE
}__attribute__ ((packed)) DstStep;
class DataFileDst
{
public:
DataFileDst();
~DataFileDst();
public:
void initColor(int cnum = 0, QRgb * pColor = NULL);
void initFile(const QString & fullPathName);
int createPreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int gradientFlag = 1, int reDraw = 0); // 生成预览文件
void convertDataToAbs(); // 转换为绝对坐标数据
void writePointToFile(u8 type, int x, int y, int st = 0,u8 workHead=0);//写入起绣点到文件中
void writeOffsetXYMoveToFile(s32 EnFlag,s32 offsetX,s32 offsetY);
int checkDstFile();//检查dst文件是否正确
public:
void clear();
void loadFile();
void saveFile();
inline const QString & getFileFullPathName() const {return m_fileFullPathName;} // 文件路径名称
inline QByteArray & getFileData() {return m_fileData;} // 得到文件数据
inline QByteArray & getEmbAbsData() {return m_embAbsData;} // 得到转换后的数据
QString getFileFullPath(); // 文件所在目录
QString getFileFullName(); // 文件名称(包括扩展名)
QString getFileName(); // 文件名称(不包括扩展名)
QString getFileSuffix(); // 文件扩展名
int getStitchNums();//得到数据的针数
int getColorNums();//得到数据的色数
int getFileid();//得到fileid
int getDatWidth();//得到数据的图形宽度
int getDatHeight();//得到数据的图形高度
int getMaxX();//得到数据最大X+
int getMinX();//得到数据最小X-
int getMaxY();//得到数据最大Y+
int getMinY();//得到数据最小Y-
int getJumpNeedleNum();//得到总的跳针数
int getBeadSequinMap(QByteArray & map); // 得到有效珠片码的位图
int setBeadSequinTable(u8 * val); // 设置珠片码对应表
protected:
QString m_fileFullPathName; // 文件路径
QByteArray m_embAbsData; // 转换后的绝对坐标数据
private:
QByteArray m_fileData;// 文件数据内容(原始数据)
int m_colorNum;//颜色数
QRgb * m_pColor;//颜色rgb值
QString m_fileName; // 文件路径
private:
double m_minX;
double m_maxX;
double m_minY;
double m_maxY;
QByteArray m_beadSequinMap; // 有效珠片码的位图
QByteArray m_beadSequinTable; // 珠片码对应表
private:
int checkDefaultSwitchTable(int colornum = 0);
int changeDstStep(DstStep * pDststep, Ds4Item & ds4step);
QColor getBrightAdd(QColor embcolor);//补光增加
QColor getBrightDec(QColor embcolor);//补光减少
};
#endif // DATAFILEDST_H