QuiltingHMI/datafile/datafiledsr.h
2024-02-06 15:10:48 +08:00

206 lines
6.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 DATAFILEDSR_H
#define DATAFILEDSR_H
#include <QFileInfo>
#include <QFile>
#include <QString>
#include <QByteArray>
#include <QImage>
#include <QDebug>
#include <QPainter>
#include <QRgb>
#include "math.h"
#include <QBrush>
#include "dsrcryption.h"
#include "machine/comm/datadef.h"
#include "machine/comm/crc16.h"
#define DSR_PREVIEW_SIDE (15) // 留边大小
#define DSR_PREVIEW_WIDTH (156) // 默认预览图区域宽度
#define DSR_PREVIEW_HEIGHT (164) // 默认预览图区域高度
#define DSR_VERSION_5 5.00f
#define DSR_VERSION_6_3 6.30f
typedef struct strDsrHead
{
// 0x00 十六进制表示
DWORD verCode; // 文件版本 LSB
DWORD cryWord; // 加密字
BYTE reserved1[8]; // 保留 8 字节
// 0x10
DWORD dataBegin; // 数据起始 LSB
DWORD stepSize; // 数据字段大小
DWORD xyUnit; // 长度数据单位
DWORD rUnit; // 角度数据单位
// 0x20
DWORD stitches; // 针数 LSB
DWORD fileID; // 文件id,和智能识别有关 = 0, 不能识别
BYTE reserved2[8]; // 保留 8 字节
// 0x30
s32 rangeNx; // 范围 -X LSB
s32 rangePx; // 范围 +X LSB
s32 rangeNy; // 范围 -Y LSB
s32 rangePy; // 范围 +Y LSB
// 0x40
long startX; // 起点坐标X LSB
long startY; // 起点坐标Y LSB
long anchorX; // 定位点X LSB
long anchorY; // 定位点Y LSB
// 0x50
u8 reserved3[0x54-0x50]; // 保留字节
// 0x54
u8 rotateStyle; //旋转式样
u8 horizontalStyle; //水平翻转式样
u8 verticalStyle; //垂直翻转式样
u8 rotateAngle; //旋转角度
u8 reinMode; //加固方式
u8 reinNeedles; //针数
u8 reinNum; //次数
s16 normalStep; //针步大小
s16 angleCorrOffset; //角度修正量
s16 angleCorrPosX; //角度修正量X正
s16 angleCorrPosY; //角度修正量Y正
s16 angleCorrNegX; //角度修正量X负
s16 angleCorrNegY; //角度修正量Y负
int scanX; //X向宽度
int scanY; //Y向高度
int left; //左边
int front; //前边
// 0x77
BYTE reserved4[0x100-0x77]; // 保留字节
// 0x100
u8 reserved5[0x200-0x100]; //BYTE // 保留字节
// 0x200
u8 reserved6[0x400-0x200]; //BYTE
}__attribute__ ((packed)) DsrHead;
//dsr6.3版本的文件头扩展
typedef struct strDsrHead63
{
//0x00
u8 switchTable2[0x200-0x000]; //BYTE // 换色表2扩展色序设定表,512个字节
//0x200
u8 towelHighTable[0x600-0x200]; //BYTE // 毛巾高度设定表, 支持1024个高度设定每个字节对应一个高度等级0非有效高度。1--11, 有效的高度等级)
}__attribute__ ((packed)) DsrHead63;
//dsr6.2版本得文件头扩展
typedef struct
{
//支持128个表,每个表包含16个字节.
HeadTable headEnableSpacing[128];
} DsrHeadEx62;
typedef struct strDsrStep
{
BYTE ctrl; // 控制字节
BYTE attr; // 属性字节
WORD action;// 附加动作
s32 dx; // X绝对偏移
s32 dy; // Y绝对偏移
s32 dr; // R角度
}__attribute__ ((packed)) DsrStep;
//-----------------------------------------------
#define DSR_NULL 0x00 // 文件结束
#define DSR_SEWING 0x01 // 缝纫数据
#define DSR_OFFSET 0x02 // 偏移数据
#define DSR_CUTTING 0x03 // 切刀数据
#define DSR_LASER 0x04 // 激光数据
#define DSR_DRAWING 0x05 // 记号数据
#define DSR_SEWING_R 0x06 // 第二缝纫数据
#define DSR_PAUSE 0x08 // 暂停
#define DSR_ANGLE 0x09 // 拐点
#define DSR_CUT 0x0A // 剪线
#define DSR_JUMP 0x0B // 跳针
#define DSR_EMB 0x0D // 绣花
#define DSR_CHGND 0x0E // 换色
#define DSR_END 0x10 // 结束码
//-----------------------------------------------
#define DSR_EMB_DATADIRX (-1) // X向数据坐标与下位机坐标系统的差异
#define DSR_EMB_DATADIRY (-1) // Y向数据坐标与下位机坐标系统的差异
#define DSR_EMB_DATADIRR (1) // R向数据坐标与下位机坐标系统的差异
#define DSR_SHOWDIRX (-1) // X向显示坐标和数据坐标的差异
#define DSR_SHOWDIRY (1) // Y向显示坐标和数据坐标的差异
class DataFileDsr
{
public:
DataFileDsr();
~DataFileDsr();
public:
void initFile(const QString & fullPathName);
int checkDsrVersion();//检查dsr文件版本非5.2和6.3版本和错误格式返回-1
void convertDataToEmbAbs(); // 转换为绝对数据
//是否保存 //笔宽
int createPreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int reDraw = 0); // 生成预览文件
DsrHead *getDsrHead();
void moveDataBeginPonit(s32 left, s32 front); //移动数据起始点
void updateFileVersionTo6_2(); //更新文件版本至6.2
public:
void clear();
void loadFile();
void saveFile();
void writePointToFile(int x, int y, int flag = 0);//写入起始点到文件中
void writePatternParaToFile(DsrHead *head);//将花样参数配置写到文件中
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 getDatWidth();//得到数据的图形宽度
int getDatHeight();//得到数据的图形高度
int getMaxX();//得到数据最大X+
int getMinX();//得到数据最小X-
int getMaxY();//得到数据最大Y+
int getMinY();//得到数据最小Y-
int getBeginXYAndAnchorXY(int &beginX, int &beginY, int &anchorX, int &anchorY);
int getStepNums(); //获取换色数
void set62ExHead(DsrHeadEx62 data);
DsrHeadEx62 & get62ExHead();
protected:
QString m_fileFullPathName; // 文件路径
QByteArray m_embAbsData; // 转换后的绝对坐标数据
private:
QByteArray m_fileData;// 文件数据内容(原始数据)
QString m_fileName; // 文件路径
public:
DsrHeadEx62 m_62HeadData; //6.2版本附加文件头数据
private:
int m_minX;
int m_maxX;
int m_minY;
int m_maxY;
int m_HeadSpacingIndex; //五头精密缝 机头间距表列数index
private:
int checkFileCryption();//检查dsr文件是否加密
void getDsrMinMax();
};
#endif // DATAFILEDSR_H