绗缝系列代码
This commit is contained in:
commit
6dc54f28f2
23
Lot/csvcode.h
Normal file
23
Lot/csvcode.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef CSVCODE_H
|
||||||
|
#define CSVCODE_H
|
||||||
|
|
||||||
|
#define CSV_MC_TYPE_01 0x01 //平绣机
|
||||||
|
#define CSV_MC_TYPE_02 0x02 //带毛巾
|
||||||
|
#define CSV_MC_TYPE_03 0x03 //带缠绕
|
||||||
|
|
||||||
|
#define CSV_00_CODE_1 0x0001 //通用-主轴点动
|
||||||
|
#define CSV_00_CODE_2 0x0002 //通用-定起绣点
|
||||||
|
#define CSV_00_CODE_3 0x0003 //通用-回起绣点
|
||||||
|
#define CSV_00_CODE_4 0x0004 //通用-边框检查
|
||||||
|
#define CSV_00_CODE_5 0x0005 //通用-手动换色
|
||||||
|
#define CSV_00_CODE_6 0x0006 //通用-手动加油
|
||||||
|
#define CSV_00_CODE_7 0x0007 //通用-匹绣
|
||||||
|
#define CSV_00_CODE_8 0x0008 //通用-自动定软限位
|
||||||
|
#define CSV_00_CODE_9 0x0009 //通用-遍历
|
||||||
|
#define CSV_02_CODE_1 0x0001 //毛巾-毛巾M轴归零
|
||||||
|
#define CSV_02_CODE_2 0x0002 //毛巾-毛巾打环轴归零
|
||||||
|
#define CSV_03_CODE_1 0x0001 //缠绕-缠绕压脚电机归零
|
||||||
|
#define CSV_03_CODE_2 0x0002 //缠绕-缠绕锯齿电机归零
|
||||||
|
|
||||||
|
|
||||||
|
#endif // CSVCODE_H
|
||||||
274
Quilting.pro
Normal file
274
Quilting.pro
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by Qt5.9.1 2021-03-08T08:42:36
|
||||||
|
# created by HUAHAIYAN
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS+=-std=c++11
|
||||||
|
|
||||||
|
TARGET = QUILTING
|
||||||
|
|
||||||
|
CONFIG += c++11
|
||||||
|
CONFIG += resources_big
|
||||||
|
|
||||||
|
QT += core gui network
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
OBJECTS_DIR += obj
|
||||||
|
MOC_DIR += moc
|
||||||
|
UI_DIR += forms
|
||||||
|
RCC_DIR += rccs
|
||||||
|
|
||||||
|
#昆仑通态操作屏设置时间的库
|
||||||
|
unix:LIBS +=-L/usr/local/MCGS/sysroot-mcgs/usr/lib -lmcgs-hal
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
sharedviews/controlactionwidget.ui \
|
||||||
|
sharedviews/numerinputdialog.ui \
|
||||||
|
sharedviews/parametersetdialog.ui \
|
||||||
|
sharedviews/passworddialog.ui \
|
||||||
|
sharedviews/patternmanagewidget.ui \
|
||||||
|
sharedviews/patternselectwidget.ui \
|
||||||
|
sharedviews/promptdialog.ui \
|
||||||
|
sharedviews/sensorinputwidget.ui \
|
||||||
|
sharedviews/systemmanagedialog.ui \
|
||||||
|
sharedviews/wordsinputdialog.ui \
|
||||||
|
mctype/patternsingleboard/mainUI/mainwidget.ui \
|
||||||
|
sharedviews/mcheaddialog.ui \
|
||||||
|
sharedviews/headspacingsheetdialog.ui \
|
||||||
|
sharedviews/fileselectdialog.ui \
|
||||||
|
sharedviews/debuginfodialog.ui \
|
||||||
|
sharedviews/patterneditwidget.ui \
|
||||||
|
sharedviews/patternneedlelayoutwidget.ui \
|
||||||
|
sharedviews/linegenerwidget.ui \
|
||||||
|
sharedviews/shuttlebottomlinedialog.ui \
|
||||||
|
sharedviews/knifegapparadialog.ui
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
main.h \
|
||||||
|
items/paraitem.h \
|
||||||
|
items/sensoritem.h \
|
||||||
|
machine/comport.h \
|
||||||
|
machine/error.h \
|
||||||
|
machine/machine.h \
|
||||||
|
machine/qbindtcpsocket.h \
|
||||||
|
machine/tcpclient.h \
|
||||||
|
machine/comm/comm.h \
|
||||||
|
machine/comm/config.h \
|
||||||
|
machine/comm/crc16.h \
|
||||||
|
machine/comm/crc32.h \
|
||||||
|
machine/comm/datadef.h \
|
||||||
|
machine/comm/protocol.h \
|
||||||
|
machine/comm/typedef.h \
|
||||||
|
machine/qextserial/qextserialbase.h \
|
||||||
|
machine/qextserial/qextserialport.h \
|
||||||
|
datafile/datafiledst.h \
|
||||||
|
datafile/embdata.h \
|
||||||
|
datafile/datafiledsr.h \
|
||||||
|
items/outctrlitem.h \
|
||||||
|
items/shortcutitem.h \
|
||||||
|
items/cmdconfig.h \
|
||||||
|
items/fileitem.h \
|
||||||
|
settings/settings.h \
|
||||||
|
sharedviews/controlactionwidget.h \
|
||||||
|
sharedviews/numerinputdialog.h \
|
||||||
|
sharedviews/parametersetdialog.h \
|
||||||
|
sharedviews/passworddialog.h \
|
||||||
|
sharedviews/patternmanagewidget.h \
|
||||||
|
sharedviews/patternselectwidget.h \
|
||||||
|
sharedviews/promptdialog.h \
|
||||||
|
sharedviews/sensorinputwidget.h \
|
||||||
|
sharedviews/systemmanagedialog.h \
|
||||||
|
sharedviews/wordsinputdialog.h \
|
||||||
|
sharedviews/mybutton.h \
|
||||||
|
mctype/mainwidgetfunction.h \
|
||||||
|
sharedviews/setcontrolstyle.h \
|
||||||
|
datafile/dsrcryption.h \
|
||||||
|
items/itemsmanage.h \
|
||||||
|
items/assistitem.h \
|
||||||
|
items/patternsetitem.h \
|
||||||
|
mctype/patternsingleboard/mainUI/mainwidget.h \
|
||||||
|
settings/lotsettings.h \
|
||||||
|
machine/lotmachine.h \
|
||||||
|
items/parasetitem.h \
|
||||||
|
mctype/machinetypefun.h \
|
||||||
|
machine/gatewaytcpclient.h \
|
||||||
|
items/errorcodestateitem.h \
|
||||||
|
mctype/patternsingleboard/function/highsinglequilting.h \
|
||||||
|
datafile/datafilequi.h \
|
||||||
|
datafile/datafilequix.h \
|
||||||
|
datafile/dataoperat.h \
|
||||||
|
sharedviews/mcheaddialog.h \
|
||||||
|
sharedviews/headspacingsheetdialog.h \
|
||||||
|
mctype/patternsingleboard/function/fiveheadprecisionsewing.h \
|
||||||
|
sharedviews/fileselectdialog.h \
|
||||||
|
sharedviews/debuginfodialog.h \
|
||||||
|
items/nineitem.h \
|
||||||
|
mctype/patternsingleboard/function/clothingmac.h \
|
||||||
|
mctype/patternsingleboard/function/multineedlerotary.h \
|
||||||
|
# datafile/dxf/dxfhelper.h \
|
||||||
|
# datafile/dxf/dxfreader.h \
|
||||||
|
# datafile/dxf/dxflib/dl_attributes.h \
|
||||||
|
# datafile/dxf/dxflib/dl_codes.h \
|
||||||
|
# datafile/dxf/dxflib/dl_creationadapter.h \
|
||||||
|
# datafile/dxf/dxflib/dl_creationinterface.h \
|
||||||
|
# datafile/dxf/dxflib/dl_dxf.h \
|
||||||
|
# datafile/dxf/dxflib/dl_entities.h \
|
||||||
|
# datafile/dxf/dxflib/dl_exception.h \
|
||||||
|
# datafile/dxf/dxflib/dl_extrusion.h \
|
||||||
|
# datafile/dxf/dxflib/dl_global.h \
|
||||||
|
# datafile/dxf/dxflib/dl_writer.h \
|
||||||
|
# datafile/dxf/dxflib/dl_writer_ascii.h \
|
||||||
|
datafile/hpgl/importhpgl.h \
|
||||||
|
datafile/hpgl/marker.h \
|
||||||
|
datafile/hpgl/typedef.h \
|
||||||
|
datafile/hpgl/vectorfont.h \
|
||||||
|
machine/mytcpserver.h \
|
||||||
|
mctype/patternsingleboard/function/thickwiringmac.h \
|
||||||
|
mctype/patternsingleboard/function/flyshuttle.h \
|
||||||
|
sharedviews/patterneditwidget.h \
|
||||||
|
sharedviews/view/mygraphicsscene.h \
|
||||||
|
sharedviews/view/mygraphicsview.h \
|
||||||
|
sharedviews/view/mygraphicsgriditem.h \
|
||||||
|
sharedviews/patternneedlelayoutwidget.h \
|
||||||
|
sharedviews/linegenerwidget.h \
|
||||||
|
sharedviews/shuttlebottomlinedialog.h \
|
||||||
|
mctype/patternsingleboard/function/glassfibremac.h \
|
||||||
|
mctype/patternsingleboard/function/doublelayeredmac.h \
|
||||||
|
mctype/patternsingleboard/function/dlqscheboard.h \
|
||||||
|
mctype/patternsingleboard/function/singlemutilneedlemac.h \
|
||||||
|
mctype/patternsingleboard/function/doublesidedbedsheets.h \
|
||||||
|
mctype/patternsingleboard/function/l2000multimac.h \
|
||||||
|
mctype/patternsingleboard/function/fullyautomatic.h \
|
||||||
|
mctype/patternsingleboard/function/pkgfoursidedtestboardmac.h \
|
||||||
|
mctype/patternsingleboard/function/autodoubledoormac.h \
|
||||||
|
mctype/patternsingleboard/function/doubleheadcombqui.h \
|
||||||
|
mctype/patternsingleboard/function/cuttingwalk.h \
|
||||||
|
sharedviews/knifegapparadialog.h \
|
||||||
|
mctype/patternsingleboard/function/fourheadcombqui.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp \
|
||||||
|
items/paraitem.cpp \
|
||||||
|
items/sensoritem.cpp \
|
||||||
|
machine/comport.cpp \
|
||||||
|
machine/error.cpp \
|
||||||
|
machine/machine.cpp \
|
||||||
|
machine/qbindtcpsocket.cpp \
|
||||||
|
machine/tcpclient.cpp \
|
||||||
|
machine/comm/comm.cpp \
|
||||||
|
machine/comm/crc16.cpp \
|
||||||
|
machine/comm/crc32.cpp \
|
||||||
|
machine/qextserial/qextserialbase.cpp \
|
||||||
|
machine/qextserial/qextserialport.cpp \
|
||||||
|
datafile/datafiledst.cpp \
|
||||||
|
datafile/embdata.cpp \
|
||||||
|
datafile/datafiledsr.cpp \
|
||||||
|
items/outctrlitem.cpp \
|
||||||
|
items/shortcutitem.cpp \
|
||||||
|
items/fileitem.cpp \
|
||||||
|
settings/settings.cpp \
|
||||||
|
sharedviews/controlactionwidget.cpp \
|
||||||
|
sharedviews/numerinputdialog.cpp \
|
||||||
|
sharedviews/parametersetdialog.cpp \
|
||||||
|
sharedviews/passworddialog.cpp \
|
||||||
|
sharedviews/patternmanagewidget.cpp \
|
||||||
|
sharedviews/patternselectwidget.cpp \
|
||||||
|
sharedviews/promptdialog.cpp \
|
||||||
|
sharedviews/sensorinputwidget.cpp \
|
||||||
|
sharedviews/systemmanagedialog.cpp \
|
||||||
|
sharedviews/wordsinputdialog.cpp \
|
||||||
|
sharedviews/mybutton.cpp \
|
||||||
|
mctype/mainwidgetfunction.cpp \
|
||||||
|
sharedviews/setcontrolstyle.cpp \
|
||||||
|
datafile/dsrcryption.cpp \
|
||||||
|
items/itemsmanage.cpp \
|
||||||
|
items/assistitem.cpp \
|
||||||
|
items/patternsetitem.cpp \
|
||||||
|
mctype/patternsingleboard/mainUI/mainwidget.cpp \
|
||||||
|
machine/lotmachine.cpp \
|
||||||
|
items/parasetitem.cpp \
|
||||||
|
mctype/machinetypefun.cpp \
|
||||||
|
machine/gatewaytcpclient.cpp \
|
||||||
|
items/errorcodestateitem.cpp \
|
||||||
|
mctype/patternsingleboard/function/highsinglequilting.cpp \
|
||||||
|
datafile/datafilequi.cpp \
|
||||||
|
datafile/datafilequix.cpp \
|
||||||
|
datafile/dataoperat.cpp \
|
||||||
|
sharedviews/mcheaddialog.cpp \
|
||||||
|
sharedviews/headspacingsheetdialog.cpp \
|
||||||
|
mctype/patternsingleboard/function/fiveheadprecisionsewing.cpp \
|
||||||
|
sharedviews/fileselectdialog.cpp \
|
||||||
|
sharedviews/debuginfodialog.cpp \
|
||||||
|
items/nineitem.cpp \
|
||||||
|
mctype/patternsingleboard/function/clothingmac.cpp \
|
||||||
|
mctype/patternsingleboard/function/multineedlerotary.cpp \
|
||||||
|
# datafile/dxf/dxfhelper.cpp \
|
||||||
|
# datafile/dxf/dxfreader.cpp \
|
||||||
|
# datafile/dxf/dxflib/dl_dxf.cpp \
|
||||||
|
# datafile/dxf/dxflib/dl_writer_ascii.cpp \
|
||||||
|
datafile/hpgl/importhpgl.cpp \
|
||||||
|
datafile/hpgl/marker.cpp \
|
||||||
|
datafile/hpgl/vectorfont.cpp \
|
||||||
|
machine/mytcpserver.cpp \
|
||||||
|
mctype/patternsingleboard/function/thickwiringmac.cpp \
|
||||||
|
mctype/patternsingleboard/function/flyshuttle.cpp \
|
||||||
|
sharedviews/patterneditwidget.cpp \
|
||||||
|
sharedviews/view/mygraphicsscene.cpp \
|
||||||
|
sharedviews/view/mygraphicsview.cpp \
|
||||||
|
sharedviews/view/mygraphicsgriditem.cpp \
|
||||||
|
sharedviews/patternneedlelayoutwidget.cpp \
|
||||||
|
sharedviews/linegenerwidget.cpp \
|
||||||
|
sharedviews/shuttlebottomlinedialog.cpp \
|
||||||
|
mctype/patternsingleboard/function/glassfibremac.cpp \
|
||||||
|
mctype/patternsingleboard/function/doublelayeredmac.cpp \
|
||||||
|
mctype/patternsingleboard/function/dlqscheboard.cpp \
|
||||||
|
mctype/patternsingleboard/function/singlemutilneedlemac.cpp \
|
||||||
|
mctype/patternsingleboard/function/doublesidedbedsheets.cpp \
|
||||||
|
mctype/patternsingleboard/function/l2000multimac.cpp \
|
||||||
|
mctype/patternsingleboard/function/fullyautomatic.cpp \
|
||||||
|
mctype/patternsingleboard/function/pkgfoursidedtestboardmac.cpp \
|
||||||
|
mctype/patternsingleboard/function/autodoubledoormac.cpp \
|
||||||
|
mctype/patternsingleboard/function/doubleheadcombqui.cpp \
|
||||||
|
mctype/patternsingleboard/function/cuttingwalk.cpp \
|
||||||
|
sharedviews/knifegapparadialog.cpp \
|
||||||
|
mctype/patternsingleboard/function/fourheadcombqui.cpp
|
||||||
|
|
||||||
|
#windows下调用库
|
||||||
|
#win32:LIBS += $$PWD/../../HMI-Widget/XPlatform/Dll/Machine.dll
|
||||||
|
#win32:LIBS += $$PWD/../../HMI-Widget/XPlatform/Dll/DataFileComb.dll
|
||||||
|
|
||||||
|
#linux下调用库
|
||||||
|
#unix:LIBS += $$PWD/../../HMI-Widget/XPlatform/Dll/Machine
|
||||||
|
|
||||||
|
#RESOURCES += \
|
||||||
|
# bf.qrc
|
||||||
|
|
||||||
|
unix:INSTALLS += target
|
||||||
|
unix:target.path=/storage/oprt
|
||||||
|
|
||||||
|
TRANSLATIONS += chinese.ts\
|
||||||
|
english.ts\
|
||||||
|
spanish.ts\
|
||||||
|
bengal.ts\
|
||||||
|
turkey.ts\
|
||||||
|
denmark.ts\
|
||||||
|
vietnamese.ts\
|
||||||
|
ukrainian.ts\
|
||||||
|
russian.ts\
|
||||||
|
france.ts\
|
||||||
|
polish.ts\ #波兰语
|
||||||
|
dutch.ts\ #荷兰语
|
||||||
|
german.ts #德语
|
||||||
|
|
||||||
|
|
||||||
|
unix:HEADERS += machine/qextserial/posix_qextserialport.h
|
||||||
|
unix:SOURCES += machine/qextserial/posix_qextserialport.cpp
|
||||||
|
unix:DEFINES += _TTY_POSIX_
|
||||||
|
|
||||||
|
win32:HEADERS += machine/qextserial/win_qextserialport.h
|
||||||
|
win32:SOURCES += machine/qextserial/win_qextserialport.cpp
|
||||||
|
win32:DEFINES += _TTY_WIN_
|
||||||
|
|
||||||
1248
datafile/datafiledsr.cpp
Normal file
1248
datafile/datafiledsr.cpp
Normal file
File diff suppressed because it is too large
Load Diff
226
datafile/datafiledsr.h
Normal file
226
datafile/datafiledsr.h
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
#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_5_2 5.20f
|
||||||
|
#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
|
||||||
|
int bisect; //平分参数
|
||||||
|
// 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
|
||||||
|
u16 HStep; // 0x1E—0x1F; 水平方向针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
u16 leftRightLen; // 0x20—0x21; 左针右针距离 单位:0.1mm(绘制用,多针机)
|
||||||
|
u16 VStep12; // 0x22—0x23; 第1 2排针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
u16 VStep23; // 0x24—0x25; 第2 3排针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
|
||||||
|
// 针位n (0x00:无针,0x01:右针, 0x10:左针,0x11:左右针)
|
||||||
|
u8 arrayNeedle1[48]; // 0x26—0x55; 第1排排针(绘制用,多针机)
|
||||||
|
u8 arrayNeedle2[48]; // 0x56—0x85; 第2排排针(绘制用,多针机)
|
||||||
|
u8 arrayNeedle3[48]; // 0x86—0xB5; 第3排排针(绘制用,多针机)
|
||||||
|
|
||||||
|
// 0x77
|
||||||
|
u8 rotation; //0x10F; 旋转角度调整
|
||||||
|
s16 oftNeedleSize; //去除偏移针步大小设置
|
||||||
|
//BYTE reserved4[0x100-0x77]; // 保留字节
|
||||||
|
// 0x100
|
||||||
|
// u8 reserved5[0x200-0x10F]; //BYTE // 保留字节
|
||||||
|
u8 reserved5[0x200-0x112]; //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 // 结束码
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
class DataFileDsr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataFileDsr();
|
||||||
|
DataFileDsr(const QString & fullPathName);
|
||||||
|
~DataFileDsr();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initFile(const QString & fullPathName);
|
||||||
|
int checkDsrVersion();//检查dsr文件版本,非5.2和6.3版本和错误格式返回-1
|
||||||
|
void convertDataToEmbAbs(int scanX = 0,int scanY = 0); // 转换为绝对数据
|
||||||
|
//是否保存 //笔宽
|
||||||
|
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 writeStartPointToFile(int x, int y);
|
||||||
|
void writeAnchorPointToFile(int x, int y);
|
||||||
|
void writeFileLL(int Left, int front);//写入左边前边到文件
|
||||||
|
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);
|
||||||
|
void getDsrMinMax();
|
||||||
|
inline int getDsrMaxX(){return m_maxX;}//得到数据最大X+
|
||||||
|
inline int getDsrMinX(){return m_minX;}//得到数据最小X-
|
||||||
|
inline int getDsrMaxY(){return m_maxY;}//得到数据最大Y+
|
||||||
|
inline int getDsrMinY(){return m_minY;}//得到数据最小Y-
|
||||||
|
|
||||||
|
int getStepNums(); //获取换色数
|
||||||
|
|
||||||
|
int getBisect();//获取平分距离
|
||||||
|
|
||||||
|
void set62ExHead(DsrHeadEx62 data);
|
||||||
|
DsrHeadEx62 & get62ExHead();
|
||||||
|
const QPoint& getFirstPoint();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString m_fileFullPathName; // 文件路径
|
||||||
|
QByteArray m_embAbsData; // 转换后的绝对坐标数据
|
||||||
|
|
||||||
|
private:
|
||||||
|
QByteArray m_fileData;// 文件数据内容(原始数据)
|
||||||
|
QString m_fileName; // 文件路径
|
||||||
|
QPoint m_firstPoint; //第一点相对左下角坐标
|
||||||
|
|
||||||
|
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文件是否加密
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATAFILEDSR_H
|
||||||
988
datafile/datafiledst.cpp
Normal file
988
datafile/datafiledst.cpp
Normal file
@ -0,0 +1,988 @@
|
|||||||
|
#include "datafiledst.h"
|
||||||
|
|
||||||
|
|
||||||
|
DataFileDst::DataFileDst()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DataFileDst::DataFileDst(const QString &fullPathName)
|
||||||
|
{
|
||||||
|
initFile(fullPathName);
|
||||||
|
loadFile();
|
||||||
|
convertDataToAbs();
|
||||||
|
}
|
||||||
|
|
||||||
|
DataFileDst::~DataFileDst()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::clear()
|
||||||
|
{
|
||||||
|
m_fileFullPathName.clear(); // 文件路径
|
||||||
|
m_fileData.clear(); // 文件数据内容
|
||||||
|
m_embAbsData.clear(); // 转换后的数据
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::initFile(const QString &fullPathName)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
QFileInfo file(fullPathName);
|
||||||
|
if (file.exists() && file.isFile())
|
||||||
|
{
|
||||||
|
m_fileFullPathName = fullPathName;
|
||||||
|
m_fileName = fullPathName;
|
||||||
|
qDebug()<<"m_fileFullPathName 1"<<m_fileFullPathName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "Init file failed path =" << m_fileFullPathName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::loadFile()
|
||||||
|
{
|
||||||
|
QFile rdfile(m_fileFullPathName);
|
||||||
|
if(!rdfile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fileData = rdfile.readAll();
|
||||||
|
|
||||||
|
rdfile.close();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::saveFile()
|
||||||
|
{
|
||||||
|
QFile wrfile(m_fileFullPathName);
|
||||||
|
if(!wrfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||||
|
{
|
||||||
|
qDebug() << "open file fail when wirte, path =" << m_fileFullPathName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wrfile.write(m_fileData);
|
||||||
|
wrfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件所在目录
|
||||||
|
QString DataFileDst::getFileFullPath()
|
||||||
|
{
|
||||||
|
QFileInfo file(m_fileFullPathName);
|
||||||
|
return file.absoluteFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件名称(包括扩展名)
|
||||||
|
QString DataFileDst::getFileFullName()
|
||||||
|
{
|
||||||
|
QFileInfo file(m_fileFullPathName);
|
||||||
|
return file.fileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件名称(不包括扩展名)
|
||||||
|
QString DataFileDst::getFileName()
|
||||||
|
{
|
||||||
|
QFileInfo file(m_fileFullPathName);
|
||||||
|
return file.completeBaseName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件扩展名
|
||||||
|
QString DataFileDst::getFileSuffix()
|
||||||
|
{
|
||||||
|
QFileInfo file(m_fileFullPathName);
|
||||||
|
return file.suffix();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getStitchNums()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return pDstHead->itemNums;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getDatWidth()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return (pDstHead->maxX - pDstHead->minX);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getDatHeight()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return (pDstHead->maxY - pDstHead->minY);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getMaxX()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return pDstHead->maxX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getMinX()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return pDstHead->minX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getMaxY()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return pDstHead->maxY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getMinY()
|
||||||
|
{
|
||||||
|
if(m_embAbsData.size() <= 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataDs16FileHead * pDstHead = (DataDs16FileHead *)((m_embAbsData.data()));
|
||||||
|
return pDstHead->minY;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::getBeginXYAndAnchorXY(int &beginX, int &beginY, int &anchorX, int &anchorY)
|
||||||
|
{
|
||||||
|
int size = m_fileData.size();
|
||||||
|
if (size <= (int)(sizeof(DstHead)))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DstHead * pDstHead = (DstHead *)((m_fileData.data()));
|
||||||
|
beginX = pDstHead->startX;
|
||||||
|
beginY = pDstHead->startY;
|
||||||
|
anchorX = pDstHead->anchorX;
|
||||||
|
anchorY = pDstHead->anchorY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QPoint &DataFileDst::getFirstPoint()
|
||||||
|
{
|
||||||
|
return m_firstPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换为绝对坐标数据,同时得到最大最小值
|
||||||
|
void DataFileDst::convertDataToAbs(int scanX,int scanY)
|
||||||
|
{
|
||||||
|
QByteArray ds4Data;//相对坐标
|
||||||
|
m_embAbsData.clear();
|
||||||
|
loadFile(); // 如果数据未读取,重新读取
|
||||||
|
|
||||||
|
int size = m_fileData.size();
|
||||||
|
if (size <= (int)(sizeof(DstHead)))
|
||||||
|
{
|
||||||
|
qDebug("dst size less then headsize");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// int dstHeadSize = sizeof(DstHead);
|
||||||
|
// qDebug()<<"dstHeadSize"<<dstHeadSize;
|
||||||
|
|
||||||
|
size -= sizeof(DstHead);
|
||||||
|
int stepsize = size/sizeof(DstStep);
|
||||||
|
if (stepsize <= 0)
|
||||||
|
{
|
||||||
|
qDebug("dst data size err");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DstHead * dstHead = (DstHead *)(m_fileData.data());
|
||||||
|
DstStep * dstDataBeg = (DstStep *)((m_fileData.data() + sizeof(DstHead)));
|
||||||
|
DstStep * dstDataPtr = dstDataBeg;
|
||||||
|
|
||||||
|
// 绝对坐标数据
|
||||||
|
DataDs16FileHead dhead;
|
||||||
|
memset(&dhead, 0, sizeof(DataDs16FileHead));
|
||||||
|
|
||||||
|
Ds4Item * pData = new Ds4Item[stepsize];
|
||||||
|
if (pData == NULL)
|
||||||
|
{
|
||||||
|
qDebug("new DsAbsItem failed, size=%d", stepsize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ds4Item ds4Item;
|
||||||
|
u8 ctrl, attr;
|
||||||
|
int dx, dy;
|
||||||
|
int rslt;
|
||||||
|
u32 jumpNeedleNum = 0;
|
||||||
|
// 得到最大最小值, 同时转换为相对坐标数据
|
||||||
|
int i = 0;
|
||||||
|
int stepidx = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (i < stepsize)
|
||||||
|
{
|
||||||
|
rslt = changeDstStep(dstDataPtr, ds4Item);//三字节针步转换
|
||||||
|
if (rslt >= 0)
|
||||||
|
{
|
||||||
|
ctrl = ds4Item.ctrl;
|
||||||
|
attr = ds4Item.attr;
|
||||||
|
|
||||||
|
if ( ctrl == DATA_SEWING ||
|
||||||
|
ctrl == DATA_OFFSET ||
|
||||||
|
0 )
|
||||||
|
{
|
||||||
|
if(ctrl == DATA_OFFSET)
|
||||||
|
{
|
||||||
|
jumpNeedleNum++;
|
||||||
|
}
|
||||||
|
|
||||||
|
dx = ds4Item.dx * DATAFACTOR;
|
||||||
|
dy = ds4Item.dy * DATAFACTOR;
|
||||||
|
|
||||||
|
if ((attr & 0x80) != 0)
|
||||||
|
{
|
||||||
|
dx *= -1;
|
||||||
|
}
|
||||||
|
if ((attr & 0x40) != 0)
|
||||||
|
{
|
||||||
|
dy *= -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&(pData[stepidx]), &ds4Item, sizeof(Ds4Item));
|
||||||
|
stepidx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
dstDataPtr++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}while(1);
|
||||||
|
|
||||||
|
//qDebug()<<"Ds4Item end";
|
||||||
|
//再将相对坐标转换为绝对坐标---开始
|
||||||
|
ds4Data.append((char *)pData, stepidx*sizeof(Ds4Item));//相对坐标字节数组
|
||||||
|
u32 fileID = 0;
|
||||||
|
fileID = calcCheckSum32((u8 *)(ds4Data.data()) , ds4Data.length()); // 原始数据累加校验和
|
||||||
|
|
||||||
|
QByteArray absItemAry;
|
||||||
|
absItemAry.clear();
|
||||||
|
|
||||||
|
DsAbsItem absItem;
|
||||||
|
memset(&absItem,0,sizeof(DsAbsItem));
|
||||||
|
u8 ctrlByte;
|
||||||
|
u8 attrByte;
|
||||||
|
|
||||||
|
m_maxX = S32_MIN;
|
||||||
|
m_maxY = S32_MIN;
|
||||||
|
m_minY = S32_MAX;
|
||||||
|
m_minX = S32_MAX;
|
||||||
|
|
||||||
|
s16 dataDirX = DST_EMB_DATADIRX;
|
||||||
|
s16 dataDirY = DST_EMB_DATADIRY;
|
||||||
|
|
||||||
|
if(g_emMacType == MACHINE_FLYSHUTTLE || g_emMacType == MACHINE_L2000_MULTI)
|
||||||
|
{
|
||||||
|
dataDirX *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ds4Item * pDs4Data = (Ds4Item *)(ds4Data.data());
|
||||||
|
Ds4Item * ds4DataPtr = pDs4Data;
|
||||||
|
|
||||||
|
s32 ax = dstHead->startX;//第一个点
|
||||||
|
s32 ay = dstHead->startY;
|
||||||
|
s32 ar = 0;
|
||||||
|
|
||||||
|
const s32 firstX = ax;
|
||||||
|
const s32 firstY = ay;
|
||||||
|
|
||||||
|
Ds4Item * ds4DataTemp = (Ds4Item *)(ds4Data.data()); // ljs
|
||||||
|
int ds4StepSize = ds4Data.size()/sizeof(Ds4Item);
|
||||||
|
int runflag = 0;
|
||||||
|
int delStepNum = 0; // ljs
|
||||||
|
|
||||||
|
for (int i = 0; i < ds4StepSize; i++)
|
||||||
|
{
|
||||||
|
// 读入一个针步数据
|
||||||
|
ctrlByte = ds4DataPtr->ctrl;
|
||||||
|
attrByte = ds4DataPtr->attr;
|
||||||
|
int ddx = ds4DataPtr->dx * DATAFACTOR;
|
||||||
|
int ddy = ds4DataPtr->dy * DATAFACTOR;
|
||||||
|
|
||||||
|
if ((attrByte & 0x80) != 0)
|
||||||
|
{
|
||||||
|
ddx *= -1;
|
||||||
|
}
|
||||||
|
if ((attrByte & 0x40) != 0)
|
||||||
|
{
|
||||||
|
ddy *= -1;
|
||||||
|
}
|
||||||
|
ddx *= dataDirX;
|
||||||
|
ddy *= dataDirY;
|
||||||
|
|
||||||
|
ax += ddx;
|
||||||
|
ay += ddy;
|
||||||
|
|
||||||
|
double tar = atan2(ddy,ddx);
|
||||||
|
ar = (tar * 10000+0.5*(tar>0?1:-1));
|
||||||
|
|
||||||
|
if(ctrlByte == DATA_OFFSET)
|
||||||
|
{
|
||||||
|
if (runflag == 0)
|
||||||
|
{
|
||||||
|
runflag = 1;
|
||||||
|
}
|
||||||
|
runflag++;
|
||||||
|
}
|
||||||
|
else if(ctrlByte == DATA_SEWING)//第一针不转换为跳针
|
||||||
|
{
|
||||||
|
if ((runflag == 0 || runflag > 3) && (i > 0)) // 第一个运针是入针
|
||||||
|
{
|
||||||
|
ctrlByte = DATA_OFFSET;
|
||||||
|
runflag = 1;
|
||||||
|
}
|
||||||
|
else if (i == 0) // 20230511 第一针,入针,向后扫描,如果有连续的三个跳针,则将第一针入针转换为跳针 ljs
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ds4DataTemp++;
|
||||||
|
if (ds4DataTemp->ctrl == DATA_OFFSET)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
if (ds4DataTemp->dx == 0 && ds4DataTemp->dy == 0) // 空跳,直接变成跳针
|
||||||
|
{
|
||||||
|
count += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}while(1);
|
||||||
|
if (count >= 3)
|
||||||
|
{
|
||||||
|
ctrlByte = DATA_OFFSET;
|
||||||
|
runflag = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runflag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runflag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ctrlByte == DATA_CHGND) // 换色
|
||||||
|
{
|
||||||
|
runflag = 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runflag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//中间数据
|
||||||
|
absItem.ctrl = ctrlByte;
|
||||||
|
absItem.attr = attrByte & ~(0x80|0x40);
|
||||||
|
absItem.ax = ax;
|
||||||
|
absItem.ay = ay;
|
||||||
|
absItem.ar = ar;
|
||||||
|
|
||||||
|
if (ax > m_maxX)
|
||||||
|
{
|
||||||
|
m_maxX = ax;
|
||||||
|
}
|
||||||
|
if (ax < m_minX)
|
||||||
|
{
|
||||||
|
m_minX = ax;
|
||||||
|
}
|
||||||
|
if (ay > m_maxY)
|
||||||
|
{
|
||||||
|
m_maxY = ay;
|
||||||
|
}
|
||||||
|
if (ay < m_minY)
|
||||||
|
{
|
||||||
|
m_minY = ay;
|
||||||
|
}
|
||||||
|
|
||||||
|
absItemAry.append((char*)&absItem,sizeof(DsAbsItem));
|
||||||
|
ds4DataPtr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
double factorX = 1.0;
|
||||||
|
double factorY = 1.0;
|
||||||
|
if(scanX != 0 || scanY != 0)
|
||||||
|
{
|
||||||
|
if(scanX != 0)
|
||||||
|
{
|
||||||
|
factorX = (double)scanX / (double)(m_maxX - m_minX);
|
||||||
|
}
|
||||||
|
if(scanY != 0)
|
||||||
|
{
|
||||||
|
factorY = (double)scanY / (double)(m_maxY - m_minY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(factorX != 1.0 || factorY != 1.0)
|
||||||
|
{
|
||||||
|
DsAbsItem *absItem = (DsAbsItem*)(absItemAry.data());
|
||||||
|
for(u32 j = 0; j < absItemAry.size()/sizeof(DsAbsItem); j++)
|
||||||
|
{
|
||||||
|
absItem->ax *= factorX;
|
||||||
|
absItem->ay *= factorY;
|
||||||
|
absItem++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int newstepnum = ds4StepSize-delStepNum; // 转换后的数据长度 ljs
|
||||||
|
|
||||||
|
QString name = getFileFullName();
|
||||||
|
QByteArray tempdata = name.toLocal8Bit();
|
||||||
|
int namelen = tempdata.size();
|
||||||
|
if (namelen > HEAD_NAME_STR_LEN)
|
||||||
|
{
|
||||||
|
namelen = HEAD_NAME_STR_LEN;
|
||||||
|
}
|
||||||
|
memcpy(dhead.fileName, tempdata.constData(), namelen); // 文件名称
|
||||||
|
dhead.fileName[namelen] = 0;
|
||||||
|
|
||||||
|
dhead.dataSize = newstepnum*sizeof(DsAbsItem); // 数据字节数
|
||||||
|
dhead.itemNums = newstepnum; // 数据项个数
|
||||||
|
dhead.bytesPerItem = sizeof(DsAbsItem); // 每项占的字节数
|
||||||
|
dhead.bytesPerBlk = MAX_EXDP_LEN; // 数据内容划分块大小
|
||||||
|
dhead.dataChecksum = calcCheckSum32((u8 *)(absItemAry.data()) , dhead.dataSize); // 数据累加校验和
|
||||||
|
dhead.checkCrc = calcCrc16((u8 *)(&dhead), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验,(6个字段分别为:文件名称,字节数,项个数,每项字节数,每块字节数,数据累加和的CRC校验值)
|
||||||
|
dhead.fileid = fileID;
|
||||||
|
|
||||||
|
dhead.anchorX = dstHead->anchorX; // 定位点坐标X
|
||||||
|
dhead.anchorY = dstHead->anchorY; // 定位点坐标Y
|
||||||
|
dhead.beginX = dstHead->startX; // 数据起点坐标X
|
||||||
|
dhead.beginY = dstHead->startY; // 数据起点坐标Y
|
||||||
|
dhead.beginR = 0; // 数据起点坐标R
|
||||||
|
|
||||||
|
qDebug() << "==========================dhead.anchorX " << dhead.anchorX;
|
||||||
|
qDebug() << "==========================dhead.anchorY " << dhead.anchorY;
|
||||||
|
qDebug() << "==========================dhead.beginX " << dhead.beginX;
|
||||||
|
qDebug() << "==========================dhead.beginY " << dhead.beginY;
|
||||||
|
|
||||||
|
dhead.minX = m_minX-m_minX;
|
||||||
|
dhead.maxX = m_maxX-m_minX;
|
||||||
|
dhead.minY = m_minY-m_minY;
|
||||||
|
dhead.maxY = m_maxY-m_minY; // 轮廓范围,使用重新计算之后的值
|
||||||
|
|
||||||
|
m_firstPoint = QPoint(firstX - static_cast<int>(m_minX), firstY - static_cast<int>(m_minY)); //反推第一点的相对左边前边的坐标
|
||||||
|
|
||||||
|
m_embAbsData.append((char *)(&dhead), sizeof(DataDs16FileHead));
|
||||||
|
m_embAbsData.append(absItemAry);
|
||||||
|
|
||||||
|
delete []pData;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::writePointToFile(int x, int y, int flag)
|
||||||
|
{
|
||||||
|
if(m_fileData.size() <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DstHead * pDstHead = (DstHead *)((m_fileData.data()));
|
||||||
|
if(flag)
|
||||||
|
{
|
||||||
|
pDstHead->anchorX = x;
|
||||||
|
pDstHead->anchorY = y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pDstHead->startX = x;
|
||||||
|
pDstHead->startY = y;
|
||||||
|
}
|
||||||
|
QFile wfile(m_fileFullPathName);
|
||||||
|
if(!wfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||||
|
{
|
||||||
|
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wfile.write(m_fileData);
|
||||||
|
wfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::writeStartPointToFile(int x, int y)
|
||||||
|
{
|
||||||
|
writePointToFile(x,y,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::writeAnchorPointToFile(int x, int y)
|
||||||
|
{
|
||||||
|
writePointToFile(x,y,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DataFileDst::writeFileLL(int Left, int front)
|
||||||
|
{
|
||||||
|
if(m_fileData.size() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DstHead * pDstHead = (DstHead *)((m_fileData.data()));
|
||||||
|
pDstHead->left = Left;
|
||||||
|
pDstHead->front = front;
|
||||||
|
|
||||||
|
QFile wfile(m_fileFullPathName);
|
||||||
|
if(!wfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||||
|
{
|
||||||
|
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wfile.write(m_fileData);
|
||||||
|
wfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::writePatternParaToFile(DstHead *head)
|
||||||
|
{
|
||||||
|
if(m_fileData.size() <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(m_fileData.data(),(char*)head,sizeof(DstHead));
|
||||||
|
|
||||||
|
QFile wfile(m_fileFullPathName);
|
||||||
|
if(!wfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
||||||
|
{
|
||||||
|
qDebug() << "open file fail when read, path =" << m_fileFullPathName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wfile.write(m_fileData);
|
||||||
|
wfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataFileDst::checkDstFile()
|
||||||
|
{
|
||||||
|
loadFile(); // 如果数据未读取,重新读取
|
||||||
|
|
||||||
|
int size = m_fileData.size();
|
||||||
|
if (size <= (int)(sizeof(DstHead)))
|
||||||
|
{
|
||||||
|
qDebug("dsr size less then headsize");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size -= sizeof(DstHead);
|
||||||
|
int stepsize = size/sizeof(DstStep);
|
||||||
|
if (stepsize <= 0)
|
||||||
|
{
|
||||||
|
qDebug("dst data size err");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepsize > PATTERN_LARGE_NEEDLES)//128万针
|
||||||
|
{
|
||||||
|
qDebug("dsr data size big");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stepsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
DstHead *DataFileDst::getDstHead()
|
||||||
|
{
|
||||||
|
if(m_fileData.size() <= 0)
|
||||||
|
{
|
||||||
|
loadFile(); // 如果数据未读取,重新读取
|
||||||
|
}
|
||||||
|
DstHead *head = NULL;
|
||||||
|
|
||||||
|
int size = m_fileData.size();
|
||||||
|
if (size <= (int)(sizeof(DstHead)))
|
||||||
|
{
|
||||||
|
head = new DstHead;
|
||||||
|
memset(head,0,sizeof(DstHead));
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
head = (DstHead *)((m_fileData.data()));
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFileDst::moveDataBeginPonit(s32 left, s32 front)
|
||||||
|
{
|
||||||
|
if((u32)m_embAbsData.size() > sizeof(DataDs16FileHead))
|
||||||
|
{
|
||||||
|
DataDs16FileHead *dhead = (DataDs16FileHead *)( m_embAbsData.data());
|
||||||
|
dhead->beginX += left;
|
||||||
|
dhead->beginY += front;
|
||||||
|
dhead->maxX += left;
|
||||||
|
dhead->minX += left;
|
||||||
|
dhead->maxY += front;
|
||||||
|
dhead->minY += front;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 生成预览文件
|
||||||
|
int DataFileDst::createPreviewImage(QImage * pImg, int saveflag, int penwidth, int reDraw)
|
||||||
|
{
|
||||||
|
#if(1)
|
||||||
|
if(reDraw == 0)//图片存在则不重画
|
||||||
|
{
|
||||||
|
// 图片是否存在,存在则返回
|
||||||
|
QString previewPath = getFileFullPathName() + ".preview.png";
|
||||||
|
QFile imageFile(previewPath);
|
||||||
|
if (imageFile.exists())
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int newimgflag = 0;
|
||||||
|
QImage * pImage;
|
||||||
|
int width, height;
|
||||||
|
if (pImg == NULL)
|
||||||
|
{
|
||||||
|
width = DST_PREVIEW_WIDTH;
|
||||||
|
height = DST_PREVIEW_HEIGHT;
|
||||||
|
pImage = new QImage(width, height, IMAGE_TYPE);
|
||||||
|
newimgflag = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pImage = pImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
width = pImage->width();
|
||||||
|
height = pImage->height();
|
||||||
|
if (width <= DST_PREVIEW_SIDE*2 || height <= DST_PREVIEW_SIDE*2)
|
||||||
|
{
|
||||||
|
if (pImage != NULL && newimgflag == 1)
|
||||||
|
{
|
||||||
|
delete pImage;
|
||||||
|
}
|
||||||
|
qDebug("preview img too small");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(pImage->bits(), 0x00, pImage->byteCount());
|
||||||
|
|
||||||
|
QPainter painter(pImage);
|
||||||
|
QColor backcolor(255, 255, 255, 0); // 透明背景
|
||||||
|
// 背景
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth(penwidth);
|
||||||
|
pen.setColor(backcolor);
|
||||||
|
painter.setPen(pen);
|
||||||
|
painter.setBrush(backcolor);
|
||||||
|
painter.drawRect(0, 0, width, height);
|
||||||
|
|
||||||
|
// 图形
|
||||||
|
//qDebug()<<"convertDataToAbs defore";
|
||||||
|
convertDataToAbs(); // 转换为绝对坐标数据
|
||||||
|
//qDebug()<<"convertDataToAbs end";
|
||||||
|
|
||||||
|
// absdat数据
|
||||||
|
int size = m_embAbsData.size();
|
||||||
|
if (size <= (int)sizeof(DataDs16FileHead))
|
||||||
|
{
|
||||||
|
qDebug("2 data less then head size");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
DataDs16FileHead * pAbsHead = (DataDs16FileHead *)(m_embAbsData.data());
|
||||||
|
int datasize = size - sizeof(DataDs16FileHead);
|
||||||
|
if (datasize <= 0)
|
||||||
|
{
|
||||||
|
qDebug("absdat dataBegin err");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int stepsize = datasize/sizeof(DsAbsItem);
|
||||||
|
if (stepsize <= 0)
|
||||||
|
{
|
||||||
|
qDebug("absdat data size err");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
DsAbsItem * pData = (DsAbsItem *)(m_embAbsData.data() + sizeof(DataDs16FileHead));
|
||||||
|
DsAbsItem * absDataPtr = pData;
|
||||||
|
//--------
|
||||||
|
|
||||||
|
// 图形显示区域
|
||||||
|
int dpminx = DST_PREVIEW_SIDE;
|
||||||
|
int dpmaxx = width - DST_PREVIEW_SIDE;
|
||||||
|
int dpminy = DST_PREVIEW_SIDE;
|
||||||
|
int dpmaxy = height - DST_PREVIEW_SIDE;
|
||||||
|
|
||||||
|
// 计算缩放系数
|
||||||
|
double factor, temp;
|
||||||
|
if ((dpmaxx - dpminx) <= 0 || (dpmaxy - dpminy) <= 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
factor = (double)(fabs(m_maxX - m_minX)) / (dpmaxx - dpminx); // 按x计算的缩放系数
|
||||||
|
temp = (double)(fabs(m_maxY - m_minY)) / (dpmaxy - dpminy); // 按x计算的缩放系数
|
||||||
|
|
||||||
|
if (temp >= factor) // 使用较大的缩放系数
|
||||||
|
{
|
||||||
|
factor = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算显示参数,按照图形的实际位置显示(数据坐标零点对应图形中心)
|
||||||
|
int dpx = (int)((dpminx+dpmaxx)/2 - ((m_maxX+m_minX)/factor)/2);
|
||||||
|
int dpy = (int)((dpminy+dpmaxy)/2 - ((m_maxY+m_minY)/factor)/2);
|
||||||
|
|
||||||
|
// 显示花样图形
|
||||||
|
u8 ctrlByte;
|
||||||
|
int dx;
|
||||||
|
int dy;
|
||||||
|
|
||||||
|
double datposx, datposy;
|
||||||
|
int curx, cury, prex, prey;
|
||||||
|
|
||||||
|
datposx = pAbsHead->beginX;
|
||||||
|
datposy = pAbsHead->beginY;
|
||||||
|
|
||||||
|
curx = (datposx) / factor + dpx;
|
||||||
|
cury = (datposy) / factor + dpy;
|
||||||
|
|
||||||
|
if (DST_SHOWDIRX == -1)
|
||||||
|
{
|
||||||
|
curx = (width)-curx;
|
||||||
|
}
|
||||||
|
if (DST_SHOWDIRY == -1)
|
||||||
|
{
|
||||||
|
cury = (height)-cury;
|
||||||
|
}
|
||||||
|
|
||||||
|
absDataPtr = pData;
|
||||||
|
|
||||||
|
QColor embcolor = QColor(Qt::green);
|
||||||
|
pen.setColor(embcolor);
|
||||||
|
painter.setPen(pen);
|
||||||
|
|
||||||
|
for (int i = 0; i < stepsize; i++)
|
||||||
|
{
|
||||||
|
// 读入一个针步数据
|
||||||
|
ctrlByte = absDataPtr->ctrl;
|
||||||
|
|
||||||
|
if ( ctrlByte == DATA_SEWING ||
|
||||||
|
0 )
|
||||||
|
{
|
||||||
|
prex = curx;
|
||||||
|
prey = cury;
|
||||||
|
|
||||||
|
dx = absDataPtr->ax;
|
||||||
|
dy = absDataPtr->ay;
|
||||||
|
|
||||||
|
datposx = dx;
|
||||||
|
datposy = dy;
|
||||||
|
|
||||||
|
curx = (datposx) / factor + dpx;
|
||||||
|
cury = (datposy) / factor + dpy;
|
||||||
|
|
||||||
|
if (DST_SHOWDIRX == -1)
|
||||||
|
{
|
||||||
|
curx = (width)-curx;
|
||||||
|
}
|
||||||
|
if (DST_SHOWDIRY == -1)
|
||||||
|
{
|
||||||
|
cury = (height)-cury;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i != 0)
|
||||||
|
{
|
||||||
|
painter.drawLine(prex, prey, curx, cury);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//如果连续两步都是跳针,则过滤掉
|
||||||
|
else if (ctrlByte == DATA_OFFSET)
|
||||||
|
{
|
||||||
|
DsAbsItem * JumpAbsDataPtr = pData;
|
||||||
|
JumpAbsDataPtr = absDataPtr - 1;
|
||||||
|
u8 beforectrlByte = JumpAbsDataPtr->ctrl;
|
||||||
|
|
||||||
|
JumpAbsDataPtr = absDataPtr + 2;
|
||||||
|
u8 nextctrlByte = JumpAbsDataPtr->ctrl;
|
||||||
|
|
||||||
|
prex = curx;
|
||||||
|
prey = cury;
|
||||||
|
|
||||||
|
dx = absDataPtr->ax;
|
||||||
|
dy = absDataPtr->ay;
|
||||||
|
|
||||||
|
datposx = dx;
|
||||||
|
datposy = dy;
|
||||||
|
|
||||||
|
curx = (datposx) / factor + dpx;
|
||||||
|
cury = (datposy) / factor + dpy;
|
||||||
|
|
||||||
|
if (DST_SHOWDIRX == -1)
|
||||||
|
{
|
||||||
|
curx = (width)-curx;
|
||||||
|
}
|
||||||
|
if (DST_SHOWDIRY == -1)
|
||||||
|
{
|
||||||
|
cury = (height)-cury;
|
||||||
|
}
|
||||||
|
|
||||||
|
pen.setColor(embcolor);
|
||||||
|
painter.setPen(pen);
|
||||||
|
|
||||||
|
if(beforectrlByte == DATA_OFFSET || nextctrlByte == DATA_OFFSET)
|
||||||
|
{
|
||||||
|
//该针上下两针都是跳针则不画线
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(i != 0)
|
||||||
|
{
|
||||||
|
painter.drawLine(prex, prey, curx, cury);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
absDataPtr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存成文件
|
||||||
|
QString preview = getFileFullPathName();
|
||||||
|
if (saveflag != 0 && preview.isEmpty() == false)
|
||||||
|
{
|
||||||
|
#if (1)
|
||||||
|
preview += ".preview.png";
|
||||||
|
pImage->save(preview, "png");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pImage != NULL && newimgflag == 1)
|
||||||
|
{
|
||||||
|
delete pImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define EMB_DST_DAT_DIRX (-1) // X向DST数据坐标和绝对数据坐标的差异
|
||||||
|
#define EMB_DST_DAT_DIRY (1) // Y向DST数据坐标和绝对数据坐标的差异
|
||||||
|
|
||||||
|
// 针步转换
|
||||||
|
int DataFileDst::changeDstStep(DstStep * pDststep, Ds4Item & ds4step)
|
||||||
|
{
|
||||||
|
int dx, dy;
|
||||||
|
u8 c1, c2, c3;
|
||||||
|
u8 ctrl, attr;
|
||||||
|
|
||||||
|
if (pDststep == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
c1 = pDststep->c1;
|
||||||
|
c2 = pDststep->c2;
|
||||||
|
c3 = pDststep->c3;
|
||||||
|
|
||||||
|
dx = 0;
|
||||||
|
dy = 0;
|
||||||
|
|
||||||
|
if ((c1&0x08) != 0) { dx -= 9; }
|
||||||
|
if ((c1&0x04) != 0) { dx += 9; }
|
||||||
|
if ((c1&0x02) != 0) { dx -= 1; }
|
||||||
|
if ((c1&0x01) != 0) { dx += 1; }
|
||||||
|
if ((c2&0x08) != 0) { dx -= 27; }
|
||||||
|
if ((c2&0x04) != 0) { dx += 27; }
|
||||||
|
if ((c2&0x02) != 0) { dx -= 3; }
|
||||||
|
if ((c2&0x01) != 0) { dx += 3; }
|
||||||
|
if ((c3&0x08) != 0) { dx -= 81; }
|
||||||
|
if ((c3&0x04) != 0) { dx += 81; }
|
||||||
|
|
||||||
|
if ((c1&0x10) != 0) { dy -= 9; }
|
||||||
|
if ((c1&0x20) != 0) { dy += 9; }
|
||||||
|
if ((c1&0x40) != 0) { dy -= 1; }
|
||||||
|
if ((c1&0x80) != 0) { dy += 1; }
|
||||||
|
if ((c2&0x10) != 0) { dy -= 27; }
|
||||||
|
if ((c2&0x20) != 0) { dy += 27; }
|
||||||
|
if ((c2&0x40) != 0) { dy -= 3; }
|
||||||
|
if ((c2&0x80) != 0) { dy += 3; }
|
||||||
|
if ((c3&0x10) != 0) { dy -= 81; }
|
||||||
|
if ((c3&0x20) != 0) { dy += 81; }
|
||||||
|
|
||||||
|
if (c3 == 0xF3 && dx == 0 && dy == 0)
|
||||||
|
{
|
||||||
|
ctrl = DATA_END; // 结束
|
||||||
|
}
|
||||||
|
else if ((c3&0xc3) == 0x03) // 运针
|
||||||
|
{
|
||||||
|
ctrl = DATA_SEWING;
|
||||||
|
}
|
||||||
|
else if ((c3&0xc3) == 0x83) // 偏移
|
||||||
|
{
|
||||||
|
ctrl = DATA_OFFSET;
|
||||||
|
}
|
||||||
|
else if ((c3&0xc3) == 0xC3) // 换色
|
||||||
|
{
|
||||||
|
ctrl = DATA_CHGND;
|
||||||
|
}
|
||||||
|
else if ((c3&0xc3) == 0x43) // 开关亮片码
|
||||||
|
{
|
||||||
|
qDebug("Sequin switch, not support, c1=0x%x, c2=0x%x, c3=0x%x", c1, c2, c3); // 不合法的DST
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug("not know dst step, c1=0x%x, c2=0x%x, c3=0x%x", c1, c2, c3); // 不合法的DST
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加针步
|
||||||
|
attr = 0;
|
||||||
|
|
||||||
|
dx *= EMB_DST_DAT_DIRX; // X向显示坐标和数据坐标的差异
|
||||||
|
dy *= EMB_DST_DAT_DIRY; // Y向显示坐标和数据坐标的差异
|
||||||
|
|
||||||
|
if (dx < 0) { attr |= 0x80; }
|
||||||
|
if (dy < 0) { attr |= 0x40; }
|
||||||
|
|
||||||
|
ds4step.ctrl = ctrl;
|
||||||
|
ds4step.attr = attr;
|
||||||
|
ds4step.dx = abs(dx);
|
||||||
|
ds4step.dy = abs(dy);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
163
datafile/datafiledst.h
Normal file
163
datafile/datafiledst.h
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
#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 "machine/comm/datadef.h"
|
||||||
|
#include "machine/comm/crc16.h"
|
||||||
|
#include "datafile/dataoperat.h"
|
||||||
|
#include "main.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 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; //前边
|
||||||
|
|
||||||
|
// 163
|
||||||
|
u8 rotation; //旋转角度调整
|
||||||
|
u8 reserved2[256-164]; //BYTE
|
||||||
|
|
||||||
|
// 256
|
||||||
|
s16 reserved3;
|
||||||
|
|
||||||
|
// 258
|
||||||
|
int anchorX; //定位点
|
||||||
|
int anchorY;
|
||||||
|
|
||||||
|
// 266
|
||||||
|
s32 startX; //起始点
|
||||||
|
s32 startY;
|
||||||
|
|
||||||
|
// 274
|
||||||
|
u8 reserved4[512-274]; //BYTE // 保留字节
|
||||||
|
};
|
||||||
|
#pragma pack(1)//恢复对齐状态
|
||||||
|
|
||||||
|
|
||||||
|
// 针步数据
|
||||||
|
typedef struct strDstStep
|
||||||
|
{
|
||||||
|
u8 c1; ////BYTE
|
||||||
|
u8 c2; ////BYTE
|
||||||
|
u8 c3; ////BYTE
|
||||||
|
}__attribute__ ((packed)) DstStep;
|
||||||
|
|
||||||
|
|
||||||
|
class DataFileDst
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataFileDst();
|
||||||
|
DataFileDst(const QString & fullPathName);
|
||||||
|
~DataFileDst();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initFile(const QString & fullPathName);
|
||||||
|
int createPreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int reDraw = 0); // 生成预览文件
|
||||||
|
void convertDataToAbs(int scanX = 0,int scanY = 0); // 转换为绝对坐标数据
|
||||||
|
void writePointToFile(int x, int y, int flag);//写入起始点到文件中
|
||||||
|
void writeStartPointToFile(int x, int y);
|
||||||
|
void writeAnchorPointToFile(int x, int y);
|
||||||
|
void writeFileLL(int Left, int front);//写入左边前边到文件
|
||||||
|
void writePatternParaToFile(DstHead *head);//将花样参数配置写到文件中
|
||||||
|
void writeOffsetXYMoveToFile(s32 EnFlag,s32 offsetX,s32 offsetY);
|
||||||
|
int checkDstFile();//检查dst文件是否正确
|
||||||
|
DstHead * getDstHead();
|
||||||
|
void moveDataBeginPonit(s32 left, s32 front);//移动数据起始点
|
||||||
|
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 getFileid();//得到fileid
|
||||||
|
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);
|
||||||
|
const QPoint& getFirstPoint();
|
||||||
|
protected:
|
||||||
|
QString m_fileFullPathName; // 文件路径
|
||||||
|
QByteArray m_embAbsData; // 转换后的绝对坐标数据
|
||||||
|
|
||||||
|
private:
|
||||||
|
QByteArray m_fileData;// 文件数据内容(原始数据)
|
||||||
|
QString m_fileName; // 文件路径
|
||||||
|
QPoint m_firstPoint; //第一点相对左下角坐标
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_minX;
|
||||||
|
double m_maxX;
|
||||||
|
double m_minY;
|
||||||
|
double m_maxY;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int changeDstStep(DstStep * pDststep, Ds4Item & ds4step);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATAFILEDST_H
|
||||||
1317
datafile/datafilequi.cpp
Normal file
1317
datafile/datafilequi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
155
datafile/datafilequi.h
Normal file
155
datafile/datafilequi.h
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
#ifndef DATAFILEQUI_H
|
||||||
|
#define DATAFILEQUI_H
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QString>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QRgb>
|
||||||
|
#include "math.h"
|
||||||
|
#include <QBrush>
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
//#include "vectorsqrt.h"
|
||||||
|
#include "machine/comm/datadef.h"
|
||||||
|
#include "machine/comm/crc16.h"
|
||||||
|
#include "datafile/dataoperat.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#define QUI_DATADIRX (1) // X向数据坐标与下位机坐标系统的差异
|
||||||
|
#define QUI_DATADIRY (1) // Y向数据坐标与下位机坐标系统的差异
|
||||||
|
#define QUI_DATADIRR (-1) // R向数据坐标与下位机坐标系统的差异
|
||||||
|
|
||||||
|
#define QUI_SHOWDIRX (1) // X向显示坐标和数据坐标的差异
|
||||||
|
#define QUI_SHOWDIRY (-1) // Y向显示坐标和数据坐标的差异
|
||||||
|
|
||||||
|
#define QUI_PREVIEW_SIDE (15) // 留边大小
|
||||||
|
#define QUI_PREVIEW_WIDTH (156) // 默认预览图区域宽度
|
||||||
|
#define QUI_PREVIEW_HEIGHT (164) // 默认预览图区域高度
|
||||||
|
|
||||||
|
#pragma pack(1)//设定为1字节对齐
|
||||||
|
|
||||||
|
typedef struct tagQuiltingFileHead
|
||||||
|
{
|
||||||
|
char id[4]; // 0x00—0x03; 标志:=="RICH"
|
||||||
|
char name[8]; // 0x04—0x07; 文件名
|
||||||
|
unsigned char reserve1[4]; // 0x0C—0x0F; 保留
|
||||||
|
unsigned char ver; // 0x10; 版本号
|
||||||
|
unsigned char unit; // 0x11; 单位 0x00: 0.1mm; 0x01: 1/1000inch; 0x02: 0.04mm;0x03: 0.01mm
|
||||||
|
unsigned char type; // 0x12; 类型, 0x00: 多针机英制; 0x01: 多针机公制; 0x10: 单头机英制; 0x11:单头机公制
|
||||||
|
unsigned char reserve2[11]; // 0x13—0x1D; 保留
|
||||||
|
unsigned short HStep; // 0x1E—0x1F; 水平方向针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
unsigned short leftRightLen; // 0x20—0x21; 左针右针距离 单位:0.1mm(绘制用,多针机)
|
||||||
|
unsigned short VStep12; // 0x22—0x23; 第1 2排针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
unsigned short VStep23; // 0x24—0x25; 第2 3排针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
|
||||||
|
// 排针每个字节:XXXX XXXX
|
||||||
|
// 针位n (0x00:无针,0x01:右针, 0x10:左针,0x11:左右针)
|
||||||
|
unsigned char arrayNeedle1[48]; // 0x26—0x55; 第1排排针(绘制用,多针机)
|
||||||
|
unsigned char arrayNeedle2[48]; // 0x56—0x85; 第2排排针(绘制用,多针机)
|
||||||
|
unsigned char arrayNeedle3[48]; // 0x86—0xB5; 第3排排针(绘制用,多针机)
|
||||||
|
unsigned char rotateStyle; // 0xB6; 旋转式样
|
||||||
|
unsigned char rotateAngle; // 0xB7; 旋转角度
|
||||||
|
unsigned char reinMode; // 0xB8; 加固方式
|
||||||
|
unsigned char reinNum; // 0xB9; 次数
|
||||||
|
unsigned char uniScale; // 等比缩放
|
||||||
|
unsigned char reserve3[3]; // 0xBB—0xBD; 保留
|
||||||
|
unsigned short angleCorrOffset; // 0xBE ; 角度修正量 (中间数据后,可以修改,拐角补偿,单针机和多针机,新加-hhy)
|
||||||
|
char angleCorrPosX; // 0xC0 ; 角度修正x正(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
char angleCorrPosY; // 0xC1 ; 角度修正y正(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
char angleCorrNegX; // 0xC2 ; 角度修正x负(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
char angleCorrNegY; // 0xC3 ; 角度修正y负(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
unsigned char stepQui[2]; // 0xC4—0xC5; 跨步绗缝
|
||||||
|
unsigned char reinNeedles; // 0xC6; 加固绗缝针数(中间数据后,可以修改,终点有跨步的才加,单针机和多针机)
|
||||||
|
short int rollaYUpDn; // 0xC7; 罗拉补偿y上下(中间数据后,让图形闭合,可以修改,多针机)
|
||||||
|
// unsigned char rollaYRev; // 0xC8; 罗拉补偿y预留
|
||||||
|
unsigned char normalStep; // 0xC9; 针步大小(中间数据前,可以修改,单针机和多针机)
|
||||||
|
unsigned char miniStep; // 0xCA; 最小针步
|
||||||
|
unsigned char reserve4[4]; // 0xCB—0xCE; 保留
|
||||||
|
unsigned char saddleRatio[2]; // 0xCF—0xD0; 鞍架比例
|
||||||
|
unsigned char rollaRatio[2]; // 0xD1—0xD2; 罗拉比例
|
||||||
|
unsigned char reinQuiNeedleHigh; // 0xD3; 加固绗缝针数高字节
|
||||||
|
unsigned short left; // 0xD4—0xD5; 左边 (中间数据后,可以修改,改变起始点,单针机)
|
||||||
|
unsigned short front; // 0xD6—0xD7; 前边 (中间数据后,可以修改,改变起始点,单针机)
|
||||||
|
unsigned short scanX; // 0xD8—0xD9; 缩放X (中间数据前,可以修改,单针机和多针机)
|
||||||
|
unsigned short scanY; // 0xDA—0xDB; 缩放Y (中间数据前,可以修改,单针机和多针机)
|
||||||
|
unsigned short totalOutput; // 0xDC—0xDD; 本花样累计总产量
|
||||||
|
unsigned short currentOutput; // 0xDE—0xDF; 本花样当次产量
|
||||||
|
unsigned short serWorkLa; // 0xE0-0xE1; 连续作业前留边
|
||||||
|
unsigned short serWorkLb; // 0xE2-0xE3; 连续作业后留边
|
||||||
|
unsigned char stepCompUpDn; // 0xE4; 跨步补偿y上下(多针机专业)(中间数据后,可以修改,多针机)
|
||||||
|
int startX; //用于存放起始点
|
||||||
|
int startY;
|
||||||
|
|
||||||
|
unsigned char setNormalStep; // 0xED; 针步大小
|
||||||
|
|
||||||
|
short int rollaYUpDnXNeg;
|
||||||
|
short int rollaYUpDnXZero;
|
||||||
|
unsigned char reserve6[14]; // 0xEE—0xFF; 保留
|
||||||
|
|
||||||
|
} __attribute__ ((packed)) QuiFileHead;
|
||||||
|
|
||||||
|
|
||||||
|
class DataFileQui
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataFileQui();
|
||||||
|
DataFileQui(const QString & fullPathName);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString m_fileFullPathName; // 文件路径
|
||||||
|
QByteArray m_absData; // 转换后的绝对坐标数据
|
||||||
|
QByteArray m_quiFileData;// 文件数据内容(原始数据)
|
||||||
|
QList<drawItem> m_drawItemLists;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_minX;
|
||||||
|
double m_maxX;
|
||||||
|
double m_minY;
|
||||||
|
double m_maxY;
|
||||||
|
QuiPoint m_firstPoint; //qui内部计算时使用
|
||||||
|
QPoint m_firstAbsolutePoint; //第一针实际绝对坐标点
|
||||||
|
|
||||||
|
private:
|
||||||
|
void creatAbsHeadAndAr(double left, double front);//生成绝对坐标数据文件头及ar
|
||||||
|
int checkFileHead();
|
||||||
|
double getMutiUnit(int unit);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initFile(const QString & fullPathName);
|
||||||
|
void clear();
|
||||||
|
void loadFile();
|
||||||
|
void convertDataToEmbAbs(s16 flag = 1);
|
||||||
|
int createPreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int reDraw = 0); // 生成预览文件
|
||||||
|
inline const QString & getFileFullPathName() const {return m_fileFullPathName;} // 文件路径名称
|
||||||
|
inline QByteArray & getEmbAbsData() {return m_absData;} // 得到转换后的数据
|
||||||
|
QuiFileHead *getQuiHead();
|
||||||
|
void writePatternParaToFile(QuiFileHead *head);//将花样参数配置写到文件中
|
||||||
|
void moveDataBeginPonit(s32 left, s32 front);//移动数据起始点
|
||||||
|
void creatDrawData(s32 scanX,s32 scanY,double sizeX,double sizeY,
|
||||||
|
int &maxX, int &minX, int &maxY, int &minY, int &pointsNum);//创建绘制数据
|
||||||
|
inline QList<drawItem> getDrawData() {return m_drawItemLists;} // 得到绘制数据
|
||||||
|
|
||||||
|
public:
|
||||||
|
int getStitchNums();//得到数据的针数
|
||||||
|
int getDatWidth();//得到数据的图形宽度
|
||||||
|
int getDatHeight();//得到数据的图形高度
|
||||||
|
int getMaxX();//得到数据最大X+
|
||||||
|
int getMinX();//得到数据最小X-
|
||||||
|
int getMaxY();//得到数据最大Y+
|
||||||
|
int getMinY();//得到数据最小Y-
|
||||||
|
|
||||||
|
inline int getDatMaxX(){return m_maxX;}//得到数据最大X+
|
||||||
|
inline int getDatMinX(){return m_minX;}//得到数据最小X-
|
||||||
|
inline int getDatMaxY(){return m_maxY;}//得到数据最大Y+
|
||||||
|
inline int getDatMinY(){return m_minY;}//得到数据最小Y-
|
||||||
|
|
||||||
|
void getQuiMinMax();
|
||||||
|
void writeFileLL(int left, int front, int startX, int startY); //写入左边前边
|
||||||
|
const QPoint getFirstPoint();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATAFILEQUI_H
|
||||||
2523
datafile/datafilequix.cpp
Normal file
2523
datafile/datafilequix.cpp
Normal file
File diff suppressed because it is too large
Load Diff
157
datafile/datafilequix.h
Normal file
157
datafile/datafilequix.h
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
#ifndef DATAFILEQUIX_H
|
||||||
|
#define DATAFILEQUIX_H
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QString>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QRgb>
|
||||||
|
#include "math.h"
|
||||||
|
#include <QBrush>
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
//#include "vectorsqrt.h"
|
||||||
|
#include "machine/comm/datadef.h"
|
||||||
|
#include "machine/comm/crc16.h"
|
||||||
|
#include "datafile/dataoperat.h"
|
||||||
|
|
||||||
|
#define QUIX_DATADIRX (1) // X向数据坐标与下位机坐标系统的差异
|
||||||
|
#define QUIX_DATADIRY (1) // Y向数据坐标与下位机坐标系统的差异
|
||||||
|
#define QUIX_DATADIRR (-1) // R向数据坐标与下位机坐标系统的差异
|
||||||
|
|
||||||
|
#define QUIX_SHOWDIRX (1) // X向显示坐标和数据坐标的差异
|
||||||
|
#define QUIX_SHOWDIRY (-1) // Y向显示坐标和数据坐标的差异
|
||||||
|
|
||||||
|
#define QUIX_PREVIEW_SIDE (15) // 留边大小
|
||||||
|
#define QUIX_PREVIEW_WIDTH (156) // 默认预览图区域宽度
|
||||||
|
#define QUIX_PREVIEW_HEIGHT (164) // 默认预览图区域高度
|
||||||
|
|
||||||
|
#define QUIX_SEWING 0x01 // 缝纫数据
|
||||||
|
#define QUIX_OFFSET 0x02 // 偏移数据
|
||||||
|
#define QUIX_SYNC_SEWING 0x07 // 同步缝纫数据
|
||||||
|
#define QUIX_SYNC_CUTTER 0x0A // 左右机头剪线
|
||||||
|
#define QUIX_SYNC_OFFSET 0x0F // 同步偏移数据
|
||||||
|
#define QUIX_SEWING_SEC 0x06 // 第二机头缝纫数据
|
||||||
|
#define QUIX_OFFSET_SEC 0x12 // 第二机头偏移数据
|
||||||
|
#define QUIX_MIRROR_SEC 0x17 // 第二机头x缝纫镜像
|
||||||
|
|
||||||
|
#define QUIX_CUTTER 0x1A // 左机头剪线
|
||||||
|
#define QUIX_CUTTER_SEC 0x1E // 右机头剪线
|
||||||
|
|
||||||
|
#define QUIX_MIRROR_OFT_SEC 0x1F // 第二机头x偏移镜像
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct tagQuixFileHead
|
||||||
|
{
|
||||||
|
char id[7]; // 0x0000~0x0006; 标志:=="GA-QUIX"
|
||||||
|
char name[1]; // 0x0007; 文件名
|
||||||
|
unsigned char reserve1[6]; // 0x0008~0x000D; 保留
|
||||||
|
unsigned char rotateStyle; // 0x000E; 旋转式样
|
||||||
|
unsigned char rotateAngle; // 0x000F; 旋转角度
|
||||||
|
unsigned int left; // 0x0010~0x0013; 左边 (中间数据后,可以修改,改变起始点,单针机)
|
||||||
|
unsigned int front; // 0x0014~0x0017; 前边 (中间数据后,可以修改,改变起始点,单针机)
|
||||||
|
unsigned int scanX; // 0x0018~0x001B; 缩放X (中间数据前,可以修改,单针机和多针机)
|
||||||
|
unsigned int scanY; // 0x001C~0x001F; 缩放Y (中间数据前,可以修改,单针机和多针机)
|
||||||
|
unsigned int normalStep; // 0x0020~0x0023; 针步大小(中间数据前,可以修改,单针机和多针机)
|
||||||
|
unsigned int reinMode; // 0x0024~0x0027; 加固模式(中间数据后,可以修改,终点有跨步的才加,单针机和多针机)
|
||||||
|
unsigned int reinNeedles; // 0x0028~0x002B; 加固针数(中间数据后,可以修改,终点有跨步的才加,单针机和多针机)
|
||||||
|
unsigned int reinNum; // 0x002C~0x002F; 加固次数(中间数据后,可以修改,终点有跨步的才加,单针机和多针机)
|
||||||
|
unsigned int angleCorrPosX; // 0x0030~0x0033; 角度修正x正(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
unsigned int angleCorrPosY; // 0x0034~0x0037; 角度修正y正(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
unsigned int angleCorrNegX; // 0x0038~0x003B; 角度修正x负(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
unsigned int angleCorrNegY; // 0x003C~0x003F; 角度修正y负(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
unsigned int stepQuiCorrection; // 0x0040~0x0043; 跨步绗缝修正(中间数据后,可以修改,拐角补偿,单针机和多针机)
|
||||||
|
int rollaComp; // 0x0044~0x0047; 罗拉补偿(中间数据后,让图形闭合,可以修改,多针机)
|
||||||
|
unsigned short angleCorrOffset; // 0x0048~0x0049; 角度修正量 (中间数据后,可以修改,拐角补偿,单针机和多针机,新加-hhy)
|
||||||
|
unsigned char reserve2[6]; // 0x004A~0x004F; 保留
|
||||||
|
unsigned int HStep; // 0x0050~0x0053; 水平方向针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
unsigned int leftRightLen; // 0x0054~0x0057; 左针右针距离 单位:0.1mm(绘制用,多针机)
|
||||||
|
unsigned int VStep12; // 0x0058~0x005B; 第1 2排针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
unsigned int VStep23; // 0x005C~0x005F; 第2 3排针距 单位:0.1mm(绘制用,多针机)
|
||||||
|
// 排针每个字节:XXXX XXXX
|
||||||
|
// 针位n (0x00:无针,0x01:右针, 0x10:左针,0x11:左右针)
|
||||||
|
unsigned char arrayNeedle1[48]; // 0x0060~0x008F; 第1排排针(绘制用,多针机)
|
||||||
|
unsigned char arrayNeedle2[48]; // 0x0090~0x00BF; 第2排排针(绘制用,多针机)
|
||||||
|
unsigned char arrayNeedle3[48]; // 0x00C0~0x00EF; 第3排排针(绘制用,多针机)
|
||||||
|
unsigned int firstPullLen; // 0x00F0~0x00F3; 一次拉料长度
|
||||||
|
unsigned int secondPullLen; // 0x00F4~0x00F7; 二次拉料长度
|
||||||
|
unsigned int triplePullLen; // 0x00F8~0x00FB; 三次拉料长度
|
||||||
|
unsigned int oftNeedleSize; //去除偏移针步大小设置
|
||||||
|
|
||||||
|
unsigned int startX;
|
||||||
|
unsigned int startY;
|
||||||
|
unsigned int setNormalStep;
|
||||||
|
unsigned char reserve4[756]; // 0x010E~0x0400; 保留
|
||||||
|
unsigned char reserve5[3072]; // 0x0401~0x1000; 保留
|
||||||
|
|
||||||
|
} __attribute__ ((packed)) QuixFileHead;
|
||||||
|
|
||||||
|
class DataFileQuix
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataFileQuix();
|
||||||
|
DataFileQuix(const QString & fullPathName);
|
||||||
|
|
||||||
|
void writeLeftFrontToFileDoubleHead(QString filePath,int left,int front); //写入左边前边
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString m_fileFullPathName; // 文件路径
|
||||||
|
QByteArray m_absData; // 转换后的绝对坐标数据
|
||||||
|
QByteArray m_fileData;// 文件数据内容(原始数据)
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_minX;
|
||||||
|
double m_maxX;
|
||||||
|
double m_minY;
|
||||||
|
double m_maxY;
|
||||||
|
QuiPoint m_firstPoint;
|
||||||
|
|
||||||
|
QuiPoint m_firstPointLeft;//左机头第一个点
|
||||||
|
QuiPoint m_firstPointRight;//右机头第一个点
|
||||||
|
QPointF m_firstAbsPoint;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void creatAbsHeadAndAr();//生成绝对坐标数据文件头及ar
|
||||||
|
int checkFileHead();
|
||||||
|
double getMutiUnit(int unit);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initFile(const QString & fullPathName);
|
||||||
|
void clear();
|
||||||
|
void loadFile();
|
||||||
|
void convertDataToEmbAbs(s16 falg = 1);
|
||||||
|
int createPreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int reDraw = 0); // 生成预览文件
|
||||||
|
inline const QString & getFileFullPathName() const {return m_fileFullPathName;} // 文件路径名称
|
||||||
|
inline QByteArray & getEmbAbsData() {return m_absData;} // 得到转换后的数据
|
||||||
|
QuixFileHead *getQuixHead();
|
||||||
|
void writePatternParaToFile(QuixFileHead *head);//将花样参数配置写到文件中
|
||||||
|
void moveDataBeginPonit(s32 left, s32 front);//移动数据起始点
|
||||||
|
|
||||||
|
//双头组合机型
|
||||||
|
int doubleHeadCreatePreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int reDraw = 0); // 生成预览文件
|
||||||
|
void doubleHeadConvertDataToEmbAbs(s16 flag = 1);
|
||||||
|
|
||||||
|
void writeFileLL(int left, int front, int startX, int startY); //写入左边前边
|
||||||
|
|
||||||
|
public:
|
||||||
|
int getStitchNums();//得到数据的针数
|
||||||
|
int getDatWidth();//得到数据的图形宽度
|
||||||
|
int getDatHeight();//得到数据的图形高度
|
||||||
|
int getMaxX();//得到数据最大X+
|
||||||
|
int getMinX();//得到数据最小X-
|
||||||
|
int getMaxY();//得到数据最大Y+
|
||||||
|
int getMinY();//得到数据最小Y-
|
||||||
|
|
||||||
|
inline int getDatMaxX(){return m_maxX;}//得到数据最大X+
|
||||||
|
inline int getDatMinX(){return m_minX;}//得到数据最小X-
|
||||||
|
inline int getDatMaxY(){return m_maxY;}//得到数据最大Y+
|
||||||
|
inline int getDatMinY(){return m_minY;}//得到数据最小Y-
|
||||||
|
|
||||||
|
void getQuixMinMax();
|
||||||
|
const QPoint getFirstPoint();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATAFILEQUI_H
|
||||||
2330
datafile/dataoperat.cpp
Normal file
2330
datafile/dataoperat.cpp
Normal file
File diff suppressed because it is too large
Load Diff
83
datafile/dataoperat.h
Normal file
83
datafile/dataoperat.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#ifndef DATAOPERAT_H
|
||||||
|
#define DATAOPERAT_H
|
||||||
|
|
||||||
|
#include "machine/comm/datadef.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include<iomanip>
|
||||||
|
#include<cmath>
|
||||||
|
#include <QList>
|
||||||
|
#include <QListIterator>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#define QUI_TYPE_LINE 1 //直线
|
||||||
|
#define QUI_TYPE_ARC 2 //三点圆弧
|
||||||
|
#define QUI_TYPE_STEP 4 //跨步
|
||||||
|
#define QUI_TYPE_HSTEP 5 //翻头跨步
|
||||||
|
#define QUI_TYPE_BES 6 //贝塞尔曲线
|
||||||
|
#define QUI_TYPE_SPLINE 7 //样条曲线
|
||||||
|
|
||||||
|
#define ERROR_NOTHING 0 //成功
|
||||||
|
#define ZERO 1e-6
|
||||||
|
|
||||||
|
#define LINEDUAN_NUM_LIMIT 5 // 计算分段数固定:不进行特殊计算
|
||||||
|
#define LINEDUAN_STITCHLEN_LIMIT 6 // 针迹步长固定
|
||||||
|
#define LINEDUAN_STITCHLEN_LIMIT_END 7 // 针迹步长固定(最后线段)
|
||||||
|
|
||||||
|
#define OBJECT_STITCHLEN_NEW_BIG 8 // 固定针迹长度(大等分)
|
||||||
|
#define OBJECT_STITCHLEN_NEW_SAME 9 // 固定针迹长度(等距分)
|
||||||
|
#define OBJECT_STITCHLEN_NEW_SAMALL 10 // 固定针迹长度(小等分)
|
||||||
|
#define ADJUSTLINE_ADD_DUAN_LIMIT 11 // 自动单针指定分段添加
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
} Point2D;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
int ctrl;
|
||||||
|
} QuiPoint;
|
||||||
|
|
||||||
|
int isThreePointOnALine(const double threex[],const double threey[]);
|
||||||
|
int getArcCenter(const double x[], const double y[], double * pxc, double * pyc, double * pr);
|
||||||
|
int getArcMinMax(const double x[], const double y[], double * pminx, double * pmaxx, double * pminy, double * pmaxy);
|
||||||
|
void rotatec(double xin, double yin, double * px, double * py, double angle);
|
||||||
|
int arcDir(const double x[], const double y[]);
|
||||||
|
|
||||||
|
Point2D pointOnCubicBezier(Point2D* cp, double t);
|
||||||
|
void computeBezier(Point2D* cp, long numberOfPoints, Point2D* curve);
|
||||||
|
int getBezierMinMax(const double x[], const double y[], double * pminx, double * pmaxx, double * pminy, double * pmaxy);
|
||||||
|
int getSplineMinMax(QList<QPointF> &ptList, double * pminx, double * pmaxx, double * pminy, double * pmaxy);
|
||||||
|
|
||||||
|
int calcLine(double x0, double y0, double x1, double y1, s16 step, QByteArray &absAry, WORD datatype, u8 ctrl = 0);
|
||||||
|
int calcCurve(double threex[], double threey[], s16 step, QByteArray &absAry, u8 ctrl = 0);
|
||||||
|
int calcBezier(double threex[], double threey[], s16 step, QByteArray &absAry);
|
||||||
|
void getBezierPointList(double threex[], double threey[], s16 step, QList<QPointF> &outList);
|
||||||
|
|
||||||
|
//样条拟合
|
||||||
|
void getSplineNew(QList<QPointF> &ptList, QList<QPointF> &splineList);
|
||||||
|
void getShap(int nCtrlPntNum, QPointF *pPoint, QList<QPointF> &splineList, double dfMinX, double dfMinY);
|
||||||
|
//线段拟合
|
||||||
|
void getCurvePointFillLine(QList<QPointF> &inList, double indRunLen,
|
||||||
|
QList<QPointF> &outList, int iSumParm, BYTE biLenLimit);
|
||||||
|
int getTotalDistanceFillLine(QList<QPointF> *pPointList, double &dTotal);
|
||||||
|
void pointToPoint(const QPointF &inPoint, QPointF &outPoint);
|
||||||
|
long doubleToLong(double indValue);//浮点数转整形
|
||||||
|
double round(double indValue);//四舍五入
|
||||||
|
void distPointToPoint(const QPointF &p1, const QPointF &p2, double &outd);
|
||||||
|
bool getPointInSectFillLine(const QPointF &p1, const QPointF &p2, const double &d, QPointF &outp);
|
||||||
|
|
||||||
|
//距p1点距离为d的点
|
||||||
|
// d > s : out_p在p2延长线上
|
||||||
|
// s >= d >= 0 : out_p在p1、p2线段上
|
||||||
|
// d < 0 : out_p在p1延长线上
|
||||||
|
bool getPointAtSect(const QPointF &p1, const QPointF &p2, const double &d, QPointF &outp);
|
||||||
|
|
||||||
|
// 两点间距离
|
||||||
|
double disPointToPoint(double x1, double y1, double x2, double y2);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DATAOPERAT_H
|
||||||
394
datafile/dsrcryption.cpp
Normal file
394
datafile/dsrcryption.cpp
Normal file
@ -0,0 +1,394 @@
|
|||||||
|
#include "dsrcryption.h"
|
||||||
|
#include <QString>
|
||||||
|
#include <QTime>
|
||||||
|
|
||||||
|
DsrCryption::DsrCryption()
|
||||||
|
{
|
||||||
|
m_initflag = 0;
|
||||||
|
m_cryword = 0;
|
||||||
|
memset(m_factors, 0, BYTES_OF_CRY_FACTORS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化加密控制, 生成加密字和加密因子
|
||||||
|
int DsrCryption::InitDsrCryptionCtrl(int version, unsigned int cryword, const unsigned char * factors)
|
||||||
|
{
|
||||||
|
int rslt = 0;
|
||||||
|
|
||||||
|
m_initflag = 0;
|
||||||
|
m_cryword = 0;
|
||||||
|
memset(m_factors, 0, BYTES_OF_CRY_FACTORS);
|
||||||
|
|
||||||
|
if (version >= 0)
|
||||||
|
{
|
||||||
|
rslt = CreateCryWord(version);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_cryword = cryword;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rslt == 0)
|
||||||
|
{
|
||||||
|
rslt = CreateCryFactors(factors);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rslt == 0)
|
||||||
|
{
|
||||||
|
m_initflag++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取加密字
|
||||||
|
unsigned int DsrCryption::GetDsrCryptionWord()
|
||||||
|
{
|
||||||
|
return m_cryword;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加密数据
|
||||||
|
int DsrCryption::EnCryption(unsigned char * pData, int size)
|
||||||
|
{
|
||||||
|
if (pData == NULL || size <= 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char thisfactors[BYTES_OF_CRY_FACTORS];
|
||||||
|
unsigned char tempbuff[BYTES_OF_CRY_FACTORS];
|
||||||
|
|
||||||
|
memcpy(thisfactors, m_factors, BYTES_OF_CRY_FACTORS); // 拷贝临时的加密因子,做计算用
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
for (i = 0; i < size; i += BYTES_OF_CRY_FACTORS)
|
||||||
|
{
|
||||||
|
// 拷贝数据到临时buff
|
||||||
|
int mv = 0;
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
if (i+j < size)
|
||||||
|
{
|
||||||
|
tempbuff[j] = pData[i+j]; // 拷贝数据
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempbuff[j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mv += thisfactors[j]; // 累加因子,作为移动因子
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移动数据
|
||||||
|
if (i + BYTES_OF_CRY_FACTORS < size)
|
||||||
|
{
|
||||||
|
// 生成移动索引
|
||||||
|
unsigned char mvidx[BYTES_OF_CRY_FACTORS];
|
||||||
|
int idx, setdidx = BYTES_OF_CRY_FACTORS-1;
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
idx = (mv >> j) & 0x1f;
|
||||||
|
for (int k = 0; k < j; k++)
|
||||||
|
{
|
||||||
|
if (mvidx[k] == idx)
|
||||||
|
{
|
||||||
|
idx = setdidx;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int kk;
|
||||||
|
for (kk = 0; kk < j; kk++)
|
||||||
|
{
|
||||||
|
if (mvidx[kk] == idx)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (kk < j)
|
||||||
|
{
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setdidx = idx-1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mvidx[j] = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移动数据
|
||||||
|
unsigned char tempdat[BYTES_OF_CRY_FACTORS];
|
||||||
|
memcpy(tempdat, tempbuff, BYTES_OF_CRY_FACTORS);
|
||||||
|
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
tempbuff[j] = tempdat[mvidx[j]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据加密
|
||||||
|
for (j = 0; i+j < size && j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
tempbuff[j] ^= thisfactors[j]; // 异或加密
|
||||||
|
pData[i+j] = tempbuff[j]; // 保存
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下次的变幻因子
|
||||||
|
int temp = 0;
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
temp += thisfactors[j];
|
||||||
|
temp *= 3;
|
||||||
|
temp += 1;
|
||||||
|
temp /= 2;
|
||||||
|
thisfactors[j] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密数据
|
||||||
|
int DsrCryption::DeCryption(unsigned char * pData, int size)
|
||||||
|
{
|
||||||
|
if (pData == NULL || size <= 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pData == NULL || size <= 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char thisfactors[BYTES_OF_CRY_FACTORS];
|
||||||
|
unsigned char tempbuff[BYTES_OF_CRY_FACTORS];
|
||||||
|
|
||||||
|
memcpy(thisfactors, m_factors, BYTES_OF_CRY_FACTORS);
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
for (i = 0; i < size; i += BYTES_OF_CRY_FACTORS)
|
||||||
|
{
|
||||||
|
// 拷贝数据到临时buff
|
||||||
|
int mv = 0;
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
if (i+j < size)
|
||||||
|
{
|
||||||
|
tempbuff[j] = pData[i+j]; // 拷贝数据
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempbuff[j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mv += thisfactors[j]; // 累加因子,作为移动因子
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据解密
|
||||||
|
for (j = 0; i+j < size && j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
tempbuff[j] ^= thisfactors[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据移动回去
|
||||||
|
if (i + BYTES_OF_CRY_FACTORS < size)
|
||||||
|
{
|
||||||
|
// 生成移动索引
|
||||||
|
unsigned char mvidx[BYTES_OF_CRY_FACTORS];
|
||||||
|
int idx, setdidx = BYTES_OF_CRY_FACTORS-1;
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
idx = (mv >> j) & 0x1f;
|
||||||
|
for (int k = 0; k < j; k++)
|
||||||
|
{
|
||||||
|
if (mvidx[k] == idx)
|
||||||
|
{
|
||||||
|
idx = setdidx;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int kk;
|
||||||
|
for (kk = 0; kk < j; kk++)
|
||||||
|
{
|
||||||
|
if (mvidx[kk] == idx)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (kk < j)
|
||||||
|
{
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setdidx = idx-1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mvidx[j] = idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移动数据
|
||||||
|
unsigned char tempdat[BYTES_OF_CRY_FACTORS];
|
||||||
|
memcpy(tempdat, tempbuff, BYTES_OF_CRY_FACTORS);
|
||||||
|
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
tempbuff[mvidx[j]] = tempdat[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存解密数据
|
||||||
|
for (j = 0; i+j < size && j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
pData[i+j] = tempbuff[j]; // 保存
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下次的变幻因子
|
||||||
|
int temp = 0;
|
||||||
|
for (j = 0; j < BYTES_OF_CRY_FACTORS; j++)
|
||||||
|
{
|
||||||
|
temp += thisfactors[j];
|
||||||
|
temp *= 3;
|
||||||
|
temp += 1;
|
||||||
|
temp /= 2;
|
||||||
|
thisfactors[j] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DsrCryption::goaDeCryption(unsigned char *pFileData, int nDncryption, int nFileSize)
|
||||||
|
{
|
||||||
|
if (pFileData == NULL || nDncryption == 0 || nFileSize <= 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char n, biOffset, biTurnOn;
|
||||||
|
biOffset = (nDncryption >> 8) & 0xFF;
|
||||||
|
biTurnOn = (nDncryption >> 16) & 0xFF;
|
||||||
|
|
||||||
|
unsigned char* pDataOffset = NULL; //备份移动块数据
|
||||||
|
pDataOffset = new unsigned char[biOffset];
|
||||||
|
int nLen = nFileSize - biOffset;
|
||||||
|
|
||||||
|
//取反
|
||||||
|
for (n = 0; n < biTurnOn; n++)
|
||||||
|
{
|
||||||
|
pFileData[n] = ~pFileData[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (n = 0; n < biOffset; n++)
|
||||||
|
{//读取移动块数据
|
||||||
|
pDataOffset[n] = pFileData[nLen + n];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 0; k < nLen; k++)
|
||||||
|
{//将数据块右移 biOffset 位
|
||||||
|
pFileData[nFileSize - 1 - k] = pFileData[nLen - 1 - k];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (n = 0; n < biOffset; n++)
|
||||||
|
{//将右块数据设置到左边
|
||||||
|
pFileData[n] = pDataOffset[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DsrCryption::goaEncryption(unsigned char *pFileData, int nEncryption, int nFileSize)
|
||||||
|
{
|
||||||
|
if (pFileData == NULL || nEncryption == 0 || nFileSize <= 0) return -1;
|
||||||
|
|
||||||
|
unsigned char biOffset = (nEncryption >> 8) & 0xFF;
|
||||||
|
unsigned char biTurnOn = (nEncryption >> 16) & 0xFF;
|
||||||
|
|
||||||
|
if (biOffset >= nFileSize) return -1;
|
||||||
|
|
||||||
|
unsigned char* pDataOffset = new unsigned char[biOffset];
|
||||||
|
int nLen = nFileSize - biOffset;
|
||||||
|
|
||||||
|
// 1. 备份开头 biOffset 字节(它们即将被移到末尾)
|
||||||
|
for (int n = 0; n < biOffset; n++) {
|
||||||
|
pDataOffset[n] = pFileData[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 左移:把中间数据整体左移 biOffset 位
|
||||||
|
for (int k = 0; k < nLen; k++) {
|
||||||
|
pFileData[k] = pFileData[k + biOffset];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 把备份放到末尾
|
||||||
|
for (int n = 0; n < biOffset; n++) {
|
||||||
|
pFileData[nLen + n] = pDataOffset[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 最后取反前 biTurnOn 字节
|
||||||
|
for (int n = 0; n < biTurnOn && n < nFileSize; n++) {
|
||||||
|
pFileData[n] = ~pFileData[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] pDataOffset;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成加密字
|
||||||
|
int DsrCryption::CreateCryWord(int version)
|
||||||
|
{
|
||||||
|
if (version < 0 || version > 250)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rdw;
|
||||||
|
if (version == 0)
|
||||||
|
{
|
||||||
|
rdw = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QTime time= QTime::currentTime();
|
||||||
|
qsrand(time.msec()+time.second()*1000);
|
||||||
|
rdw = qrand(); // 产生随机数
|
||||||
|
}
|
||||||
|
|
||||||
|
m_cryword = rdw & 0xffffff;
|
||||||
|
m_cryword *= 251;
|
||||||
|
m_cryword += version;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成加密因子
|
||||||
|
int DsrCryption::CreateCryFactors(const unsigned char * factors)
|
||||||
|
{
|
||||||
|
if (factors == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(m_factors, factors, BYTES_OF_CRY_FACTORS);
|
||||||
|
|
||||||
|
int * pDat = (int*)m_factors;
|
||||||
|
|
||||||
|
// 变幻加密因子,兼容非加密情况
|
||||||
|
for (int i = 0; i < BYTES_OF_CRY_FACTORS; i+=sizeof(int))
|
||||||
|
{
|
||||||
|
*pDat *= m_cryword;
|
||||||
|
pDat++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
35
datafile/dsrcryption.h
Normal file
35
datafile/dsrcryption.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef DSRCRYPTION_H
|
||||||
|
#define DSRCRYPTION_H
|
||||||
|
|
||||||
|
#define CRY_VERSION1 0x01
|
||||||
|
#define CRY_VERSION2 0x02
|
||||||
|
|
||||||
|
#define CUR_CRY_VERSION 0x01 // 当前的加密版本(取值范围为 0 -- 250),方便通过版本使用不同的加密方法。
|
||||||
|
#define BYTES_OF_CRY_FACTORS 32 // 加密因子字节数
|
||||||
|
|
||||||
|
|
||||||
|
class DsrCryption
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DsrCryption();
|
||||||
|
|
||||||
|
public:
|
||||||
|
int InitDsrCryptionCtrl(int version, unsigned int cryword, const unsigned char * factors); // 初始化加密控制, 自动生成生成加密字和加密因子
|
||||||
|
unsigned int GetDsrCryptionWord(); // 获取加密字
|
||||||
|
|
||||||
|
int EnCryption(unsigned char * pData, int size); // 加密数据,使用当前的加密字和加密因子
|
||||||
|
int DeCryption(unsigned char * pData, int size); // 解密数据,使用当前的加密字和加密因子
|
||||||
|
int goaDeCryption(unsigned char * pFileData, int nDncryption, int nFileSize); // 解密数据,再登高,与富怡加密方法不同
|
||||||
|
int goaEncryption(unsigned char *pFileData, int nEncryption, int nFileSize); //加密
|
||||||
|
|
||||||
|
private:
|
||||||
|
int CreateCryWord(int version); // 生成加密字
|
||||||
|
int CreateCryFactors(const unsigned char * factors); // 生成加密因子
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_initflag;
|
||||||
|
unsigned int m_cryword;
|
||||||
|
unsigned char m_factors[BYTES_OF_CRY_FACTORS];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DSRCRYPTION_H
|
||||||
520
datafile/dxf/dxfhelper.cpp
Normal file
520
datafile/dxf/dxfhelper.cpp
Normal file
@ -0,0 +1,520 @@
|
|||||||
|
#include "dxfhelper.h"
|
||||||
|
#include "dxfreader.h"
|
||||||
|
|
||||||
|
#include <QImage>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
DxfHelper::DxfHelper()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double norm(double x, double y)
|
||||||
|
{
|
||||||
|
return sqrt(x * x + y * y);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QVector3D> DxfHelper::expandPolygon(QList<QVector3D> polygon, float expand)
|
||||||
|
{
|
||||||
|
QList<QVector3D> new_polygon;
|
||||||
|
int len = polygon.length();
|
||||||
|
if(len<3||qFuzzyIsNull(expand)) return polygon;
|
||||||
|
|
||||||
|
bool repeatFlag = false;
|
||||||
|
if(polygon.first()==polygon.back()) {
|
||||||
|
repeatFlag = true;
|
||||||
|
polygon.removeLast();
|
||||||
|
len = polygon.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int convertNum = 0;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
QVector3D p = polygon[i];
|
||||||
|
QVector3D p1 = polygon[i == 0 ? len - 1 : i - 1];
|
||||||
|
QVector3D p2 = polygon[i == len - 1 ? 0 : i + 1];
|
||||||
|
float v1x = p1.x() - p.x();
|
||||||
|
float v1y = p1.y() - p.y();
|
||||||
|
float n1 = norm(v1x, v1y);
|
||||||
|
float vv1x = v1x / n1;
|
||||||
|
float vv1y = v1y / n1;
|
||||||
|
float v2x = p2.x() - p.x();
|
||||||
|
float v2y = p2.y() - p.y();
|
||||||
|
float n2 = norm(v2x, v2y);
|
||||||
|
float vv2x = v2x / n2;
|
||||||
|
float vv2y = v2y / n2;
|
||||||
|
float vectorLen = -expand / sqrt((1 - (vv1x * vv2x + vv1y * vv2y)) / 2.0f);
|
||||||
|
float judge = v1x * v2y - v2x * v1y;
|
||||||
|
if (judge < 0) vectorLen *= -1;
|
||||||
|
if (judge < 0) convertNum++;
|
||||||
|
float vx = vv1x + vv2x;
|
||||||
|
float vy = vv1y + vv2y;
|
||||||
|
vectorLen = vectorLen / norm(vx, vy);
|
||||||
|
vx *= vectorLen;
|
||||||
|
vy *= vectorLen;
|
||||||
|
new_polygon.append(QVector3D(vx + p.x(), vy + p.y(), 0));
|
||||||
|
}
|
||||||
|
if(convertNum==len) {
|
||||||
|
new_polygon.clear();
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
QVector3D p = polygon[i];
|
||||||
|
QVector3D p1 = polygon[i == 0 ? len - 1 : i - 1];
|
||||||
|
QVector3D p2 = polygon[i == len - 1 ? 0 : i + 1];
|
||||||
|
float v1x = p1.x() - p.x();
|
||||||
|
float v1y = p1.y() - p.y();
|
||||||
|
float n1 = norm(v1x, v1y);
|
||||||
|
float vv1x = v1x / n1;
|
||||||
|
float vv1y = v1y / n1;
|
||||||
|
float v2x = p2.x() - p.x();
|
||||||
|
float v2y = p2.y() - p.y();
|
||||||
|
float n2 = norm(v2x, v2y);
|
||||||
|
float vv2x = v2x / n2;
|
||||||
|
float vv2y = v2y / n2;
|
||||||
|
float vectorLen = -expand / sqrt((1 - (vv1x * vv2x + vv1y * vv2y)) / 2.0f);
|
||||||
|
float vx = vv1x + vv2x;
|
||||||
|
float vy = vv1y + vv2y;
|
||||||
|
vectorLen = vectorLen / norm(vx, vy);
|
||||||
|
vx *= vectorLen;
|
||||||
|
vy *= vectorLen;
|
||||||
|
new_polygon.append(QVector3D(vx + p.x(), vy + p.y(), 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(repeatFlag) new_polygon.append(new_polygon.first());
|
||||||
|
|
||||||
|
return new_polygon;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DxfHelper::generateDxf(const QString &fileName)
|
||||||
|
{
|
||||||
|
// currentPos = QPointF(QRandomGenerator::global()->bounded(9999.99), QRandomGenerator::global()->bounded(9999.99));
|
||||||
|
currentPos = QPointF(9999.99, 9999.99);
|
||||||
|
vertexIndex = 0;
|
||||||
|
controlIndex = 0;
|
||||||
|
dxfPaths.clear();
|
||||||
|
|
||||||
|
DxfReader dxfReader(fileName);
|
||||||
|
for(auto d: dxfReader.dxfText) {
|
||||||
|
//qDebug() << "text data:" << d.text.c_str() << d.angle << d.style.c_str() << d.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfLinetypes) {
|
||||||
|
//qDebug() << "linetypes data:" << d.name.c_str() << d.flags << d.pattern << d.description.c_str() << d.patternLength << d.numberOfDashes;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QPointF> linepath;
|
||||||
|
for(auto d: dxfReader.dxfLines) {
|
||||||
|
//qDebug() << "line data:" << d.x1 << d.y1 << d.z1 << "," << d.x2 << d.y2 << d.z2;
|
||||||
|
if(currentPos!=QPointF(d.x1, d.y1)) {
|
||||||
|
if(!linepath.isEmpty()) {
|
||||||
|
QList<QVector3D> linelist;
|
||||||
|
foreach(auto point, linepath) linelist.append(QVector3D(point));
|
||||||
|
linepath.clear();
|
||||||
|
linelist = expandPolygon(linelist, expandOffset);
|
||||||
|
foreach(QVector3D point, linelist) {
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
linepath.append(QPointF(x, y));
|
||||||
|
currentPos = QPointF(x, y);
|
||||||
|
}
|
||||||
|
dxfPaths.append(linepath);
|
||||||
|
linepath.clear();
|
||||||
|
}
|
||||||
|
linepath.append(QPointF(d.x1, d.y1));
|
||||||
|
linepath.append(QPointF(d.x2, d.y2));
|
||||||
|
currentPos = QPointF(d.x2, d.y2);
|
||||||
|
} else {
|
||||||
|
linepath.append(QPointF(d.x2, d.y2));
|
||||||
|
currentPos = QPointF(d.x2, d.y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!linepath.isEmpty()) {
|
||||||
|
QList<QVector3D> linelist;
|
||||||
|
foreach(auto point, linepath) linelist.append(QVector3D(point));
|
||||||
|
linepath.clear();
|
||||||
|
linelist = expandPolygon(linelist, expandOffset);
|
||||||
|
foreach(QVector3D point, linelist) {
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
linepath.append(QPointF(x, y));
|
||||||
|
currentPos = QPointF(x, y);
|
||||||
|
}
|
||||||
|
dxfPaths.append(linepath);
|
||||||
|
linepath.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfArcs) {
|
||||||
|
//qDebug() << "arcs data:" << d.cx << d.cy << d.cz << d.angle1 << d.angle2 << d.radius;
|
||||||
|
|
||||||
|
|
||||||
|
double cx = d.cx;
|
||||||
|
double cy = d.cy;
|
||||||
|
// double cz = d.cz;
|
||||||
|
double angle1 = d.angle1;
|
||||||
|
double angle2 = d.angle2;
|
||||||
|
double radius = d.radius;
|
||||||
|
|
||||||
|
radius = radius + expandOffset;
|
||||||
|
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
double startXPos = cx + cos(abs(angle1)*M_PI/180)*radius;
|
||||||
|
double startYPos = cy + sin(abs(angle1)*M_PI/180)*radius;
|
||||||
|
|
||||||
|
path.moveTo(startXPos, startYPos);
|
||||||
|
|
||||||
|
double angleStart ,anglePassed;
|
||||||
|
angleStart = angle1;
|
||||||
|
if(angleStart>=180) angleStart = angleStart-360;
|
||||||
|
anglePassed = angleStart-angle2;
|
||||||
|
if(angleStart<180) angleStart = -angleStart;
|
||||||
|
if(anglePassed<-360) anglePassed = anglePassed+360;
|
||||||
|
|
||||||
|
QRectF rect(cx-radius, cy-radius, 2*radius, 2*radius);
|
||||||
|
path.arcTo(rect, angleStart, anglePassed);
|
||||||
|
|
||||||
|
QVector<QPointF> arcpath;
|
||||||
|
for(double i = 0; i <= 1; i += 0.003) { // TODO: 步长随图片大小调整
|
||||||
|
QPointF point = path.pointAtPercent(i);
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
arcpath.append(point);
|
||||||
|
currentPos=QPointF(x, y);
|
||||||
|
}
|
||||||
|
dxfPaths.append(arcpath);
|
||||||
|
// dxfPathList.append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfCircles) {
|
||||||
|
//qDebug() << "circle data:" << d.cx << d.cy << d.cz << d.radius;
|
||||||
|
|
||||||
|
|
||||||
|
double cx = d.cx;
|
||||||
|
double cy = d.cy;
|
||||||
|
// double cz = d.cz;
|
||||||
|
double radius = d.radius;
|
||||||
|
|
||||||
|
radius = radius + expandOffset;
|
||||||
|
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
path.moveTo(cx+radius, cy);
|
||||||
|
path.arcTo(cx-radius, cy-radius, 2*radius, 2*radius, 0, 360);
|
||||||
|
|
||||||
|
QVector<QPointF> circlepath;
|
||||||
|
for(double i = 0; i <= 1; i += 0.003) { // TODO: 步长随图片大小调整
|
||||||
|
QPointF point = path.pointAtPercent(i);
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
circlepath.append(point);
|
||||||
|
currentPos=QPointF(x, y);
|
||||||
|
}
|
||||||
|
dxfPaths.append(circlepath);
|
||||||
|
// dxfPathList.append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfEllipses) { // 起点角度要×ratio
|
||||||
|
//qDebug() << "ellipses data:" << d.cx << d.cy << d.cz << d.mx << d.my << d.mz << d.ratio << d.angle1 << d.angle2;
|
||||||
|
|
||||||
|
double cx = d.cx;
|
||||||
|
double cy = d.cy;
|
||||||
|
// double cz = d.cz;
|
||||||
|
double mx = d.mx;
|
||||||
|
double my = d.my;
|
||||||
|
// double mz = d.mz;
|
||||||
|
double ratio = d.ratio;
|
||||||
|
double angle1 = d.angle1;
|
||||||
|
double angle2 = d.angle2;
|
||||||
|
|
||||||
|
|
||||||
|
double rab = sqrt((cx- mx)*(cx - mx) +(cy - my)*(cy - my));
|
||||||
|
double resy = (expandOffset*(my-cy))/rab + my;
|
||||||
|
double resx = (expandOffset*(mx-cx))/rab + mx;
|
||||||
|
|
||||||
|
mx = resx;
|
||||||
|
my = resy;
|
||||||
|
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
double angle_1 = angle1;
|
||||||
|
double angle_2 = angle2;
|
||||||
|
while(angle_1>=3.14&&angle_2>=6.28) {
|
||||||
|
angle_1 -= M_PI;
|
||||||
|
angle_2 -= M_PI;
|
||||||
|
}
|
||||||
|
angle_1 = angle_1*180/M_PI;
|
||||||
|
angle_2 = angle_2*180/M_PI;
|
||||||
|
|
||||||
|
double angleStart ,anglePassed;
|
||||||
|
angleStart = angle_1;
|
||||||
|
if(angleStart>=180) angleStart = angleStart-360;
|
||||||
|
anglePassed = angleStart-angle_2;
|
||||||
|
if(angleStart<180) angleStart = -angleStart;
|
||||||
|
if(anglePassed<-360) anglePassed = anglePassed+360;
|
||||||
|
|
||||||
|
if(abs(anglePassed)<1) anglePassed = 360;
|
||||||
|
|
||||||
|
double c_x = cx;
|
||||||
|
double c_y = cy;
|
||||||
|
double dl = sqrt(mx*mx+my*my);
|
||||||
|
double ds = dl*ratio;
|
||||||
|
|
||||||
|
double rx;
|
||||||
|
double ry;
|
||||||
|
if(qFuzzyIsNull(mx)) {
|
||||||
|
rx = ds; ry = dl;
|
||||||
|
angleStart += 90;
|
||||||
|
} else {
|
||||||
|
rx = dl; ry = ds;
|
||||||
|
}
|
||||||
|
|
||||||
|
double angle=angleStart;
|
||||||
|
if(angle<0) angle=-angle;
|
||||||
|
else if(angle>=0) angle = 360-angle;
|
||||||
|
//if(!qFuzzyCompare(abs(anglePassed),360)) angle *= ratio;
|
||||||
|
if(!qFuzzyCompare(float(anglePassed),(float)360)) angle *= ratio;
|
||||||
|
double a=qDegreesToRadians(angle);
|
||||||
|
double R=rx*ry/sqrt(pow(rx*sin(a),2)+pow(ry*cos(a),2)); //计算对应角度的半径
|
||||||
|
double startXPos=c_x+R*cos(a);
|
||||||
|
double startYPos=c_y+R*sin(a);
|
||||||
|
path.moveTo(startXPos, startYPos);
|
||||||
|
|
||||||
|
//qDebug() << c_x << c_y << rx << ry << angleStart << anglePassed << angle;
|
||||||
|
path.arcTo(c_x-rx, c_y-ry, 2*rx, 2*ry, angleStart, anglePassed);
|
||||||
|
|
||||||
|
QVector<QPointF> ellipsepath;
|
||||||
|
for(double i = 0; i <= 1; i += 0.003) { // TODO: 步长随图片大小调整
|
||||||
|
QPointF point = path.pointAtPercent(i);
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
ellipsepath.append(point);
|
||||||
|
currentPos=QPointF(x, y);
|
||||||
|
}
|
||||||
|
dxfPaths.append(ellipsepath);
|
||||||
|
// dxfPathList.append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfPolylines) {
|
||||||
|
//qDebug() << "polylines data:" << d.m << d.n << d.flags << d.number << d.elevation;
|
||||||
|
|
||||||
|
QList<QVector3D> pointlist;
|
||||||
|
QVector<QPointF> path;
|
||||||
|
for(unsigned int i = 0; i < d.number; i++) {
|
||||||
|
double x = dxfReader.dxfVertexs.at(vertexIndex).x;
|
||||||
|
double y = dxfReader.dxfVertexs.at(vertexIndex).y;
|
||||||
|
double z = dxfReader.dxfVertexs.at(vertexIndex).z;
|
||||||
|
pointlist.append(QVector3D(x, y, z));
|
||||||
|
vertexIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointlist = expandPolygon(pointlist, expandOffset);
|
||||||
|
foreach(QVector3D point, pointlist) {
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
path.append(QPointF(x, y));
|
||||||
|
currentPos = QPointF(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(d.flags) {
|
||||||
|
double x = pointlist.first().x();
|
||||||
|
double y = pointlist.first().y();
|
||||||
|
path.append(QPointF(x, y));
|
||||||
|
currentPos = QPointF(x, y);
|
||||||
|
}
|
||||||
|
dxfPaths.append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfVertexs) {
|
||||||
|
// qDebug() << "vertexs data:" << d.x << d.y << d.z << d.bulge;
|
||||||
|
// }
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfPoints) {
|
||||||
|
//qDebug() << "points data:" << d.x << d.y << d.z;
|
||||||
|
QVector<QPointF> path;
|
||||||
|
path.append(QPointF(d.x, d.y));
|
||||||
|
dxfPaths.append(path);
|
||||||
|
currentPos = QPointF(d.x, d.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto d: dxfReader.dxfSplines) {
|
||||||
|
//qDebug() << "splines data:" << d.nFit << d.flags << d.degree << d.nKnots << d.nControl << d.tangentEndX << d.tangentEndY << d.tangentEndZ << d.tangentStartX << d.tangentStartY << d.tangentStartZ;
|
||||||
|
std::vector<QVector2D> pointList;
|
||||||
|
for(unsigned int i = 0; i < d.nControl; i++) {
|
||||||
|
int x = dxfReader.dxfControlPoints.at(controlIndex).x;
|
||||||
|
int y = dxfReader.dxfControlPoints.at(controlIndex).y;
|
||||||
|
pointList.push_back(QVector2D(x, y));
|
||||||
|
currentPos = QPointF(x, y);
|
||||||
|
controlIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QVector3D> templist;
|
||||||
|
foreach(auto point, pointList) templist.append(point);
|
||||||
|
templist = expandPolygon(templist, expandOffset);
|
||||||
|
|
||||||
|
QVector<QVector2D> inputList;
|
||||||
|
foreach(auto point, templist) inputList.append(point.toVector2D());
|
||||||
|
inputList.push_front(inputList.first());
|
||||||
|
inputList.push_back(inputList.back());
|
||||||
|
// std::vector<QVector2D> finalList(inputList.begin(), inputList.end());
|
||||||
|
|
||||||
|
// SplineHelper splineHelper(finalList, TypeCubicBSpline);
|
||||||
|
// auto splinePath = splineHelper.getSplinePath();
|
||||||
|
|
||||||
|
// dxfPaths.append(splinePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfControlPoints) {
|
||||||
|
// qDebug() << "control points data:" << d.w << d.x << d.y << d.z;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfXLines) {
|
||||||
|
// qDebug() << "XLines data:" << d.bx << d.by << d.bz << d.dx << d.dy << d.dz;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfRays) {
|
||||||
|
// qDebug() << "rays data:" << d.bx << d.by << d.bz << d.dx << d.dy << d.dz;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfFitPoints) {
|
||||||
|
// qDebug() << "fit points data:" << d.x << d.y << d.z;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfHatchs) {
|
||||||
|
// qDebug() << "hatchs data:" << d.angle << d.scale << d.solid << d.originX << d.originY << d.pattern.c_str() << d.numLoops;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfHatchLoops) {
|
||||||
|
// qDebug() << "hatchLoops data:" << d.numEdges;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for(auto d: dxfReader.dxfHatchEdges) {
|
||||||
|
// qDebug() << "hatchEdges data:" << d.cx << d.cy << d.mx << d.my << d.x1 << d.y1 << d.x2 << d.y2 << d.ccw << d.nFit << d.ratio << d.angle1 << d.angle2 << d.degree << d.nKnots << d.radius << d.defined << d.weights << d.nControl << d.periodic << d.rational << d.vertices << d.fitPoints << d.endTangentX << d.endTangentY << d.endTangentY << d.controlPoints << d.startTangentX << d.startTangentY;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfHelper::matchDXFSize()
|
||||||
|
{
|
||||||
|
double minx = __DBL_MAX__;
|
||||||
|
double maxx = __DBL_MIN__;
|
||||||
|
double miny = __DBL_MAX__;
|
||||||
|
double maxy = __DBL_MIN__;
|
||||||
|
foreach (QVector<QPointF> path, dxfPaths) {
|
||||||
|
for(int i = 0; i < path.length(); i++) {
|
||||||
|
QPointF point = path.at(i);
|
||||||
|
double x = point.x();
|
||||||
|
double y = point.y();
|
||||||
|
if(x<minx) minx = x;
|
||||||
|
if(x>maxx) maxx = x;
|
||||||
|
if(y<miny) miny = y;
|
||||||
|
if(y>maxy) maxy = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int width = maxx - minx;
|
||||||
|
int height = maxy - miny;
|
||||||
|
imageSize = QSize(width, height);
|
||||||
|
dxfBorderList.clear();
|
||||||
|
dxfBorderList.append(minx);
|
||||||
|
dxfBorderList.append(miny);
|
||||||
|
dxfBorderList.append(maxx);
|
||||||
|
dxfBorderList.append(maxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage DxfHelper::generateDXFImage()
|
||||||
|
{
|
||||||
|
matchDXFSize();
|
||||||
|
double minx = dxfBorderList.at(0);
|
||||||
|
double miny = dxfBorderList.at(1);
|
||||||
|
int penwidth = imageSize.width()/400;
|
||||||
|
int border = penwidth;
|
||||||
|
QImage image((imageSize.width()+2*border), (imageSize.height()+2*border), QImage::Format_ARGB32);
|
||||||
|
image.fill(Qt::white);
|
||||||
|
QPainter p(&image);
|
||||||
|
p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); // 抗锯齿和使用平滑转换算法
|
||||||
|
QPen pen;
|
||||||
|
if(penwidth<1) penwidth = 1;
|
||||||
|
pen.setWidth(penwidth);
|
||||||
|
pen.setColor(Qt::black);
|
||||||
|
p.setPen(pen);
|
||||||
|
QPainterPath painterpath;
|
||||||
|
foreach (QVector<QPointF> path, dxfPaths) {
|
||||||
|
for(int i = 0; i < path.length(); i++) {
|
||||||
|
double x = path.at(i).x()-minx;
|
||||||
|
double y = path.at(i).y()-miny;
|
||||||
|
y = imageSize.height()-y;
|
||||||
|
x += border;
|
||||||
|
y += border;
|
||||||
|
QPointF point(x, y);
|
||||||
|
if(i == 0) painterpath.moveTo(point);
|
||||||
|
else painterpath.lineTo(point);
|
||||||
|
}
|
||||||
|
// dxfPathList.append(painterpath);
|
||||||
|
}
|
||||||
|
//qDebug() << "[" << __FILE__ << ":" << __LINE__ << "]\t"<< "dxf path length:" <<dxfPaths.length();
|
||||||
|
p.drawPath(painterpath);
|
||||||
|
p.end();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<double> DxfHelper::getDxfBorderList() const
|
||||||
|
{
|
||||||
|
return dxfBorderList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize DxfHelper::getImageSize() const
|
||||||
|
{
|
||||||
|
return imageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QPainterPath> DxfHelper::getDxfPathList() const
|
||||||
|
{
|
||||||
|
return dxfPathList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QVector<QPointF> > DxfHelper::getDxfPaths() const
|
||||||
|
{
|
||||||
|
return dxfPaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFLine> DxfHelper::getDxfLineList() const
|
||||||
|
{
|
||||||
|
return dxfLineList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFRect> DxfHelper::getDxfRectList() const
|
||||||
|
{
|
||||||
|
return dxfRectList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFArc> DxfHelper::getDxfArcList() const
|
||||||
|
{
|
||||||
|
return dxfArcList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFCircle> DxfHelper::getDxfCircleList() const
|
||||||
|
{
|
||||||
|
return dxfCircleList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFEllipse> DxfHelper::getDxfEllipseList() const
|
||||||
|
{
|
||||||
|
return dxfEllipseList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFPolyline> DxfHelper::getDxfPolylineList() const
|
||||||
|
{
|
||||||
|
return dxfPolylineList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<DXFSpline> DxfHelper::getDxfSplineList() const
|
||||||
|
{
|
||||||
|
return dxfSplineList;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfHelper::setExpandOffset(double value)
|
||||||
|
{
|
||||||
|
expandOffset = value;
|
||||||
|
}
|
||||||
110
datafile/dxf/dxfhelper.h
Normal file
110
datafile/dxf/dxfhelper.h
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
#ifndef DXFHELPER_H
|
||||||
|
#define DXFHELPER_H
|
||||||
|
|
||||||
|
#include <QPointF>
|
||||||
|
//#include <QRandomGenerator>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPainterPath>
|
||||||
|
#include <QtMath>
|
||||||
|
#include <QVector2D>
|
||||||
|
#include <QVector3D>
|
||||||
|
//#include <spline_library/splinehelper.h>
|
||||||
|
|
||||||
|
struct DXFLine {
|
||||||
|
double x1;
|
||||||
|
double y1;
|
||||||
|
double z1;
|
||||||
|
double x2;
|
||||||
|
double y2;
|
||||||
|
double z2;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DXFRect {
|
||||||
|
QList<QVector3D> list;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct DXFArc {
|
||||||
|
double cx;
|
||||||
|
double cy;
|
||||||
|
double cz;
|
||||||
|
double angle1;
|
||||||
|
double angle2;
|
||||||
|
double radius;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DXFCircle {
|
||||||
|
double cx;
|
||||||
|
double cy;
|
||||||
|
double cz;
|
||||||
|
double radius;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DXFEllipse {
|
||||||
|
double cx;
|
||||||
|
double cy;
|
||||||
|
double cz;
|
||||||
|
double mx;
|
||||||
|
double my;
|
||||||
|
double mz;
|
||||||
|
double angle1;
|
||||||
|
double angle2;
|
||||||
|
double ratio;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DXFPolyline {
|
||||||
|
double flags;
|
||||||
|
double number;
|
||||||
|
QList<QVector3D> list;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DXFSpline {
|
||||||
|
double nControl;
|
||||||
|
QList<QVector3D> controlPoints;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DxfHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DxfHelper();
|
||||||
|
QList<QVector3D> expandPolygon(QList<QVector3D> polygon, float expand);
|
||||||
|
bool generateDxf(const QString &fileName);
|
||||||
|
QVector<QVector<QPointF>> getDxfPaths() const;
|
||||||
|
|
||||||
|
QList<DXFLine> getDxfLineList() const;
|
||||||
|
QList<DXFRect> getDxfRectList() const;
|
||||||
|
QList<DXFArc> getDxfArcList() const;
|
||||||
|
QList<DXFCircle> getDxfCircleList() const;
|
||||||
|
QList<DXFEllipse> getDxfEllipseList() const;
|
||||||
|
QList<DXFPolyline> getDxfPolylineList() const;
|
||||||
|
QList<DXFSpline> getDxfSplineList() const;
|
||||||
|
|
||||||
|
void setExpandOffset(double value);
|
||||||
|
|
||||||
|
void matchDXFSize();
|
||||||
|
QImage generateDXFImage();
|
||||||
|
QList<QPainterPath> getDxfPathList() const;
|
||||||
|
QSize getImageSize() const;
|
||||||
|
QList<double> getDxfBorderList() const;
|
||||||
|
private:
|
||||||
|
QPointF currentPos;
|
||||||
|
unsigned int vertexIndex = 0;
|
||||||
|
unsigned int controlIndex = 0;
|
||||||
|
QVector<QVector<QPointF>> dxfPaths;
|
||||||
|
QList<QPainterPath> dxfPathList;
|
||||||
|
|
||||||
|
double expandOffset = 0;
|
||||||
|
|
||||||
|
QList<DXFLine> dxfLineList;
|
||||||
|
QList<DXFRect> dxfRectList;
|
||||||
|
QList<DXFArc> dxfArcList;
|
||||||
|
QList<DXFCircle> dxfCircleList;
|
||||||
|
QList<DXFEllipse> dxfEllipseList;
|
||||||
|
QList<DXFPolyline> dxfPolylineList;
|
||||||
|
QList<DXFSpline> dxfSplineList;
|
||||||
|
QList<double> dxfBorderList;
|
||||||
|
QSize imageSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DXFHELPER_H
|
||||||
237
datafile/dxf/dxflib/dl_attributes.h
Normal file
237
datafile/dxf/dxflib/dl_attributes.h
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_ATTRIBUTES_H
|
||||||
|
#define DL_ATTRIBUTES_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "dl_codes.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storing and passing around attributes. Attributes
|
||||||
|
* are the layer name, color, width and line type.
|
||||||
|
*
|
||||||
|
* @author Andrew Mustun
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_Attributes {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
DL_Attributes() :
|
||||||
|
layer(""),
|
||||||
|
color(0),
|
||||||
|
color24(-1),
|
||||||
|
width(0),
|
||||||
|
linetype("BYLAYER"),
|
||||||
|
linetypeScale(1.0),
|
||||||
|
handle(-1),
|
||||||
|
inPaperSpace(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for DXF attributes.
|
||||||
|
*
|
||||||
|
* @param layer Layer name for this entity or NULL for no layer
|
||||||
|
* (every entity should be on a named layer!).
|
||||||
|
* @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER.
|
||||||
|
* @param width Line thickness. Defaults to zero. -1 = BYLAYER,
|
||||||
|
* -2 = BYBLOCK, -3 = default width
|
||||||
|
* @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults
|
||||||
|
* to "BYLAYER"
|
||||||
|
*/
|
||||||
|
DL_Attributes(const std::string& layer,
|
||||||
|
int color, int width,
|
||||||
|
const std::string& linetype,
|
||||||
|
double linetypeScale) :
|
||||||
|
layer(layer),
|
||||||
|
color(color),
|
||||||
|
color24(-1),
|
||||||
|
width(width),
|
||||||
|
linetype(linetype),
|
||||||
|
linetypeScale(linetypeScale),
|
||||||
|
handle(-1),
|
||||||
|
inPaperSpace(false) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for DXF attributes.
|
||||||
|
*
|
||||||
|
* @param layer Layer name for this entity or NULL for no layer
|
||||||
|
* (every entity should be on a named layer!).
|
||||||
|
* @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER.
|
||||||
|
* @param color24 24 bit color (0x00RRGGBB, see DXF reference).
|
||||||
|
* @param width Line thickness. Defaults to zero. -1 = BYLAYER,
|
||||||
|
* -2 = BYBLOCK, -3 = default width
|
||||||
|
* @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults
|
||||||
|
* to "BYLAYER"
|
||||||
|
*/
|
||||||
|
DL_Attributes(const std::string& layer,
|
||||||
|
int color, int color24, int width,
|
||||||
|
const std::string& linetype,
|
||||||
|
int handle=-1) :
|
||||||
|
layer(layer),
|
||||||
|
color(color),
|
||||||
|
color24(color24),
|
||||||
|
width(width),
|
||||||
|
linetype(linetype),
|
||||||
|
linetypeScale(1.0),
|
||||||
|
handle(handle),
|
||||||
|
inPaperSpace(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the layer. If the given pointer points to NULL, the
|
||||||
|
* new layer name will be an empty but valid string.
|
||||||
|
*/
|
||||||
|
void setLayer(const std::string& layer) {
|
||||||
|
this->layer = layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Layer name.
|
||||||
|
*/
|
||||||
|
std::string getLayer() const {
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color.
|
||||||
|
*
|
||||||
|
* @see DL_Codes, dxfColors
|
||||||
|
*/
|
||||||
|
void setColor(int color) {
|
||||||
|
this->color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the 24bit color.
|
||||||
|
*
|
||||||
|
* @see DL_Codes, dxfColors
|
||||||
|
*/
|
||||||
|
void setColor24(int color) {
|
||||||
|
this->color24 = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Color.
|
||||||
|
*
|
||||||
|
* @see DL_Codes, dxfColors
|
||||||
|
*/
|
||||||
|
int getColor() const {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 24 bit color or -1 if no 24bit color is defined.
|
||||||
|
*
|
||||||
|
* @see DL_Codes, dxfColors
|
||||||
|
*/
|
||||||
|
int getColor24() const {
|
||||||
|
return color24;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the width.
|
||||||
|
*/
|
||||||
|
void setWidth(int width) {
|
||||||
|
this->width = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Width.
|
||||||
|
*/
|
||||||
|
int getWidth() const {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the line type. This can be any string and is not
|
||||||
|
* checked to be a valid line type.
|
||||||
|
*/
|
||||||
|
void setLinetype(const std::string& linetype) {
|
||||||
|
this->linetype = linetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the entity specific line type scale.
|
||||||
|
*/
|
||||||
|
void setLinetypeScale(double linetypeScale) {
|
||||||
|
this->linetypeScale = linetypeScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getLinetypeScale() const {
|
||||||
|
return linetypeScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Line type.
|
||||||
|
*/
|
||||||
|
std::string getLinetype() const {
|
||||||
|
if (linetype.length()==0) {
|
||||||
|
return "BYLAYER";
|
||||||
|
} else {
|
||||||
|
return linetype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHandle(int h) {
|
||||||
|
handle = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getHandle() const {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setInPaperSpace(bool on) {
|
||||||
|
inPaperSpace = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInPaperSpace() const {
|
||||||
|
return inPaperSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string layer;
|
||||||
|
int color;
|
||||||
|
int color24;
|
||||||
|
int width;
|
||||||
|
std::string linetype;
|
||||||
|
double linetypeScale;
|
||||||
|
int handle;
|
||||||
|
|
||||||
|
// DXF code 67 (true: entity in paper space, false: entity in model space (default):
|
||||||
|
bool inPaperSpace;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// EOF
|
||||||
546
datafile/dxf/dxflib/dl_codes.h
Normal file
546
datafile/dxf/dxflib/dl_codes.h
Normal file
@ -0,0 +1,546 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
** Copyright (C) 2001 Robert J. Campbell Jr.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines common DXF codes and constants.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DXF_CODES_H
|
||||||
|
#define DXF_CODES_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
//#if defined(__OS2__)||defined(__EMX__)
|
||||||
|
//#define strcasecmp(s,t) stricmp(s,t)
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
//#if defined(_WIN32)
|
||||||
|
//#define strcasecmp(s,t) _stricmp(s,t)
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#undef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
//#pragma warning(disable : 4800)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.1415926535897932384626433832795
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DL_DXF_MAXLINE 1024
|
||||||
|
#define DL_DXF_MAXGROUPCODE 1100
|
||||||
|
|
||||||
|
// used to mark invalid vectors:
|
||||||
|
//#define DL_DXF_MAXDOUBLE 1.0E+10
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codes for colors and DXF versions.
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_Codes {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Standard DXF colors.
|
||||||
|
*/
|
||||||
|
enum color {
|
||||||
|
black = 250,
|
||||||
|
green = 3,
|
||||||
|
red = 1,
|
||||||
|
brown = 15,
|
||||||
|
yellow = 2,
|
||||||
|
cyan = 4,
|
||||||
|
magenta = 6,
|
||||||
|
gray = 8,
|
||||||
|
blue = 5,
|
||||||
|
l_blue = 163,
|
||||||
|
l_green = 121,
|
||||||
|
l_cyan = 131,
|
||||||
|
l_red = 23,
|
||||||
|
l_magenta = 221,
|
||||||
|
l_gray = 252,
|
||||||
|
white = 7,
|
||||||
|
bylayer = 256,
|
||||||
|
byblock = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version numbers for the DXF Format.
|
||||||
|
*/
|
||||||
|
enum version {
|
||||||
|
AC1009_MIN, // R12, minimalistic
|
||||||
|
AC1009, // R12
|
||||||
|
AC1012,
|
||||||
|
AC1014,
|
||||||
|
AC1015 // R2000
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Extended color palette:
|
||||||
|
// The first entry is only for direct indexing starting with [1]
|
||||||
|
// Color 1 is red (1,0,0)
|
||||||
|
const double dxfColors[][3] = {
|
||||||
|
{0,0,0}, // unused
|
||||||
|
{1,0,0}, // 1
|
||||||
|
{1,1,0},
|
||||||
|
{0,1,0},
|
||||||
|
{0,1,1},
|
||||||
|
{0,0,1},
|
||||||
|
{1,0,1},
|
||||||
|
{1,1,1}, // black or white
|
||||||
|
{0.5,0.5,0.5},
|
||||||
|
{0.75,0.75,0.75},
|
||||||
|
{1,0,0}, // 10
|
||||||
|
{1,0.5,0.5},
|
||||||
|
{0.65,0,0},
|
||||||
|
{0.65,0.325,0.325},
|
||||||
|
{0.5,0,0},
|
||||||
|
{0.5,0.25,0.25},
|
||||||
|
{0.3,0,0},
|
||||||
|
{0.3,0.15,0.15},
|
||||||
|
{0.15,0,0},
|
||||||
|
{0.15,0.075,0.075},
|
||||||
|
{1,0.25,0}, // 20
|
||||||
|
{1,0.625,0.5},
|
||||||
|
{0.65,0.1625,0},
|
||||||
|
{0.65,0.4063,0.325},
|
||||||
|
{0.5,0.125,0},
|
||||||
|
{0.5,0.3125,0.25},
|
||||||
|
{0.3,0.075,0},
|
||||||
|
{0.3,0.1875,0.15},
|
||||||
|
{0.15,0.0375,0},
|
||||||
|
{0.15,0.0938,0.075},
|
||||||
|
{1,0.5,0}, // 30
|
||||||
|
{1,0.75,0.5},
|
||||||
|
{0.65,0.325,0},
|
||||||
|
{0.65,0.4875,0.325},
|
||||||
|
{0.5,0.25,0},
|
||||||
|
{0.5,0.375,0.25},
|
||||||
|
{0.3,0.15,0},
|
||||||
|
{0.3,0.225,0.15},
|
||||||
|
{0.15,0.075,0},
|
||||||
|
{0.15,0.1125,0.075},
|
||||||
|
{1,0.75,0}, // 40
|
||||||
|
{1,0.875,0.5},
|
||||||
|
{0.65,0.4875,0},
|
||||||
|
{0.65,0.5688,0.325},
|
||||||
|
{0.5,0.375,0},
|
||||||
|
{0.5,0.4375,0.25},
|
||||||
|
{0.3,0.225,0},
|
||||||
|
{0.3,0.2625,0.15},
|
||||||
|
{0.15,0.1125,0},
|
||||||
|
{0.15,0.1313,0.075},
|
||||||
|
{1,1,0}, // 50
|
||||||
|
{1,1,0.5},
|
||||||
|
{0.65,0.65,0},
|
||||||
|
{0.65,0.65,0.325},
|
||||||
|
{0.5,0.5,0},
|
||||||
|
{0.5,0.5,0.25},
|
||||||
|
{0.3,0.3,0},
|
||||||
|
{0.3,0.3,0.15},
|
||||||
|
{0.15,0.15,0},
|
||||||
|
{0.15,0.15,0.075},
|
||||||
|
{0.75,1,0}, // 60
|
||||||
|
{0.875,1,0.5},
|
||||||
|
{0.4875,0.65,0},
|
||||||
|
{0.5688,0.65,0.325},
|
||||||
|
{0.375,0.5,0},
|
||||||
|
{0.4375,0.5,0.25},
|
||||||
|
{0.225,0.3,0},
|
||||||
|
{0.2625,0.3,0.15},
|
||||||
|
{0.1125,0.15,0},
|
||||||
|
{0.1313,0.15,0.075},
|
||||||
|
{0.5,1,0}, // 70
|
||||||
|
{0.75,1,0.5},
|
||||||
|
{0.325,0.65,0},
|
||||||
|
{0.4875,0.65,0.325},
|
||||||
|
{0.25,0.5,0},
|
||||||
|
{0.375,0.5,0.25},
|
||||||
|
{0.15,0.3,0},
|
||||||
|
{0.225,0.3,0.15},
|
||||||
|
{0.075,0.15,0},
|
||||||
|
{0.1125,0.15,0.075},
|
||||||
|
{0.25,1,0}, // 80
|
||||||
|
{0.625,1,0.5},
|
||||||
|
{0.1625,0.65,0},
|
||||||
|
{0.4063,0.65,0.325},
|
||||||
|
{0.125,0.5,0},
|
||||||
|
{0.3125,0.5,0.25},
|
||||||
|
{0.075,0.3,0},
|
||||||
|
{0.1875,0.3,0.15},
|
||||||
|
{0.0375,0.15,0},
|
||||||
|
{0.0938,0.15,0.075},
|
||||||
|
{0,1,0}, // 90
|
||||||
|
{0.5,1,0.5},
|
||||||
|
{0,0.65,0},
|
||||||
|
{0.325,0.65,0.325},
|
||||||
|
{0,0.5,0},
|
||||||
|
{0.25,0.5,0.25},
|
||||||
|
{0,0.3,0},
|
||||||
|
{0.15,0.3,0.15},
|
||||||
|
{0,0.15,0},
|
||||||
|
{0.075,0.15,0.075},
|
||||||
|
{0,1,0.25}, // 100
|
||||||
|
{0.5,1,0.625},
|
||||||
|
{0,0.65,0.1625},
|
||||||
|
{0.325,0.65,0.4063},
|
||||||
|
{0,0.5,0.125},
|
||||||
|
{0.25,0.5,0.3125},
|
||||||
|
{0,0.3,0.075},
|
||||||
|
{0.15,0.3,0.1875},
|
||||||
|
{0,0.15,0.0375},
|
||||||
|
{0.075,0.15,0.0938},
|
||||||
|
{0,1,0.5}, // 110
|
||||||
|
{0.5,1,0.75},
|
||||||
|
{0,0.65,0.325},
|
||||||
|
{0.325,0.65,0.4875},
|
||||||
|
{0,0.5,0.25},
|
||||||
|
{0.25,0.5,0.375},
|
||||||
|
{0,0.3,0.15},
|
||||||
|
{0.15,0.3,0.225},
|
||||||
|
{0,0.15,0.075},
|
||||||
|
{0.075,0.15,0.1125},
|
||||||
|
{0,1,0.75}, // 120
|
||||||
|
{0.5,1,0.875},
|
||||||
|
{0,0.65,0.4875},
|
||||||
|
{0.325,0.65,0.5688},
|
||||||
|
{0,0.5,0.375},
|
||||||
|
{0.25,0.5,0.4375},
|
||||||
|
{0,0.3,0.225},
|
||||||
|
{0.15,0.3,0.2625},
|
||||||
|
{0,0.15,0.1125},
|
||||||
|
{0.075,0.15,0.1313},
|
||||||
|
{0,1,1}, // 130
|
||||||
|
{0.5,1,1},
|
||||||
|
{0,0.65,0.65},
|
||||||
|
{0.325,0.65,0.65},
|
||||||
|
{0,0.5,0.5},
|
||||||
|
{0.25,0.5,0.5},
|
||||||
|
{0,0.3,0.3},
|
||||||
|
{0.15,0.3,0.3},
|
||||||
|
{0,0.15,0.15},
|
||||||
|
{0.075,0.15,0.15},
|
||||||
|
{0,0.75,1}, // 140
|
||||||
|
{0.5,0.875,1},
|
||||||
|
{0,0.4875,0.65},
|
||||||
|
{0.325,0.5688,0.65},
|
||||||
|
{0,0.375,0.5},
|
||||||
|
{0.25,0.4375,0.5},
|
||||||
|
{0,0.225,0.3},
|
||||||
|
{0.15,0.2625,0.3},
|
||||||
|
{0,0.1125,0.15},
|
||||||
|
{0.075,0.1313,0.15},
|
||||||
|
{0,0.5,1}, // 150
|
||||||
|
{0.5,0.75,1},
|
||||||
|
{0,0.325,0.65},
|
||||||
|
{0.325,0.4875,0.65},
|
||||||
|
{0,0.25,0.5},
|
||||||
|
{0.25,0.375,0.5},
|
||||||
|
{0,0.15,0.3},
|
||||||
|
{0.15,0.225,0.3},
|
||||||
|
{0,0.075,0.15},
|
||||||
|
{0.075,0.1125,0.15},
|
||||||
|
{0,0.25,1}, // 160
|
||||||
|
{0.5,0.625,1},
|
||||||
|
{0,0.1625,0.65},
|
||||||
|
{0.325,0.4063,0.65},
|
||||||
|
{0,0.125,0.5},
|
||||||
|
{0.25,0.3125,0.5},
|
||||||
|
{0,0.075,0.3},
|
||||||
|
{0.15,0.1875,0.3},
|
||||||
|
{0,0.0375,0.15},
|
||||||
|
{0.075,0.0938,0.15},
|
||||||
|
{0,0,1}, // 170
|
||||||
|
{0.5,0.5,1},
|
||||||
|
{0,0,0.65},
|
||||||
|
{0.325,0.325,0.65},
|
||||||
|
{0,0,0.5},
|
||||||
|
{0.25,0.25,0.5},
|
||||||
|
{0,0,0.3},
|
||||||
|
{0.15,0.15,0.3},
|
||||||
|
{0,0,0.15},
|
||||||
|
{0.075,0.075,0.15},
|
||||||
|
{0.25,0,1}, // 180
|
||||||
|
{0.625,0.5,1},
|
||||||
|
{0.1625,0,0.65},
|
||||||
|
{0.4063,0.325,0.65},
|
||||||
|
{0.125,0,0.5},
|
||||||
|
{0.3125,0.25,0.5},
|
||||||
|
{0.075,0,0.3},
|
||||||
|
{0.1875,0.15,0.3},
|
||||||
|
{0.0375,0,0.15},
|
||||||
|
{0.0938,0.075,0.15},
|
||||||
|
{0.5,0,1}, // 190
|
||||||
|
{0.75,0.5,1},
|
||||||
|
{0.325,0,0.65},
|
||||||
|
{0.4875,0.325,0.65},
|
||||||
|
{0.25,0,0.5},
|
||||||
|
{0.375,0.25,0.5},
|
||||||
|
{0.15,0,0.3},
|
||||||
|
{0.225,0.15,0.3},
|
||||||
|
{0.075,0,0.15},
|
||||||
|
{0.1125,0.075,0.15},
|
||||||
|
{0.75,0,1}, // 200
|
||||||
|
{0.875,0.5,1},
|
||||||
|
{0.4875,0,0.65},
|
||||||
|
{0.5688,0.325,0.65},
|
||||||
|
{0.375,0,0.5},
|
||||||
|
{0.4375,0.25,0.5},
|
||||||
|
{0.225,0,0.3},
|
||||||
|
{0.2625,0.15,0.3},
|
||||||
|
{0.1125,0,0.15},
|
||||||
|
{0.1313,0.075,0.15},
|
||||||
|
{1,0,1}, // 210
|
||||||
|
{1,0.5,1},
|
||||||
|
{0.65,0,0.65},
|
||||||
|
{0.65,0.325,0.65},
|
||||||
|
{0.5,0,0.5},
|
||||||
|
{0.5,0.25,0.5},
|
||||||
|
{0.3,0,0.3},
|
||||||
|
{0.3,0.15,0.3},
|
||||||
|
{0.15,0,0.15},
|
||||||
|
{0.15,0.075,0.15},
|
||||||
|
{1,0,0.75}, // 220
|
||||||
|
{1,0.5,0.875},
|
||||||
|
{0.65,0,0.4875},
|
||||||
|
{0.65,0.325,0.5688},
|
||||||
|
{0.5,0,0.375},
|
||||||
|
{0.5,0.25,0.4375},
|
||||||
|
{0.3,0,0.225},
|
||||||
|
{0.3,0.15,0.2625},
|
||||||
|
{0.15,0,0.1125},
|
||||||
|
{0.15,0.075,0.1313},
|
||||||
|
{1,0,0.5}, // 230
|
||||||
|
{1,0.5,0.75},
|
||||||
|
{0.65,0,0.325},
|
||||||
|
{0.65,0.325,0.4875},
|
||||||
|
{0.5,0,0.25},
|
||||||
|
{0.5,0.25,0.375},
|
||||||
|
{0.3,0,0.15},
|
||||||
|
{0.3,0.15,0.225},
|
||||||
|
{0.15,0,0.075},
|
||||||
|
{0.15,0.075,0.1125},
|
||||||
|
{1,0,0.25}, // 240
|
||||||
|
{1,0.5,0.625},
|
||||||
|
{0.65,0,0.1625},
|
||||||
|
{0.65,0.325,0.4063},
|
||||||
|
{0.5,0,0.125},
|
||||||
|
{0.5,0.25,0.3125},
|
||||||
|
{0.3,0,0.075},
|
||||||
|
{0.3,0.15,0.1875},
|
||||||
|
{0.15,0,0.0375},
|
||||||
|
{0.15,0.075,0.0938},
|
||||||
|
{0.33,0.33,0.33}, // 250
|
||||||
|
{0.464,0.464,0.464},
|
||||||
|
{0.598,0.598,0.598},
|
||||||
|
{0.732,0.732,0.732},
|
||||||
|
{0.866,0.866,0.866},
|
||||||
|
{1,1,1} // 255
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
// AutoCAD VERSION aliases
|
||||||
|
#define DL_VERSION_R12 DL_Codes::AC1009
|
||||||
|
#define DL_VERSION_LT2 DL_Codes::AC1009
|
||||||
|
#define DL_VERSION_R13 DL_Codes::AC1012 // not supported yet
|
||||||
|
#define DL_VERSION_LT95 DL_Codes::AC1012 // not supported yet
|
||||||
|
#define DL_VERSION_R14 DL_Codes::AC1014 // not supported yet
|
||||||
|
#define DL_VERSION_LT97 DL_Codes::AC1014 // not supported yet
|
||||||
|
#define DL_VERSION_LT98 DL_Codes::AC1014 // not supported yet
|
||||||
|
#define DL_VERSION_2000 DL_Codes::AC1015
|
||||||
|
#define DL_VERSION_2002 DL_Codes::AC1015
|
||||||
|
|
||||||
|
|
||||||
|
// DXF Group Codes:
|
||||||
|
|
||||||
|
// Strings
|
||||||
|
#define DL_STRGRP_START 0
|
||||||
|
#define DL_STRGRP_END 9
|
||||||
|
|
||||||
|
// Coordinates
|
||||||
|
#define DL_CRDGRP_START 10
|
||||||
|
#define DL_CRDGRP_END 19
|
||||||
|
|
||||||
|
// Real values
|
||||||
|
#define DL_RLGRP_START 38
|
||||||
|
#define DL_RLGRP_END 59
|
||||||
|
|
||||||
|
// Short integer values
|
||||||
|
#define DL_SHOGRP_START 60
|
||||||
|
#define DL_SHOGRP_END 79
|
||||||
|
|
||||||
|
// New in Release 13,
|
||||||
|
#define DL_SUBCLASS 100
|
||||||
|
|
||||||
|
// More coordinates
|
||||||
|
#define DL_CRD2GRP_START 210
|
||||||
|
#define DL_CRD2GRP_END 239
|
||||||
|
|
||||||
|
// Extended data strings
|
||||||
|
#define DL_ESTRGRP_START 1000
|
||||||
|
#define DL_ESTRGRP_END 1009
|
||||||
|
|
||||||
|
// Extended data reals
|
||||||
|
#define DL_ERLGRP_START 1010
|
||||||
|
#define DL_ERLGRP_END 1059
|
||||||
|
|
||||||
|
|
||||||
|
#define DL_Y8_COORD_CODE 28
|
||||||
|
#define DL_Z0_COORD_CODE 30
|
||||||
|
#define DL_Z8_COORD_CODE 38
|
||||||
|
|
||||||
|
#define DL_POINT_COORD_CODE 10
|
||||||
|
#define DL_INSERT_COORD_CODE 10
|
||||||
|
|
||||||
|
#define DL_CRD2GRP_START 210
|
||||||
|
#define DL_CRD2GRP_END 239
|
||||||
|
|
||||||
|
#define DL_THICKNESS 39
|
||||||
|
#define DL_FIRST_REAL_CODE THICKNESS
|
||||||
|
#define DL_LAST_REAL_CODE 59
|
||||||
|
#define DL_FIRST_INT_CODE 60
|
||||||
|
#define DL_ATTFLAGS_CODE 70
|
||||||
|
#define DL_PLINE_FLAGS_CODE 70
|
||||||
|
#define DL_LAYER_FLAGS_CODE 70
|
||||||
|
#define DL_FLD_LEN_CODE 73 // Inside ATTRIB resbuf
|
||||||
|
#define DL_LAST_INT_CODE 79
|
||||||
|
#define DL_X_EXTRU_CODE 210
|
||||||
|
#define DL_Y_EXTRU_CODE 220
|
||||||
|
#define DL_Z_EXTRU_CODE 230
|
||||||
|
#define DL_COMMENT_CODE 999
|
||||||
|
|
||||||
|
// Start and endpoints of a line
|
||||||
|
#define DL_LINE_START_CODE 10 // Followed by x coord
|
||||||
|
#define DL_LINE_END_CODE 11 // Followed by x coord
|
||||||
|
|
||||||
|
// Some codes used by blocks
|
||||||
|
#define DL_BLOCK_FLAGS_CODE 70 // An int containing flags
|
||||||
|
#define DL_BLOCK_BASE_CODE 10 // Origin of block definition
|
||||||
|
#define DL_XREF_DEPENDENT 16 // If a block contains an XREF
|
||||||
|
#define DL_XREF_RESOLVED 32 // If a XREF resolved ok
|
||||||
|
#define DL_REFERENCED 64 // If a block is ref'd in DWG
|
||||||
|
|
||||||
|
#define DL_XSCALE_CODE 41
|
||||||
|
#define DL_YSCALE_CODE 42
|
||||||
|
#define DL_ANGLE_CODE 50
|
||||||
|
#define DL_INS_POINT_CODE 10 // Followed by x of ins pnt
|
||||||
|
#define DL_NAME2_CODE 3 // Second appearance of name
|
||||||
|
|
||||||
|
// Some codes used by circle entities
|
||||||
|
#define DL_CENTER_CODE 10 // Followed by x of center
|
||||||
|
#define DL_RADIUS_CODE 40 // Followd by radius of circle
|
||||||
|
|
||||||
|
#define DL_COND_OP_CODE -4 // Conditional op,ads_ssget
|
||||||
|
|
||||||
|
// When using ads_buildlist you MUST use RTDXF0 instead of these
|
||||||
|
#define DL_ENTITY_TYPE_CODE 0 // Then there is LINE, 3DFACE..
|
||||||
|
#define DL_SES_CODE 0 // Start End String Code
|
||||||
|
#define DL_FILE_SEP_CODE 0 // File separator
|
||||||
|
#define DL_SOT_CODE 0 // Start Of Table
|
||||||
|
#define DL_TEXTVAL_CODE 1
|
||||||
|
#define DL_NAME_CODE 2
|
||||||
|
#define DL_BLOCK_NAME_CODE 2
|
||||||
|
#define DL_SECTION_NAME_CODE 2
|
||||||
|
#define DL_ENT_HAND_CODE 5 // What follows is hexa string
|
||||||
|
#define DL_TXT_STYLE_CODE 7 // Inside attributes
|
||||||
|
#define DL_LAYER_NAME_CODE 8 // What follows is layer name
|
||||||
|
#define DL_FIRST_XCOORD_CODE 10 // Group code x of 1st coord
|
||||||
|
#define DL_FIRST_YCOORD_CODE 20 // Group code y of 1st coord
|
||||||
|
#define DL_FIRST_ZCOORD_CODE 30 // Group code z of 1st coord
|
||||||
|
#define DL_L_START_CODE 10
|
||||||
|
#define DL_L_END_CODE 11
|
||||||
|
#define DL_TXTHI_CODE 40
|
||||||
|
#define DL_SCALE_X_CODE 41
|
||||||
|
#define DL_SCALE_Y_CODE 42
|
||||||
|
#define DL_SCALE_Z_CODE 43
|
||||||
|
#define DL_BULGE_CODE 42 // Used in PLINE verts for arcs
|
||||||
|
#define DL_ROTATION_CODE 50
|
||||||
|
#define DL_COLOUR_CODE 62 // What follows is a color int
|
||||||
|
#define DL_LTYPE_CODE 6 // What follows is a linetype
|
||||||
|
|
||||||
|
|
||||||
|
// Attribute flags
|
||||||
|
#define DL_ATTS_FOLLOW_CODE 66
|
||||||
|
#define DL_ATT_TAG_CODE 2
|
||||||
|
#define DL_ATT_VAL_CODE 1
|
||||||
|
#define DL_ATT_FLAGS_CODE 70 // 4 1 bit flags as follows...
|
||||||
|
#define DL_ATT_INVIS_FLAG 1
|
||||||
|
#define DL_ATT_CONST_FLAG 2
|
||||||
|
#define DL_ATT_VERIFY_FLAG 4 // Prompt and verify
|
||||||
|
#define DL_ATT_PRESET_FLAG 8 // No prompt and no verify
|
||||||
|
|
||||||
|
// PLINE defines
|
||||||
|
// Flags
|
||||||
|
#define DL_OPEN_PLINE 0x00
|
||||||
|
#define DL_CLOSED_PLINE 0x01
|
||||||
|
#define DL_POLYLINE3D 0x80
|
||||||
|
#define DL_PFACE_MESH 0x40
|
||||||
|
#define DL_PGON_MESH 0x10
|
||||||
|
// Vertices follow entity, required in POLYLINES
|
||||||
|
#define DL_VERTS_FOLLOW_CODE 66 // Value should always be 1
|
||||||
|
#define DL_VERTEX_COORD_CODE 10
|
||||||
|
|
||||||
|
|
||||||
|
// LAYER flags
|
||||||
|
#define DL_FROZEN 1
|
||||||
|
#define DL_FROZEN_BY_DEF 2
|
||||||
|
#define DL_LOCKED 4
|
||||||
|
#define DL_OBJECT_USED 64 // Object is ref'd in the dwg
|
||||||
|
|
||||||
|
#define DL_BLOCK_EN_CODE -2 // Block entity definition
|
||||||
|
#define DL_E_NAME -1 // Entity name
|
||||||
|
|
||||||
|
// Extended data codes
|
||||||
|
#define DL_EXTD_SENTINEL (-3)
|
||||||
|
#define DL_EXTD_STR 1000
|
||||||
|
#define DL_EXTD_APP_NAME 1001
|
||||||
|
#define DL_EXTD_CTL_STR 1002
|
||||||
|
#define DL_EXTD_LYR_STR 1003
|
||||||
|
#define DL_EXTD_CHUNK 1004
|
||||||
|
#define DL_EXTD_HANDLE 1005
|
||||||
|
#define DL_EXTD_POINT 1010
|
||||||
|
#define DL_EXTD_POS 1011
|
||||||
|
#define DL_EXTD_DISP 1012
|
||||||
|
#define DL_EXTD_DIR 1013
|
||||||
|
#define DL_EXTD_FLOAT 1040
|
||||||
|
#define DL_EXTD_DIST 1041
|
||||||
|
#define DL_EXTD_SCALE 1042
|
||||||
|
#define DL_EXTD_INT16 1070
|
||||||
|
#define DL_EXTD_INT32 1071
|
||||||
|
|
||||||
|
// UCS codes for use in ads_trans
|
||||||
|
#define DL_WCS_TRANS_CODE 0
|
||||||
|
#define DL_UCS_TRANS_CODE 1
|
||||||
|
#define DL_DCS_TRANS_CODE 2
|
||||||
|
#define DL_PCS_TRANS_CODE 3
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
138
datafile/dxf/dxflib/dl_creationadapter.h
Normal file
138
datafile/dxf/dxflib/dl_creationadapter.h
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_CREATIONADAPTER_H
|
||||||
|
#define DL_CREATIONADAPTER_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#include "dl_creationinterface.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract adapter class for receiving DXF events when a DXF file is being read.
|
||||||
|
* The methods in this class are empty. This class exists as convenience for creating
|
||||||
|
* listener objects.
|
||||||
|
*
|
||||||
|
* @author Andrew Mustun
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_CreationAdapter : public DL_CreationInterface {
|
||||||
|
public:
|
||||||
|
DL_CreationAdapter() {}
|
||||||
|
virtual ~DL_CreationAdapter() {}
|
||||||
|
virtual void processCodeValuePair(unsigned int, const std::string&) {}
|
||||||
|
virtual void endSection() {}
|
||||||
|
virtual void addLayer(const DL_LayerData&) {}
|
||||||
|
virtual void addLinetype(const DL_LinetypeData&) {}
|
||||||
|
virtual void addLinetypeDash(double) {}
|
||||||
|
virtual void addBlock(const DL_BlockData&) {}
|
||||||
|
virtual void endBlock() {}
|
||||||
|
virtual void addTextStyle(const DL_StyleData&) {}
|
||||||
|
virtual void addPoint(const DL_PointData&) {}
|
||||||
|
virtual void addLine(const DL_LineData&) {}
|
||||||
|
virtual void addXLine(const DL_XLineData&) {}
|
||||||
|
virtual void addRay(const DL_RayData&) {}
|
||||||
|
|
||||||
|
virtual void addArc(const DL_ArcData&) {}
|
||||||
|
virtual void addCircle(const DL_CircleData&) {}
|
||||||
|
virtual void addEllipse(const DL_EllipseData&) {}
|
||||||
|
|
||||||
|
virtual void addPolyline(const DL_PolylineData&) {}
|
||||||
|
virtual void addVertex(const DL_VertexData&) {}
|
||||||
|
|
||||||
|
virtual void addSpline(const DL_SplineData&) {}
|
||||||
|
virtual void addControlPoint(const DL_ControlPointData&) {}
|
||||||
|
virtual void addFitPoint(const DL_FitPointData&) {}
|
||||||
|
virtual void addKnot(const DL_KnotData&) {}
|
||||||
|
|
||||||
|
virtual void addInsert(const DL_InsertData&) {}
|
||||||
|
|
||||||
|
virtual void addMText(const DL_MTextData&) {}
|
||||||
|
virtual void addMTextChunk(const std::string&) {}
|
||||||
|
virtual void addText(const DL_TextData&) {}
|
||||||
|
virtual void addArcAlignedText(const DL_ArcAlignedTextData&) {}
|
||||||
|
virtual void addAttribute(const DL_AttributeData&) {}
|
||||||
|
|
||||||
|
virtual void addDimAlign(const DL_DimensionData&,
|
||||||
|
const DL_DimAlignedData&) {}
|
||||||
|
virtual void addDimLinear(const DL_DimensionData&,
|
||||||
|
const DL_DimLinearData&) {}
|
||||||
|
virtual void addDimRadial(const DL_DimensionData&,
|
||||||
|
const DL_DimRadialData&) {}
|
||||||
|
virtual void addDimDiametric(const DL_DimensionData&,
|
||||||
|
const DL_DimDiametricData&) {}
|
||||||
|
virtual void addDimAngular(const DL_DimensionData&,
|
||||||
|
const DL_DimAngularData&) {}
|
||||||
|
virtual void addDimAngular3P(const DL_DimensionData&,
|
||||||
|
const DL_DimAngular3PData&) {}
|
||||||
|
virtual void addDimOrdinate(const DL_DimensionData&,
|
||||||
|
const DL_DimOrdinateData&) {}
|
||||||
|
virtual void addLeader(const DL_LeaderData&) {}
|
||||||
|
virtual void addLeaderVertex(const DL_LeaderVertexData&) {}
|
||||||
|
|
||||||
|
virtual void addHatch(const DL_HatchData&) {}
|
||||||
|
|
||||||
|
virtual void addTrace(const DL_TraceData&) {}
|
||||||
|
virtual void add3dFace(const DL_3dFaceData&) {}
|
||||||
|
virtual void addSolid(const DL_SolidData&) {}
|
||||||
|
|
||||||
|
virtual void addImage(const DL_ImageData&) {}
|
||||||
|
virtual void linkImage(const DL_ImageDefData&) {}
|
||||||
|
virtual void addHatchLoop(const DL_HatchLoopData&) {}
|
||||||
|
virtual void addHatchEdge(const DL_HatchEdgeData&) {}
|
||||||
|
|
||||||
|
virtual void addXRecord(const std::string&) {}
|
||||||
|
virtual void addXRecordString(int, const std::string&) {}
|
||||||
|
virtual void addXRecordReal(int, double) {}
|
||||||
|
virtual void addXRecordInt(int, int) {}
|
||||||
|
virtual void addXRecordBool(int, bool) {}
|
||||||
|
|
||||||
|
virtual void addXDataApp(const std::string&) {}
|
||||||
|
virtual void addXDataString(int, const std::string&) {}
|
||||||
|
virtual void addXDataReal(int, double) {}
|
||||||
|
virtual void addXDataInt(int, int) {}
|
||||||
|
|
||||||
|
virtual void addDictionary(const DL_DictionaryData&) {}
|
||||||
|
virtual void addDictionaryEntry(const DL_DictionaryEntryData&) {}
|
||||||
|
|
||||||
|
virtual void endEntity() {}
|
||||||
|
|
||||||
|
virtual void addComment(const std::string&) {}
|
||||||
|
|
||||||
|
virtual void setVariableVector(const std::string&, double, double, double, int) {}
|
||||||
|
virtual void setVariableString(const std::string&, const std::string&, int) {}
|
||||||
|
virtual void setVariableInt(const std::string&, int, int) {}
|
||||||
|
virtual void setVariableDouble(const std::string&, double, int) {}
|
||||||
|
#ifdef DL_COMPAT
|
||||||
|
virtual void setVariableVector(const char*, double, double, double, int) {}
|
||||||
|
virtual void setVariableString(const char*, const char*, int) {}
|
||||||
|
virtual void setVariableInt(const char*, int, int) {}
|
||||||
|
virtual void setVariableDouble(const char*, double, int) {}
|
||||||
|
virtual void processCodeValuePair(unsigned int, char*) {}
|
||||||
|
virtual void addComment(const char*) {}
|
||||||
|
virtual void addMTextChunk(const char*) {}
|
||||||
|
#endif
|
||||||
|
virtual void endSequence() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
369
datafile/dxf/dxflib/dl_creationinterface.h
Normal file
369
datafile/dxf/dxflib/dl_creationinterface.h
Normal file
@ -0,0 +1,369 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_CREATIONINTERFACE_H
|
||||||
|
#define DL_CREATIONINTERFACE_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "dl_attributes.h"
|
||||||
|
#include "dl_codes.h"
|
||||||
|
#include "dl_entities.h"
|
||||||
|
#include "dl_extrusion.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class (interface) for the creation of new entities.
|
||||||
|
* Inherit your class which takes care of the entities in the
|
||||||
|
* processed DXF file from this interface.
|
||||||
|
*
|
||||||
|
* Double arrays passed to your implementation contain 3 double
|
||||||
|
* values for x, y, z coordinates unless stated differently.
|
||||||
|
*
|
||||||
|
* @author Andrew Mustun
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_CreationInterface {
|
||||||
|
public:
|
||||||
|
DL_CreationInterface() {
|
||||||
|
extrusion = new DL_Extrusion;
|
||||||
|
}
|
||||||
|
virtual ~DL_CreationInterface() {
|
||||||
|
delete extrusion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every code / value tuple of the DXF file. The complete DXF file
|
||||||
|
* contents can be handled by the implemetation of this function.
|
||||||
|
*/
|
||||||
|
virtual void processCodeValuePair(unsigned int groupCode, const std::string& groupValue) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a section (entity, table entry, etc.) is finished.
|
||||||
|
*/
|
||||||
|
virtual void endSection() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every layer.
|
||||||
|
*/
|
||||||
|
virtual void addLayer(const DL_LayerData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every linetype.
|
||||||
|
*/
|
||||||
|
virtual void addLinetype(const DL_LinetypeData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every dash in linetype pattern
|
||||||
|
*/
|
||||||
|
virtual void addLinetypeDash(double length) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every block. Note: all entities added after this
|
||||||
|
* command go into this block until endBlock() is called.
|
||||||
|
*
|
||||||
|
* @see endBlock()
|
||||||
|
*/
|
||||||
|
virtual void addBlock(const DL_BlockData& data) = 0;
|
||||||
|
|
||||||
|
/** Called to end the current block */
|
||||||
|
virtual void endBlock() = 0;
|
||||||
|
|
||||||
|
/** Called for every text style */
|
||||||
|
virtual void addTextStyle(const DL_StyleData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every point */
|
||||||
|
virtual void addPoint(const DL_PointData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every line */
|
||||||
|
virtual void addLine(const DL_LineData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every xline */
|
||||||
|
virtual void addXLine(const DL_XLineData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every ray */
|
||||||
|
virtual void addRay(const DL_RayData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every arc */
|
||||||
|
virtual void addArc(const DL_ArcData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every circle */
|
||||||
|
virtual void addCircle(const DL_CircleData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every ellipse */
|
||||||
|
virtual void addEllipse(const DL_EllipseData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every polyline start */
|
||||||
|
virtual void addPolyline(const DL_PolylineData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every polyline vertex */
|
||||||
|
virtual void addVertex(const DL_VertexData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every spline */
|
||||||
|
virtual void addSpline(const DL_SplineData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every spline control point */
|
||||||
|
virtual void addControlPoint(const DL_ControlPointData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every spline fit point */
|
||||||
|
virtual void addFitPoint(const DL_FitPointData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every spline knot value */
|
||||||
|
virtual void addKnot(const DL_KnotData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every insert. */
|
||||||
|
virtual void addInsert(const DL_InsertData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every trace start */
|
||||||
|
virtual void addTrace(const DL_TraceData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every 3dface start */
|
||||||
|
virtual void add3dFace(const DL_3dFaceData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every solid start */
|
||||||
|
virtual void addSolid(const DL_SolidData& data) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/** Called for every multi Text entity. */
|
||||||
|
virtual void addMText(const DL_MTextData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for additional text chunks for MTEXT entities.
|
||||||
|
* The chunks come at 250 character in size each. Note that
|
||||||
|
* those chunks come <b>before</b> the actual MTEXT entity.
|
||||||
|
*/
|
||||||
|
virtual void addMTextChunk(const std::string& text) = 0;
|
||||||
|
|
||||||
|
/** Called for every text entity. */
|
||||||
|
virtual void addText(const DL_TextData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every arc aligned text entity. */
|
||||||
|
virtual void addArcAlignedText(const DL_ArcAlignedTextData& data) = 0;
|
||||||
|
|
||||||
|
/** Called for every block Attribute entity. */
|
||||||
|
virtual void addAttribute(const DL_AttributeData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every aligned dimension entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimAlign(const DL_DimensionData& data,
|
||||||
|
const DL_DimAlignedData& edata) = 0;
|
||||||
|
/**
|
||||||
|
* Called for every linear or rotated dimension entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimLinear(const DL_DimensionData& data,
|
||||||
|
const DL_DimLinearData& edata) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every radial dimension entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimRadial(const DL_DimensionData& data,
|
||||||
|
const DL_DimRadialData& edata) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every diametric dimension entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimDiametric(const DL_DimensionData& data,
|
||||||
|
const DL_DimDiametricData& edata) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every angular dimension (2 lines version) entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimAngular(const DL_DimensionData& data,
|
||||||
|
const DL_DimAngularData& edata) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every angular dimension (3 points version) entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimAngular3P(const DL_DimensionData& data,
|
||||||
|
const DL_DimAngular3PData& edata) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every ordinate dimension entity.
|
||||||
|
*/
|
||||||
|
virtual void addDimOrdinate(const DL_DimensionData& data,
|
||||||
|
const DL_DimOrdinateData& edata) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every leader start.
|
||||||
|
*/
|
||||||
|
virtual void addLeader(const DL_LeaderData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every leader vertex
|
||||||
|
*/
|
||||||
|
virtual void addLeaderVertex(const DL_LeaderVertexData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every hatch entity.
|
||||||
|
*/
|
||||||
|
virtual void addHatch(const DL_HatchData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every image entity.
|
||||||
|
*/
|
||||||
|
virtual void addImage(const DL_ImageData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every image definition.
|
||||||
|
*/
|
||||||
|
virtual void linkImage(const DL_ImageDefData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every hatch loop.
|
||||||
|
*/
|
||||||
|
virtual void addHatchLoop(const DL_HatchLoopData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every hatch edge entity.
|
||||||
|
*/
|
||||||
|
virtual void addHatchEdge(const DL_HatchEdgeData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every XRecord with the given handle.
|
||||||
|
*/
|
||||||
|
virtual void addXRecord(const std::string& handle) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XRecords of type string.
|
||||||
|
*/
|
||||||
|
virtual void addXRecordString(int code, const std::string& value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XRecords of type double.
|
||||||
|
*/
|
||||||
|
virtual void addXRecordReal(int code, double value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XRecords of type int.
|
||||||
|
*/
|
||||||
|
virtual void addXRecordInt(int code, int value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XRecords of type bool.
|
||||||
|
*/
|
||||||
|
virtual void addXRecordBool(int code, bool value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every beginning of an XData section of the given application.
|
||||||
|
*/
|
||||||
|
virtual void addXDataApp(const std::string& appId) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XData tuples.
|
||||||
|
*/
|
||||||
|
virtual void addXDataString(int code, const std::string& value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XData tuples.
|
||||||
|
*/
|
||||||
|
virtual void addXDataReal(int code, double value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for XData tuples.
|
||||||
|
*/
|
||||||
|
virtual void addXDataInt(int code, int value) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for dictionary objects.
|
||||||
|
*/
|
||||||
|
virtual void addDictionary(const DL_DictionaryData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for dictionary entries.
|
||||||
|
*/
|
||||||
|
virtual void addDictionaryEntry(const DL_DictionaryEntryData& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after an entity has been completed.
|
||||||
|
*/
|
||||||
|
virtual void endEntity() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every comment in the DXF file (code 999).
|
||||||
|
*/
|
||||||
|
virtual void addComment(const std::string& comment) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every vector variable in the DXF file (e.g. "$EXTMIN").
|
||||||
|
*/
|
||||||
|
virtual void setVariableVector(const std::string& key, double v1, double v2, double v3, int code) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every string variable in the DXF file (e.g. "$ACADVER").
|
||||||
|
*/
|
||||||
|
virtual void setVariableString(const std::string& key, const std::string& value, int code) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every int variable in the DXF file (e.g. "$ACADMAINTVER").
|
||||||
|
*/
|
||||||
|
virtual void setVariableInt(const std::string& key, int value, int code) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called for every double variable in the DXF file (e.g. "$DIMEXO").
|
||||||
|
*/
|
||||||
|
virtual void setVariableDouble(const std::string& key, double value, int code) = 0;
|
||||||
|
|
||||||
|
#ifdef DL_COMPAT
|
||||||
|
virtual void setVariableVector(const char* key, double v1, double v2, double v3, int code) = 0;
|
||||||
|
virtual void setVariableString(const char* key, const char* value, int code) = 0;
|
||||||
|
virtual void setVariableInt(const char* key, int value, int code) = 0;
|
||||||
|
virtual void setVariableDouble(const char* key, double value, int code) = 0;
|
||||||
|
virtual void processCodeValuePair(unsigned int groupCode, char* groupValue) = 0;
|
||||||
|
virtual void addComment(const char* comment) = 0;
|
||||||
|
virtual void addMTextChunk(const char* text) = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a SEQEND occurs (when a POLYLINE or ATTRIB is done)
|
||||||
|
*/
|
||||||
|
virtual void endSequence() = 0;
|
||||||
|
|
||||||
|
/** Sets the current attributes for entities. */
|
||||||
|
void setAttributes(const DL_Attributes& attrib) {
|
||||||
|
attributes = attrib;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the current attributes used for new entities. */
|
||||||
|
DL_Attributes getAttributes() {
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the current attributes for entities. */
|
||||||
|
void setExtrusion(double dx, double dy, double dz, double elevation) {
|
||||||
|
extrusion->setDirection(dx, dy, dz);
|
||||||
|
extrusion->setElevation(elevation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the current attributes used for new entities. */
|
||||||
|
DL_Extrusion* getExtrusion() {
|
||||||
|
return extrusion;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
DL_Attributes attributes;
|
||||||
|
DL_Extrusion *extrusion;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
5332
datafile/dxf/dxflib/dl_dxf.cpp
Normal file
5332
datafile/dxf/dxflib/dl_dxf.cpp
Normal file
File diff suppressed because it is too large
Load Diff
529
datafile/dxf/dxflib/dl_dxf.h
Normal file
529
datafile/dxf/dxflib/dl_dxf.h
Normal file
@ -0,0 +1,529 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_DXF_H
|
||||||
|
#define DL_DXF_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "dl_attributes.h"
|
||||||
|
#include "dl_codes.h"
|
||||||
|
#include "dl_entities.h"
|
||||||
|
#include "dl_writer_ascii.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#undef M_PI
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
//#pragma warning(disable : 4800)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI 3.1415926535897932384626433832795
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DL_NANDOUBLE
|
||||||
|
#define DL_NANDOUBLE std::numeric_limits<double>::quiet_NaN()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class DL_CreationInterface;
|
||||||
|
class DL_WriterA;
|
||||||
|
|
||||||
|
|
||||||
|
#define DL_VERSION "3.17.0.0"
|
||||||
|
|
||||||
|
#define DL_VERSION_MAJOR 3
|
||||||
|
#define DL_VERSION_MINOR 17
|
||||||
|
#define DL_VERSION_REV 0
|
||||||
|
#define DL_VERSION_BUILD 0
|
||||||
|
|
||||||
|
#define DL_UNKNOWN 0
|
||||||
|
#define DL_LAYER 10
|
||||||
|
#define DL_BLOCK 11
|
||||||
|
#define DL_ENDBLK 12
|
||||||
|
#define DL_LINETYPE 13
|
||||||
|
#define DL_STYLE 20
|
||||||
|
#define DL_SETTING 50
|
||||||
|
#define DL_ENTITY_POINT 100
|
||||||
|
#define DL_ENTITY_LINE 101
|
||||||
|
#define DL_ENTITY_POLYLINE 102
|
||||||
|
#define DL_ENTITY_LWPOLYLINE 103
|
||||||
|
#define DL_ENTITY_VERTEX 104
|
||||||
|
#define DL_ENTITY_SPLINE 105
|
||||||
|
#define DL_ENTITY_KNOT 106
|
||||||
|
#define DL_ENTITY_CONTROLPOINT 107
|
||||||
|
#define DL_ENTITY_ARC 108
|
||||||
|
#define DL_ENTITY_CIRCLE 109
|
||||||
|
#define DL_ENTITY_ELLIPSE 110
|
||||||
|
#define DL_ENTITY_INSERT 111
|
||||||
|
#define DL_ENTITY_TEXT 112
|
||||||
|
#define DL_ENTITY_MTEXT 113
|
||||||
|
#define DL_ENTITY_DIMENSION 114
|
||||||
|
#define DL_ENTITY_LEADER 115
|
||||||
|
#define DL_ENTITY_HATCH 116
|
||||||
|
#define DL_ENTITY_ATTRIB 117
|
||||||
|
#define DL_ENTITY_IMAGE 118
|
||||||
|
#define DL_ENTITY_IMAGEDEF 119
|
||||||
|
#define DL_ENTITY_TRACE 120
|
||||||
|
#define DL_ENTITY_SOLID 121
|
||||||
|
#define DL_ENTITY_3DFACE 122
|
||||||
|
#define DL_ENTITY_XLINE 123
|
||||||
|
#define DL_ENTITY_RAY 124
|
||||||
|
#define DL_ENTITY_ARCALIGNEDTEXT 125
|
||||||
|
#define DL_ENTITY_SEQEND 126
|
||||||
|
#define DL_XRECORD 200
|
||||||
|
#define DL_DICTIONARY 210
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reading and writing of DXF files.
|
||||||
|
*
|
||||||
|
* This class can read in a DXF file and calls methods from the
|
||||||
|
* interface DL_EntityContainer to add the entities to the
|
||||||
|
* contianer provided by the user of the library.
|
||||||
|
*
|
||||||
|
* It can also be used to write DXF files to a certain extent.
|
||||||
|
*
|
||||||
|
* When saving entities, special values for colors and linetypes
|
||||||
|
* can be used:
|
||||||
|
*
|
||||||
|
* Special colors are 0 (=BYBLOCK) and 256 (=BYLAYER).
|
||||||
|
* Special linetypes are "BYLAYER" and "BYBLOCK".
|
||||||
|
*
|
||||||
|
* @author Andrew Mustun
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_Dxf {
|
||||||
|
public:
|
||||||
|
DL_Dxf();
|
||||||
|
~DL_Dxf();
|
||||||
|
|
||||||
|
bool in(const std::string& file,
|
||||||
|
DL_CreationInterface* creationInterface);
|
||||||
|
bool readDxfGroups(FILE* fp,
|
||||||
|
DL_CreationInterface* creationInterface);
|
||||||
|
static bool getStrippedLine(std::string& s, unsigned int size,
|
||||||
|
FILE* stream, bool stripSpace = true);
|
||||||
|
|
||||||
|
bool readDxfGroups(std::stringstream& stream,
|
||||||
|
DL_CreationInterface* creationInterface);
|
||||||
|
bool in(std::stringstream &stream,
|
||||||
|
DL_CreationInterface* creationInterface);
|
||||||
|
static bool getStrippedLine(std::string& s, unsigned int size,
|
||||||
|
std::stringstream& stream, bool stripSpace = true);
|
||||||
|
|
||||||
|
static bool stripWhiteSpace(char** s, bool stripSpaces = true);
|
||||||
|
|
||||||
|
bool processDXFGroup(DL_CreationInterface* creationInterface,
|
||||||
|
int groupCode, const std::string& groupValue);
|
||||||
|
void addSetting(DL_CreationInterface* creationInterface);
|
||||||
|
void addLayer(DL_CreationInterface* creationInterface);
|
||||||
|
void addLinetype(DL_CreationInterface *creationInterface);
|
||||||
|
void addBlock(DL_CreationInterface* creationInterface);
|
||||||
|
void endBlock(DL_CreationInterface* creationInterface);
|
||||||
|
void addTextStyle(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addPoint(DL_CreationInterface* creationInterface);
|
||||||
|
void addLine(DL_CreationInterface* creationInterface);
|
||||||
|
void addXLine(DL_CreationInterface* creationInterface);
|
||||||
|
void addRay(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addPolyline(DL_CreationInterface* creationInterface);
|
||||||
|
void addVertex(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addSpline(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addArc(DL_CreationInterface* creationInterface);
|
||||||
|
void addCircle(DL_CreationInterface* creationInterface);
|
||||||
|
void addEllipse(DL_CreationInterface* creationInterface);
|
||||||
|
void addInsert(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addTrace(DL_CreationInterface* creationInterface);
|
||||||
|
void add3dFace(DL_CreationInterface* creationInterface);
|
||||||
|
void addSolid(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addMText(DL_CreationInterface* creationInterface);
|
||||||
|
void addText(DL_CreationInterface* creationInterface);
|
||||||
|
void addArcAlignedText(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addAttribute(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
DL_DimensionData getDimData();
|
||||||
|
void addDimLinear(DL_CreationInterface* creationInterface);
|
||||||
|
void addDimAligned(DL_CreationInterface* creationInterface);
|
||||||
|
void addDimRadial(DL_CreationInterface* creationInterface);
|
||||||
|
void addDimDiametric(DL_CreationInterface* creationInterface);
|
||||||
|
void addDimAngular(DL_CreationInterface* creationInterface);
|
||||||
|
void addDimAngular3P(DL_CreationInterface* creationInterface);
|
||||||
|
void addDimOrdinate(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addLeader(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addHatch(DL_CreationInterface* creationInterface);
|
||||||
|
void addHatchLoop();
|
||||||
|
void addHatchEdge();
|
||||||
|
bool handleHatchData(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addImage(DL_CreationInterface* creationInterface);
|
||||||
|
void addImageDef(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void addComment(DL_CreationInterface* creationInterface, const std::string& comment);
|
||||||
|
|
||||||
|
void addDictionary(DL_CreationInterface* creationInterface);
|
||||||
|
void addDictionaryEntry(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
bool handleXRecordData(DL_CreationInterface* creationInterface);
|
||||||
|
bool handleDictionaryData(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
bool handleXData(DL_CreationInterface *creationInterface);
|
||||||
|
bool handleMTextData(DL_CreationInterface* creationInterface);
|
||||||
|
bool handleLWPolylineData(DL_CreationInterface* creationInterface);
|
||||||
|
bool handleSplineData(DL_CreationInterface* creationInterface);
|
||||||
|
bool handleLeaderData(DL_CreationInterface* creationInterface);
|
||||||
|
bool handleLinetypeData(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void endEntity(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
void endSequence(DL_CreationInterface* creationInterface);
|
||||||
|
|
||||||
|
//int stringToInt(const char* s, bool* ok=NULL);
|
||||||
|
|
||||||
|
DL_WriterA* out(const char* file,
|
||||||
|
DL_Codes::version version=DL_VERSION_2000);
|
||||||
|
|
||||||
|
void writeHeader(DL_WriterA& dw);
|
||||||
|
|
||||||
|
void writePoint(DL_WriterA& dw,
|
||||||
|
const DL_PointData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeLine(DL_WriterA& dw,
|
||||||
|
const DL_LineData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeXLine(DL_WriterA& dw,
|
||||||
|
const DL_XLineData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeRay(DL_WriterA& dw,
|
||||||
|
const DL_RayData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writePolyline(DL_WriterA& dw,
|
||||||
|
const DL_PolylineData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeVertex(DL_WriterA& dw,
|
||||||
|
const DL_VertexData& data);
|
||||||
|
void writePolylineEnd(DL_WriterA& dw);
|
||||||
|
void writeSpline(DL_WriterA& dw,
|
||||||
|
const DL_SplineData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeControlPoint(DL_WriterA& dw,
|
||||||
|
const DL_ControlPointData& data);
|
||||||
|
void writeFitPoint(DL_WriterA& dw,
|
||||||
|
const DL_FitPointData& data);
|
||||||
|
void writeKnot(DL_WriterA& dw,
|
||||||
|
const DL_KnotData& data);
|
||||||
|
void writeCircle(DL_WriterA& dw,
|
||||||
|
const DL_CircleData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeArc(DL_WriterA& dw,
|
||||||
|
const DL_ArcData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeEllipse(DL_WriterA& dw,
|
||||||
|
const DL_EllipseData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeSolid(DL_WriterA& dw,
|
||||||
|
const DL_SolidData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeTrace(DL_WriterA& dw,
|
||||||
|
const DL_TraceData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void write3dFace(DL_WriterA& dw,
|
||||||
|
const DL_3dFaceData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeInsert(DL_WriterA& dw,
|
||||||
|
const DL_InsertData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeMText(DL_WriterA& dw,
|
||||||
|
const DL_MTextData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeText(DL_WriterA& dw,
|
||||||
|
const DL_TextData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeAttribute(DL_WriterA& dw,
|
||||||
|
const DL_AttributeData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimStyleOverrides(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data);
|
||||||
|
void writeDimAligned(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimAlignedData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimLinear(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimLinearData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimRadial(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimRadialData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimDiametric(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimDiametricData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimAngular(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimAngularData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimAngular3P(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimAngular3PData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeDimOrdinate(DL_WriterA& dw,
|
||||||
|
const DL_DimensionData& data,
|
||||||
|
const DL_DimOrdinateData& edata,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeLeader(DL_WriterA& dw,
|
||||||
|
const DL_LeaderData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeLeaderVertex(DL_WriterA& dw,
|
||||||
|
const DL_LeaderVertexData& data);
|
||||||
|
void writeHatch1(DL_WriterA& dw,
|
||||||
|
const DL_HatchData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeHatch2(DL_WriterA& dw,
|
||||||
|
const DL_HatchData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
void writeHatchLoop1(DL_WriterA& dw,
|
||||||
|
const DL_HatchLoopData& data);
|
||||||
|
void writeHatchLoop2(DL_WriterA& dw,
|
||||||
|
const DL_HatchLoopData& data);
|
||||||
|
void writeHatchEdge(DL_WriterA& dw,
|
||||||
|
const DL_HatchEdgeData& data);
|
||||||
|
|
||||||
|
int writeImage(DL_WriterA& dw,
|
||||||
|
const DL_ImageData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
|
||||||
|
void writeImageDef(DL_WriterA& dw, int handle,
|
||||||
|
const DL_ImageData& data);
|
||||||
|
|
||||||
|
void writeLayer(DL_WriterA& dw,
|
||||||
|
const DL_LayerData& data,
|
||||||
|
const DL_Attributes& attrib);
|
||||||
|
|
||||||
|
void writeLinetype(DL_WriterA& dw,
|
||||||
|
const DL_LinetypeData& data);
|
||||||
|
|
||||||
|
void writeAppid(DL_WriterA& dw, const std::string& name);
|
||||||
|
|
||||||
|
void writeBlock(DL_WriterA& dw,
|
||||||
|
const DL_BlockData& data);
|
||||||
|
void writeEndBlock(DL_WriterA& dw, const std::string& name);
|
||||||
|
|
||||||
|
void writeVPort(DL_WriterA& dw);
|
||||||
|
void writeStyle(DL_WriterA& dw, const DL_StyleData& style);
|
||||||
|
void writeView(DL_WriterA& dw);
|
||||||
|
void writeUcs(DL_WriterA& dw);
|
||||||
|
void writeDimStyle(DL_WriterA& dw,
|
||||||
|
double dimasz, double dimexe, double dimexo,
|
||||||
|
double dimgap, double dimtxt);
|
||||||
|
void writeBlockRecord(DL_WriterA& dw);
|
||||||
|
void writeBlockRecord(DL_WriterA& dw, const std::string& name);
|
||||||
|
void writeObjects(DL_WriterA& dw, const std::string& appDictionaryName = "");
|
||||||
|
void writeAppDictionary(DL_WriterA& dw);
|
||||||
|
int writeDictionaryEntry(DL_WriterA& dw, const std::string& name);
|
||||||
|
void writeXRecord(DL_WriterA& dw, int handle, int value);
|
||||||
|
void writeXRecord(DL_WriterA& dw, int handle, double value);
|
||||||
|
void writeXRecord(DL_WriterA& dw, int handle, bool value);
|
||||||
|
void writeXRecord(DL_WriterA& dw, int handle, const std::string& value);
|
||||||
|
void writeObjectsEnd(DL_WriterA& dw);
|
||||||
|
|
||||||
|
void writeComment(DL_WriterA& dw, const std::string& comment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given string into a double or returns the given
|
||||||
|
* default valud (def) if value is NULL or empty.
|
||||||
|
*/
|
||||||
|
//static double toReal(const char* value, double def=0.0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given string into an int or returns the given
|
||||||
|
* default valud (def) if value is NULL or empty.
|
||||||
|
*/
|
||||||
|
// static int toInt(const char* value, int def=0) {
|
||||||
|
// if (value!=NULL && value[0] != '\0') {
|
||||||
|
// return atoi(value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return def;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given string into a string or returns the given
|
||||||
|
* default valud (def) if value is NULL or empty.
|
||||||
|
*/
|
||||||
|
// static const char* toString(const char* value, const char* def="") {
|
||||||
|
// if (value!=NULL && value[0] != '\0') {
|
||||||
|
// return value;
|
||||||
|
// } else {
|
||||||
|
// return def;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
static bool checkVariable(const char* var, DL_Codes::version version);
|
||||||
|
|
||||||
|
DL_Codes::version getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getLibVersion(const std::string &str);
|
||||||
|
|
||||||
|
static void test();
|
||||||
|
|
||||||
|
bool hasValue(int code) {
|
||||||
|
return values.count(code)==1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getIntValue(int code, int def) {
|
||||||
|
if (!hasValue(code)) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return toInt(values[code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int toInt(const std::string& str) {
|
||||||
|
char* p;
|
||||||
|
return strtol(str.c_str(), &p, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getInt16Value(int code, int def) {
|
||||||
|
if (!hasValue(code)) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return toInt16(values[code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int toInt16(const std::string& str) {
|
||||||
|
char* p;
|
||||||
|
return strtol(str.c_str(), &p, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool toBool(const std::string& str) {
|
||||||
|
char* p;
|
||||||
|
return (bool)strtol(str.c_str(), &p, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getStringValue(int code, const std::string& def) {
|
||||||
|
if (!hasValue(code)) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return values[code];
|
||||||
|
}
|
||||||
|
|
||||||
|
double getRealValue(int code, double def) {
|
||||||
|
if (!hasValue(code)) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return toReal(values[code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
double toReal(const std::string& str) {
|
||||||
|
double ret;
|
||||||
|
// make sure the real value uses '.' not ',':
|
||||||
|
std::string str2 = str;
|
||||||
|
std::replace(str2.begin(), str2.end(), ',', '.');
|
||||||
|
// make sure c++ expects '.' not ',':
|
||||||
|
std::istringstream istr(str2);
|
||||||
|
//istr.imbue(std::locale("C"));
|
||||||
|
istr >> ret;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DL_Codes::version version;
|
||||||
|
|
||||||
|
std::string polylineLayer;
|
||||||
|
double* vertices;
|
||||||
|
int maxVertices;
|
||||||
|
int vertexIndex;
|
||||||
|
|
||||||
|
double* knots;
|
||||||
|
int maxKnots;
|
||||||
|
int knotIndex;
|
||||||
|
|
||||||
|
double* weights;
|
||||||
|
int weightIndex;
|
||||||
|
|
||||||
|
double* controlPoints;
|
||||||
|
int maxControlPoints;
|
||||||
|
int controlPointIndex;
|
||||||
|
|
||||||
|
double* fitPoints;
|
||||||
|
int maxFitPoints;
|
||||||
|
int fitPointIndex;
|
||||||
|
|
||||||
|
double* leaderVertices;
|
||||||
|
int maxLeaderVertices;
|
||||||
|
int leaderVertexIndex;
|
||||||
|
|
||||||
|
bool firstHatchLoop;
|
||||||
|
DL_HatchEdgeData hatchEdge;
|
||||||
|
std::vector<std::vector<DL_HatchEdgeData> > hatchEdges;
|
||||||
|
|
||||||
|
std::string xRecordHandle;
|
||||||
|
bool xRecordValues;
|
||||||
|
|
||||||
|
// Only the useful part of the group code
|
||||||
|
std::string groupCodeTmp;
|
||||||
|
// ...same as integer
|
||||||
|
unsigned int groupCode;
|
||||||
|
// Only the useful part of the group value
|
||||||
|
std::string groupValue;
|
||||||
|
// Current entity type
|
||||||
|
int currentObjectType;
|
||||||
|
// Value of the current setting
|
||||||
|
char settingValue[DL_DXF_MAXLINE+1];
|
||||||
|
// Key of the current setting (e.g. "$ACADVER")
|
||||||
|
std::string settingKey;
|
||||||
|
// Stores the group codes
|
||||||
|
std::map<int, std::string> values;
|
||||||
|
// First call of this method. We initialize all group values in
|
||||||
|
// the first call.
|
||||||
|
bool firstCall;
|
||||||
|
// Attributes of the current entity (layer, color, width, line type)
|
||||||
|
DL_Attributes attrib;
|
||||||
|
// library version. hex: 0x20003001 = 2.0.3.1
|
||||||
|
int libVersion;
|
||||||
|
// app specific dictionary handle:
|
||||||
|
unsigned long appDictionaryHandle;
|
||||||
|
// handle of standard text style, referenced by dimstyle:
|
||||||
|
unsigned long styleHandleStd;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// EOF
|
||||||
1813
datafile/dxf/dxflib/dl_entities.h
Normal file
1813
datafile/dxf/dxflib/dl_entities.h
Normal file
File diff suppressed because it is too large
Load Diff
55
datafile/dxf/dxflib/dl_exception.h
Normal file
55
datafile/dxf/dxflib/dl_exception.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
** Copyright (C) 2001 Robert J. Campbell Jr.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_EXCEPTION_H
|
||||||
|
#define DL_EXCEPTION_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for exception handling.
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_Exception {}
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for exception handling.
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_NullStrExc : public DL_Exception {}
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for exception handling.
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_GroupCodeExc : public DL_Exception {
|
||||||
|
DL_GroupCodeExc(int gc=0) : groupCode(gc) {}
|
||||||
|
int groupCode;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
143
datafile/dxf/dxflib/dl_extrusion.h
Normal file
143
datafile/dxf/dxflib/dl_extrusion.h
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_EXTRUSION_H
|
||||||
|
#define DL_EXTRUSION_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extrusion direction.
|
||||||
|
*
|
||||||
|
* @author Andrew Mustun
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_Extrusion {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
DL_Extrusion() {
|
||||||
|
direction = new double[3];
|
||||||
|
setDirection(0.0, 0.0, 1.0);
|
||||||
|
setElevation(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
~DL_Extrusion() {
|
||||||
|
delete[] direction ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for DXF extrusion.
|
||||||
|
*
|
||||||
|
* @param direction Vector of axis along which the entity shall be extruded
|
||||||
|
* this is also the Z axis of the Entity coordinate system
|
||||||
|
* @param elevation Distance of the entities XY plane from the origin of the
|
||||||
|
* world coordinate system
|
||||||
|
*/
|
||||||
|
DL_Extrusion(double dx, double dy, double dz, double elevation) {
|
||||||
|
direction = new double[3];
|
||||||
|
setDirection(dx, dy, dz);
|
||||||
|
setElevation(elevation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the direction vector.
|
||||||
|
*/
|
||||||
|
void setDirection(double dx, double dy, double dz) {
|
||||||
|
direction[0]=dx;
|
||||||
|
direction[1]=dy;
|
||||||
|
direction[2]=dz;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return direction vector.
|
||||||
|
*/
|
||||||
|
double* getDirection() const {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return direction vector.
|
||||||
|
*/
|
||||||
|
void getDirection(double dir[]) const {
|
||||||
|
dir[0]=direction[0];
|
||||||
|
dir[1]=direction[1];
|
||||||
|
dir[2]=direction[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the elevation.
|
||||||
|
*/
|
||||||
|
void setElevation(double elevation) {
|
||||||
|
this->elevation = elevation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Elevation.
|
||||||
|
*/
|
||||||
|
double getElevation() const {
|
||||||
|
return elevation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies extrusion (deep copies) from another extrusion object.
|
||||||
|
*/
|
||||||
|
DL_Extrusion operator = (const DL_Extrusion& extru) {
|
||||||
|
setDirection(extru.direction[0], extru.direction[1], extru.direction[2]);
|
||||||
|
setElevation(extru.elevation);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
double *direction;
|
||||||
|
double elevation;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
13
datafile/dxf/dxflib/dl_global.h
Normal file
13
datafile/dxf/dxflib/dl_global.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#if defined(DXFLIB_DLL)
|
||||||
|
# ifdef _WIN32
|
||||||
|
# if defined(DXFLIB_LIBRARY)
|
||||||
|
# define DXFLIB_EXPORT __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# define DXFLIB_EXPORT __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# define DXFLIB_EXPORT
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define DXFLIB_EXPORT
|
||||||
|
#endif
|
||||||
654
datafile/dxf/dxflib/dl_writer.h
Normal file
654
datafile/dxf/dxflib/dl_writer.h
Normal file
@ -0,0 +1,654 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
** Copyright (C) 2001 Robert J. Campbell Jr.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_WRITER_H
|
||||||
|
#define DL_WRITER_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "dl_attributes.h"
|
||||||
|
#include "dl_codes.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines interface for writing low level DXF constructs to
|
||||||
|
* a file. Implementation is defined in derived classes that write
|
||||||
|
* to binary or ASCII files.
|
||||||
|
*
|
||||||
|
* Implements functions that write higher level constructs in terms of
|
||||||
|
* the low level ones.
|
||||||
|
*
|
||||||
|
* @todo Add error checking for string/entry length.
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_Writer {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @param version DXF version. Defaults to DL_VERSION_2002.
|
||||||
|
*/
|
||||||
|
DL_Writer(DL_Codes::version version) : m_handle(0x30) {
|
||||||
|
this->version = version;
|
||||||
|
modelSpaceHandle = 0;
|
||||||
|
paperSpaceHandle = 0;
|
||||||
|
paperSpace0Handle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~DL_Writer() {}
|
||||||
|
;
|
||||||
|
|
||||||
|
/** Generic section for section 'name'.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* name
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void section(const char* name) const {
|
||||||
|
dxfString(0, "SECTION");
|
||||||
|
dxfString(2, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section HEADER
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* HEADER
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionHeader() const {
|
||||||
|
section("HEADER");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section TABLES
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* TABLES
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionTables() const {
|
||||||
|
section("TABLES");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section BLOCKS
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* BLOCKS
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionBlocks() const {
|
||||||
|
section("BLOCKS");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section ENTITIES
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* ENTITIES
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionEntities() const {
|
||||||
|
section("ENTITIES");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section CLASSES
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* CLASSES
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionClasses() const {
|
||||||
|
section("CLASSES");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section OBJECTS
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* SECTION
|
||||||
|
* 2
|
||||||
|
* OBJECTS
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionObjects() const {
|
||||||
|
section("OBJECTS");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End of a section.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* ENDSEC
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionEnd() const {
|
||||||
|
dxfString(0, "ENDSEC");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic table for table 'name' with 'num' entries:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* TABLE
|
||||||
|
* 2
|
||||||
|
* name
|
||||||
|
* 70
|
||||||
|
* num
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void table(const char* name, int num, int h=0) const {
|
||||||
|
dxfString(0, "TABLE");
|
||||||
|
dxfString(2, name);
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
if (h==0) {
|
||||||
|
handle();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dxfHex(5, h);
|
||||||
|
}
|
||||||
|
dxfString(100, "AcDbSymbolTable");
|
||||||
|
}
|
||||||
|
dxfInt(70, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Table for layers.
|
||||||
|
*
|
||||||
|
* @param num Number of layers in total.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* TABLE
|
||||||
|
* 2
|
||||||
|
* LAYER
|
||||||
|
* 70
|
||||||
|
* num
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableLayers(int num) const {
|
||||||
|
table("LAYER", num, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Table for line types.
|
||||||
|
*
|
||||||
|
* @param num Number of line types in total.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* TABLE
|
||||||
|
* 2
|
||||||
|
* LTYPE
|
||||||
|
* 70
|
||||||
|
* num
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableLinetypes(int num) const {
|
||||||
|
//linetypeHandle = 5;
|
||||||
|
table("LTYPE", num, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Table for application id.
|
||||||
|
*
|
||||||
|
* @param num Number of registered applications in total.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* TABLE
|
||||||
|
* 2
|
||||||
|
* APPID
|
||||||
|
* 70
|
||||||
|
* num
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableAppid(int num) const {
|
||||||
|
table("APPID", num, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Table for text style.
|
||||||
|
*
|
||||||
|
* @param num Number of text styles.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* TABLE
|
||||||
|
* 2
|
||||||
|
* STYLE
|
||||||
|
* 70
|
||||||
|
* num
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableStyle(int num) const {
|
||||||
|
table("STYLE", num, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End of a table.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* ENDTAB
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableEnd() const {
|
||||||
|
dxfString(0, "ENDTAB");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End of the DXF file.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* EOF
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void dxfEOF() const {
|
||||||
|
dxfString(0, "EOF");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comment.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 999
|
||||||
|
* text
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void comment(const char* text) const {
|
||||||
|
dxfString(999, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* entTypeName
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @return Unique handle or 0.
|
||||||
|
*/
|
||||||
|
void entity(const char* entTypeName) const {
|
||||||
|
dxfString(0, entTypeName);
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
handle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attributes of an entity.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 8
|
||||||
|
* layer
|
||||||
|
* 62
|
||||||
|
* color
|
||||||
|
* 39
|
||||||
|
* width
|
||||||
|
* 6
|
||||||
|
* linetype
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void entityAttributes(const DL_Attributes& attrib) const {
|
||||||
|
|
||||||
|
// layer name:
|
||||||
|
dxfString(8, attrib.getLayer());
|
||||||
|
|
||||||
|
// R12 doesn't accept BYLAYER values. The value has to be missing
|
||||||
|
// in that case.
|
||||||
|
if (version>=DL_VERSION_2000 || attrib.getColor()!=256) {
|
||||||
|
dxfInt(62, attrib.getColor());
|
||||||
|
}
|
||||||
|
if (version>=DL_VERSION_2000 && attrib.getColor24()!=-1) {
|
||||||
|
dxfInt(420, attrib.getColor24());
|
||||||
|
}
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
dxfInt(370, attrib.getWidth());
|
||||||
|
}
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
dxfReal(48, attrib.getLinetypeScale());
|
||||||
|
}
|
||||||
|
std::string linetype = attrib.getLinetype();
|
||||||
|
std::transform(linetype.begin(), linetype.end(), linetype.begin(), ::toupper);
|
||||||
|
if (version>=DL_VERSION_2000 || linetype=="BYLAYER") {
|
||||||
|
dxfString(6, attrib.getLinetype());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass.
|
||||||
|
*/
|
||||||
|
void subClass(const char* sub) const {
|
||||||
|
dxfString(100, sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layer (must be in the TABLES section LAYER).
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* LAYER
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableLayerEntry(unsigned long int h=0) const {
|
||||||
|
dxfString(0, "LAYER");
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
if (h==0) {
|
||||||
|
handle();
|
||||||
|
} else {
|
||||||
|
dxfHex(5, h);
|
||||||
|
}
|
||||||
|
dxfString(100, "AcDbSymbolTableRecord");
|
||||||
|
dxfString(100, "AcDbLayerTableRecord");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Line type (must be in the TABLES section LTYPE).
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* LTYPE
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableLinetypeEntry(unsigned long int h=0) const {
|
||||||
|
dxfString(0, "LTYPE");
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
if (h==0) {
|
||||||
|
handle();
|
||||||
|
} else {
|
||||||
|
dxfHex(5, h);
|
||||||
|
}
|
||||||
|
//dxfHex(330, 0x5);
|
||||||
|
dxfString(100, "AcDbSymbolTableRecord");
|
||||||
|
dxfString(100, "AcDbLinetypeTableRecord");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appid (must be in the TABLES section APPID).
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* APPID
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void tableAppidEntry(unsigned long int h=0) const {
|
||||||
|
dxfString(0, "APPID");
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
if (h==0) {
|
||||||
|
handle();
|
||||||
|
} else {
|
||||||
|
dxfHex(5, h);
|
||||||
|
}
|
||||||
|
//dxfHex(330, 0x9);
|
||||||
|
dxfString(100, "AcDbSymbolTableRecord");
|
||||||
|
dxfString(100, "AcDbRegAppTableRecord");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block (must be in the section BLOCKS).
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* BLOCK
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionBlockEntry(unsigned long int h=0) const {
|
||||||
|
dxfString(0, "BLOCK");
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
if (h==0) {
|
||||||
|
handle();
|
||||||
|
} else {
|
||||||
|
dxfHex(5, h);
|
||||||
|
}
|
||||||
|
//dxfHex(330, blockHandle);
|
||||||
|
dxfString(100, "AcDbEntity");
|
||||||
|
if (h==0x1C) {
|
||||||
|
dxfInt(67, 1);
|
||||||
|
}
|
||||||
|
dxfString(8, "0"); // TODO: Layer for block
|
||||||
|
dxfString(100, "AcDbBlockBegin");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End of Block (must be in the section BLOCKS).
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 0
|
||||||
|
* ENDBLK
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
void sectionBlockEntryEnd(unsigned long int h=0) const {
|
||||||
|
dxfString(0, "ENDBLK");
|
||||||
|
if (version>=DL_VERSION_2000) {
|
||||||
|
if (h==0) {
|
||||||
|
handle();
|
||||||
|
} else {
|
||||||
|
dxfHex(5, h);
|
||||||
|
}
|
||||||
|
//dxfHex(330, blockHandle);
|
||||||
|
dxfString(100, "AcDbEntity");
|
||||||
|
if (h==0x1D) {
|
||||||
|
dxfInt(67, 1);
|
||||||
|
}
|
||||||
|
dxfString(8, "0"); // TODO: Layer for block
|
||||||
|
dxfString(100, "AcDbBlockEnd");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void color(int col=256) const {
|
||||||
|
dxfInt(62, col);
|
||||||
|
}
|
||||||
|
void linetype(const char *lt) const {
|
||||||
|
dxfString(6, lt);
|
||||||
|
}
|
||||||
|
void linetypeScale(double scale) const {
|
||||||
|
dxfReal(48, scale);
|
||||||
|
}
|
||||||
|
void lineWeight(int lw) const {
|
||||||
|
dxfInt(370, lw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void coord(int gc, double x, double y, double z=0) const {
|
||||||
|
dxfReal(gc, x);
|
||||||
|
dxfReal(gc+10, y);
|
||||||
|
dxfReal(gc+20, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void coordTriplet(int gc, const double* value) const {
|
||||||
|
if (value) {
|
||||||
|
dxfReal(gc, *value++);
|
||||||
|
dxfReal(gc+10, *value++);
|
||||||
|
dxfReal(gc+20, *value++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetHandle() const {
|
||||||
|
m_handle = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a unique handle and returns it.
|
||||||
|
*/
|
||||||
|
unsigned long handle(int gc=5) const {
|
||||||
|
// handle has to be hex
|
||||||
|
dxfHex(gc, m_handle);
|
||||||
|
return m_handle++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Next handle that will be written.
|
||||||
|
*/
|
||||||
|
unsigned long getNextHandle() const {
|
||||||
|
return m_handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increases handle, so that the handle returned remains available.
|
||||||
|
*/
|
||||||
|
unsigned long incHandle() const {
|
||||||
|
return m_handle++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the handle of the model space. Entities refer to
|
||||||
|
* this handle.
|
||||||
|
*/
|
||||||
|
void setModelSpaceHandle(unsigned long h) {
|
||||||
|
modelSpaceHandle = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long getModelSpaceHandle() {
|
||||||
|
return modelSpaceHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the handle of the paper space. Some special blocks refer to
|
||||||
|
* this handle.
|
||||||
|
*/
|
||||||
|
void setPaperSpaceHandle(unsigned long h) {
|
||||||
|
paperSpaceHandle = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long getPaperSpaceHandle() {
|
||||||
|
return paperSpaceHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the handle of the paper space 0. Some special blocks refer to
|
||||||
|
* this handle.
|
||||||
|
*/
|
||||||
|
void setPaperSpace0Handle(unsigned long h) {
|
||||||
|
paperSpace0Handle = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long getPaperSpace0Handle() {
|
||||||
|
return paperSpace0Handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Must be overwritten by the implementing class to write a
|
||||||
|
* real value to the file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value The real value.
|
||||||
|
*/
|
||||||
|
virtual void dxfReal(int gc, double value) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Must be overwritten by the implementing class to write an
|
||||||
|
* int value to the file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value The int value.
|
||||||
|
*/
|
||||||
|
virtual void dxfInt(int gc, int value) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be overwritten by the implementing class to write a
|
||||||
|
* bool value to the file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value The bool value.
|
||||||
|
*/
|
||||||
|
virtual void dxfBool(int gc, bool value) const {
|
||||||
|
dxfInt(gc, (int)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Must be overwritten by the implementing class to write an
|
||||||
|
* int value (hex) to the file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value The int value.
|
||||||
|
*/
|
||||||
|
virtual void dxfHex(int gc, int value) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Must be overwritten by the implementing class to write a
|
||||||
|
* string to the file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value The string.
|
||||||
|
*/
|
||||||
|
virtual void dxfString(int gc, const char* value) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Must be overwritten by the implementing class to write a
|
||||||
|
* string to the file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value The string.
|
||||||
|
*/
|
||||||
|
virtual void dxfString(int gc, const std::string& value) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mutable unsigned long m_handle;
|
||||||
|
mutable unsigned long modelSpaceHandle;
|
||||||
|
mutable unsigned long paperSpaceHandle;
|
||||||
|
mutable unsigned long paperSpace0Handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DXF version to be created.
|
||||||
|
*/
|
||||||
|
DL_Codes::version version;
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
156
datafile/dxf/dxflib/dl_writer_ascii.cpp
Normal file
156
datafile/dxf/dxflib/dl_writer_ascii.cpp
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
** Copyright (C) 2001 Robert J. Campbell Jr.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "dl_writer_ascii.h"
|
||||||
|
#include "dl_exception.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the output file.
|
||||||
|
*/
|
||||||
|
void DL_WriterA::close() const {
|
||||||
|
m_ofile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @retval true Opening file has failed.
|
||||||
|
* @retval false Otherwise.
|
||||||
|
*/
|
||||||
|
bool DL_WriterA::openFailed() const {
|
||||||
|
return m_ofile.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a real (double) variable to the DXF file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value Double value
|
||||||
|
*/
|
||||||
|
void DL_WriterA::dxfReal(int gc, double value) const {
|
||||||
|
char str[256];
|
||||||
|
if (version==DL_Codes::AC1009_MIN) {
|
||||||
|
sprintf(str, "%.6lf", value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sprintf(str, "%.16lf", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix for german locale:
|
||||||
|
strReplace(str, ',', '.');
|
||||||
|
|
||||||
|
// Cut away those zeros at the end:
|
||||||
|
bool dot = false;
|
||||||
|
int end = -1;
|
||||||
|
for (unsigned int i=0; i<strlen(str); ++i) {
|
||||||
|
if (str[i]=='.') {
|
||||||
|
dot = true;
|
||||||
|
end = i+2;
|
||||||
|
continue;
|
||||||
|
} else if (dot && str[i]!='0') {
|
||||||
|
end = i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (end>0 && end<(int)strlen(str)) {
|
||||||
|
str[end] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
dxfString(gc, str);
|
||||||
|
m_ofile.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes an int variable to the DXF file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value Int value
|
||||||
|
*/
|
||||||
|
void DL_WriterA::dxfInt(int gc, int value) const {
|
||||||
|
m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n" << value << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a hex int variable to the DXF file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value Int value
|
||||||
|
*/
|
||||||
|
void DL_WriterA::dxfHex(int gc, int value) const {
|
||||||
|
char str[12];
|
||||||
|
sprintf(str, "%0X", value);
|
||||||
|
dxfString(gc, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a string variable to the DXF file.
|
||||||
|
*
|
||||||
|
* @param gc Group code.
|
||||||
|
* @param value String
|
||||||
|
*/
|
||||||
|
void DL_WriterA::dxfString(int gc, const char* value) const {
|
||||||
|
if (value==NULL) {
|
||||||
|
#ifndef __GCC2x__
|
||||||
|
//throw DL_NullStrExc();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
|
||||||
|
<< value << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DL_WriterA::dxfString(int gc, const std::string& value) const {
|
||||||
|
m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n"
|
||||||
|
<< value << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces every occurence of src with dest in the null terminated str.
|
||||||
|
*/
|
||||||
|
void DL_WriterA::strReplace(char* str, char src, char dest) {
|
||||||
|
size_t i;
|
||||||
|
for (i=0; i<strlen(str); i++) {
|
||||||
|
if (str[i]==src) {
|
||||||
|
str[i] = dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
74
datafile/dxf/dxflib/dl_writer_ascii.h
Normal file
74
datafile/dxf/dxflib/dl_writer_ascii.h
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
|
||||||
|
** Copyright (C) 2001 Robert J. Campbell Jr.
|
||||||
|
**
|
||||||
|
** This file is part of the dxflib project.
|
||||||
|
**
|
||||||
|
** This file is free software; you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Licensees holding valid dxflib Professional Edition licenses may use
|
||||||
|
** this file in accordance with the dxflib Commercial License
|
||||||
|
** Agreement provided with the Software.
|
||||||
|
**
|
||||||
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
**
|
||||||
|
** See http://www.ribbonsoft.com for further details.
|
||||||
|
**
|
||||||
|
** Contact info@ribbonsoft.com if any conditions of this licensing are
|
||||||
|
** not clear to you.
|
||||||
|
**
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#ifndef DL_WRITER_ASCII_H
|
||||||
|
#define DL_WRITER_ASCII_H
|
||||||
|
|
||||||
|
#include "dl_global.h"
|
||||||
|
|
||||||
|
#if _MSC_VER > 1000
|
||||||
|
#pragma once
|
||||||
|
#endif // _MSC_VER > 1000
|
||||||
|
|
||||||
|
#include "dl_writer.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements functions defined in DL_Writer for writing low
|
||||||
|
* level DXF constructs to an ASCII format DXF file.
|
||||||
|
*
|
||||||
|
* @para fname File name of the file to be created.
|
||||||
|
* @para version DXF version. Defaults to DL_VERSION_2002.
|
||||||
|
*
|
||||||
|
* @todo What if \c fname is NULL? Or \c fname can't be opened for
|
||||||
|
* another reason?
|
||||||
|
*/
|
||||||
|
class DXFLIB_EXPORT DL_WriterA : public DL_Writer {
|
||||||
|
public:
|
||||||
|
DL_WriterA(const char* fname, DL_Codes::version version=DL_VERSION_2000)
|
||||||
|
: DL_Writer(version), m_ofile(fname) {}
|
||||||
|
virtual ~DL_WriterA() {}
|
||||||
|
|
||||||
|
bool openFailed() const;
|
||||||
|
void close() const;
|
||||||
|
void dxfReal(int gc, double value) const;
|
||||||
|
void dxfInt(int gc, int value) const;
|
||||||
|
void dxfHex(int gc, int value) const;
|
||||||
|
void dxfString(int gc, const char* value) const;
|
||||||
|
void dxfString(int gc, const std::string& value) const;
|
||||||
|
|
||||||
|
static void strReplace(char* str, char src, char dest);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* DXF file to be created.
|
||||||
|
*/
|
||||||
|
mutable std::ofstream m_ofile;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
379
datafile/dxf/dxfreader.cpp
Normal file
379
datafile/dxf/dxfreader.cpp
Normal file
@ -0,0 +1,379 @@
|
|||||||
|
#include "dxfreader.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DxfReader::DxfReader(const QString &fileName, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, fileName(fileName)
|
||||||
|
{
|
||||||
|
//QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
|
||||||
|
|
||||||
|
// 读取 dxf 文件
|
||||||
|
DL_Dxf *dxf = new DL_Dxf;
|
||||||
|
if (!dxf->in(std::string(fileName.toLocal8Bit()), this)) { // if file open failed
|
||||||
|
std::cerr << std::string(fileName.toLocal8Bit()) << " could not be opened.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete dxf;
|
||||||
|
dxf = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addText(const DL_TextData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfText << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addLine(const DL_LineData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfLines << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addArc(const DL_ArcData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfArcs << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addCircle(const DL_CircleData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfCircles << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addEllipse(const DL_EllipseData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfEllipses << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addPolyline(const DL_PolylineData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfPolylines << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addPoint(const DL_PointData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfPoints << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addSpline(const DL_SplineData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfSplines << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addBlock(const DL_BlockData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfBlocks << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::endBlock()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addLayer(const DL_LayerData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfLayers << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addLinetype(const DL_LinetypeData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfLinetypes << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addLinetypeDash(double length)
|
||||||
|
{
|
||||||
|
if(length < 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXLine(const DL_XLineData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfXLines << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addRay(const DL_RayData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfRays << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addVertex(const DL_VertexData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfVertexs << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addControlPoint(const DL_ControlPointData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfControlPoints << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addFitPoint(const DL_FitPointData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfFitPoints << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addKnot(const DL_KnotData &data)
|
||||||
|
{
|
||||||
|
if(data.k == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addInsert(const DL_InsertData &data)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addSolid(const DL_SolidData &data)
|
||||||
|
{
|
||||||
|
if(data.x == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addTrace(const DL_TraceData &data)
|
||||||
|
{
|
||||||
|
if(data.x == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addTextStyle(const DL_StyleData &data)
|
||||||
|
{
|
||||||
|
if(data.flags == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addMTextChunk(const std::string &text)
|
||||||
|
{
|
||||||
|
if(text.data() == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addMText(const DL_MTextData &data)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addArcAlignedText(const DL_ArcAlignedTextData &data)
|
||||||
|
{
|
||||||
|
if(data.alignment == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addAttribute(const DL_AttributeData &data)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimAlign(const DL_DimensionData &data, const DL_DimAlignedData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.epx1 == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimLinear(const DL_DimensionData &data, const DL_DimLinearData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.angle == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimRadial(const DL_DimensionData &data, const DL_DimRadialData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.dpx == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimDiametric(const DL_DimensionData &data, const DL_DimDiametricData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.dpx == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimAngular(const DL_DimensionData &data, const DL_DimAngularData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.dpx1 == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimAngular3P(const DL_DimensionData &data, const DL_DimAngular3PData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.dpx1 == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDimOrdinate(const DL_DimensionData &data, const DL_DimOrdinateData &edata)
|
||||||
|
{
|
||||||
|
if(data.angle == 0){}
|
||||||
|
if(edata.dpx1 == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addLeader(const DL_LeaderData &data)
|
||||||
|
{
|
||||||
|
if(data.arrowHeadFlag == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addLeaderVertex(const DL_LeaderVertexData &data)
|
||||||
|
{
|
||||||
|
if(data.x == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addHatch(const DL_HatchData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfHatchs << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addHatchLoop(const DL_HatchLoopData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfHatchLoops << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addHatchEdge(const DL_HatchEdgeData &data)
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
dxfHatchEdges << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addImage(const DL_ImageData &data)
|
||||||
|
{
|
||||||
|
if(data.brightness == 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::linkImage(const DL_ImageDefData &data)
|
||||||
|
{
|
||||||
|
if(data.file == ""){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXRecord(const std::string &handle)
|
||||||
|
{
|
||||||
|
if(handle.length() <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXRecordString(int code, const std::string &value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value.length() <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXRecordReal(int code, double value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXRecordInt(int code, int value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXRecordBool(int code, bool value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXDataApp(const std::string &appId)
|
||||||
|
{
|
||||||
|
if(appId.length() <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXDataString(int code, const std::string &value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value.length() <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXDataReal(int code, double value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addXDataInt(int code, int value)
|
||||||
|
{
|
||||||
|
if(code <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDictionary(const DL_DictionaryData &data)
|
||||||
|
{
|
||||||
|
if(data.handle.length() <= 0){}
|
||||||
|
// qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addDictionaryEntry(const DL_DictionaryEntryData &data)
|
||||||
|
{
|
||||||
|
if(data.handle.length() <= 0){}
|
||||||
|
// qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::setVariableVector(const std::string &key, double v1, double v2, double v3, int code)
|
||||||
|
{
|
||||||
|
if(key.length() <= 0){}
|
||||||
|
if(v1 <= 0){}
|
||||||
|
if(v2 <= 0){}
|
||||||
|
if(v3 <= 0){}
|
||||||
|
if(code <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::setVariableString(const std::string &key, const std::string &value, int code)
|
||||||
|
{
|
||||||
|
if(key.length() <= 0){}
|
||||||
|
if(value.length() <= 0){}
|
||||||
|
if(code <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::setVariableInt(const std::string &key, int value, int code)
|
||||||
|
{
|
||||||
|
if(key.length() <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
if(code <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::setVariableDouble(const std::string &key, double value, int code)
|
||||||
|
{
|
||||||
|
if(key.length() <= 0){}
|
||||||
|
if(value <= 0){}
|
||||||
|
if(code <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::add3dFace(const DL_3dFaceData &data)
|
||||||
|
{
|
||||||
|
if(data.thickness <= 0){}
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::addComment(const std::string &comment)
|
||||||
|
{
|
||||||
|
if(comment.length() <= 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DxfReader::endSequence()
|
||||||
|
{
|
||||||
|
//qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
109
datafile/dxf/dxfreader.h
Normal file
109
datafile/dxf/dxfreader.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#ifndef DXFREADER_H
|
||||||
|
#define DXFREADER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include "dxflib/dl_dxf.h"
|
||||||
|
#include "dxflib/dl_creationadapter.h"
|
||||||
|
|
||||||
|
class DxfReader : public QObject, public DL_CreationAdapter
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
struct DxfText {
|
||||||
|
QString Text;
|
||||||
|
};
|
||||||
|
explicit DxfReader(const QString &fileName, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
virtual void addText(const DL_TextData& data) override;
|
||||||
|
virtual void addLine(const DL_LineData& data) override;
|
||||||
|
virtual void addArc(const DL_ArcData& data) override;
|
||||||
|
virtual void addCircle(const DL_CircleData& data) override;
|
||||||
|
virtual void addEllipse(const DL_EllipseData& data) override;
|
||||||
|
virtual void addPolyline(const DL_PolylineData& data) override;
|
||||||
|
virtual void addPoint(const DL_PointData& data) override;
|
||||||
|
virtual void addSpline(const DL_SplineData& data) override;
|
||||||
|
virtual void addBlock(const DL_BlockData& data) override;
|
||||||
|
virtual void endBlock() override;
|
||||||
|
|
||||||
|
virtual void addLayer(const DL_LayerData& data) override;
|
||||||
|
virtual void addLinetype(const DL_LinetypeData& data) override;
|
||||||
|
virtual void addLinetypeDash(double length) override;
|
||||||
|
virtual void addXLine(const DL_XLineData& data) override;
|
||||||
|
virtual void addRay(const DL_RayData& data) override;
|
||||||
|
virtual void addVertex(const DL_VertexData& data) override;
|
||||||
|
virtual void addControlPoint(const DL_ControlPointData& data) override;
|
||||||
|
virtual void addFitPoint(const DL_FitPointData& data) override;
|
||||||
|
virtual void addKnot(const DL_KnotData& data) override;
|
||||||
|
virtual void addInsert(const DL_InsertData& data) override;
|
||||||
|
virtual void addSolid(const DL_SolidData& data) override;
|
||||||
|
virtual void addTrace(const DL_TraceData& data) override;
|
||||||
|
virtual void addTextStyle(const DL_StyleData& data) override;
|
||||||
|
virtual void addMTextChunk(const std::string& text) override;
|
||||||
|
virtual void addMText(const DL_MTextData& data) override;
|
||||||
|
virtual void addArcAlignedText(const DL_ArcAlignedTextData& data) override;
|
||||||
|
virtual void addAttribute(const DL_AttributeData& data) override;
|
||||||
|
virtual void addDimAlign(const DL_DimensionData& data, const DL_DimAlignedData& edata) override;
|
||||||
|
virtual void addDimLinear(const DL_DimensionData& data, const DL_DimLinearData& edata) override;
|
||||||
|
virtual void addDimRadial(const DL_DimensionData& data, const DL_DimRadialData& edata) override;
|
||||||
|
virtual void addDimDiametric(const DL_DimensionData& data, const DL_DimDiametricData& edata) override;
|
||||||
|
virtual void addDimAngular(const DL_DimensionData& data, const DL_DimAngularData& edata) override;
|
||||||
|
virtual void addDimAngular3P(const DL_DimensionData& data, const DL_DimAngular3PData& edata) override;
|
||||||
|
virtual void addDimOrdinate(const DL_DimensionData& data, const DL_DimOrdinateData& edata) override;
|
||||||
|
virtual void addLeader(const DL_LeaderData &data) override;
|
||||||
|
virtual void addLeaderVertex(const DL_LeaderVertexData &data) override;
|
||||||
|
virtual void addHatch(const DL_HatchData& data) override;
|
||||||
|
virtual void addHatchLoop(const DL_HatchLoopData& data) override;
|
||||||
|
virtual void addHatchEdge(const DL_HatchEdgeData& data) override;
|
||||||
|
virtual void addImage(const DL_ImageData &data) override;
|
||||||
|
virtual void linkImage(const DL_ImageDefData &data) override;
|
||||||
|
|
||||||
|
virtual void addXRecord(const std::string& handle) override;
|
||||||
|
virtual void addXRecordString(int code, const std::string& value) override;
|
||||||
|
virtual void addXRecordReal(int code, double value) override;
|
||||||
|
virtual void addXRecordInt(int code, int value) override;
|
||||||
|
virtual void addXRecordBool(int code, bool value) override;
|
||||||
|
|
||||||
|
virtual void addXDataApp(const std::string& appId) override;
|
||||||
|
virtual void addXDataString(int code, const std::string& value) override;
|
||||||
|
virtual void addXDataReal(int code, double value) override;
|
||||||
|
virtual void addXDataInt(int code, int value) override;
|
||||||
|
|
||||||
|
virtual void addDictionary(const DL_DictionaryData& data) override;
|
||||||
|
virtual void addDictionaryEntry(const DL_DictionaryEntryData& data) override;
|
||||||
|
|
||||||
|
virtual void setVariableVector(const std::string& key, double v1, double v2, double v3, int code) override;
|
||||||
|
virtual void setVariableString(const std::string& key, const std::string& value, int code) override;
|
||||||
|
virtual void setVariableInt(const std::string& key, int value, int code) override;
|
||||||
|
virtual void setVariableDouble(const std::string& key, double value, int code) override;
|
||||||
|
|
||||||
|
virtual void add3dFace(const DL_3dFaceData &data) override;
|
||||||
|
virtual void addComment(const std::string &comment) override;
|
||||||
|
virtual void endSequence() override;
|
||||||
|
|
||||||
|
QList<DL_LineData> dxfLines;
|
||||||
|
QList<DL_TextData> dxfText;
|
||||||
|
QList<DL_ArcData> dxfArcs;
|
||||||
|
QList<DL_CircleData> dxfCircles;
|
||||||
|
QList<DL_EllipseData> dxfEllipses;
|
||||||
|
QList<DL_PolylineData> dxfPolylines;
|
||||||
|
QList<DL_PointData> dxfPoints;
|
||||||
|
QList<DL_SplineData> dxfSplines;
|
||||||
|
QList<DL_BlockData> dxfBlocks;
|
||||||
|
QList<DL_VertexData> dxfVertexs;
|
||||||
|
QList<DL_LayerData> dxfLayers;
|
||||||
|
QList<DL_LinetypeData> dxfLinetypes;
|
||||||
|
QList<DL_XLineData> dxfXLines;
|
||||||
|
QList<DL_RayData> dxfRays;
|
||||||
|
QList<DL_ControlPointData> dxfControlPoints;
|
||||||
|
QList<DL_FitPointData> dxfFitPoints;
|
||||||
|
QList<DL_HatchData> dxfHatchs;
|
||||||
|
QList<DL_HatchLoopData> dxfHatchLoops;
|
||||||
|
QList<DL_HatchEdgeData> dxfHatchEdges;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString fileName;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DXFREADER_H
|
||||||
10660
datafile/embdata.cpp
Normal file
10660
datafile/embdata.cpp
Normal file
File diff suppressed because it is too large
Load Diff
317
datafile/embdata.h
Normal file
317
datafile/embdata.h
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
#ifndef EMBDATA_H
|
||||||
|
#define EMBDATA_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QImage>
|
||||||
|
#include <qmath.h>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QRgb>
|
||||||
|
#include <QObject>
|
||||||
|
#include "machine/comm/datadef.h"
|
||||||
|
#include "machine/comm/crc16.h"
|
||||||
|
#include <QVector>
|
||||||
|
#include "datafile/datafiledsr.h"
|
||||||
|
|
||||||
|
#define ZERO 1e-6
|
||||||
|
|
||||||
|
#define MAX_EMB_STEP 121//四字节针步最大针步限制
|
||||||
|
#define DEFAULT_JUMP 70//默认针步大小
|
||||||
|
#define SEW_NEEDLE_NUM 2 //缝纫2个针杆
|
||||||
|
#define COLORTABLE_NUM 512//色序表
|
||||||
|
|
||||||
|
#define EMB_PREVIEW_SIDE (32) // 留边大小
|
||||||
|
#define TENTHOUSANDNEEDLE 100000
|
||||||
|
|
||||||
|
//#define EMB_SHOWDIRX (1) // X向显示坐标和数据坐标的差异
|
||||||
|
//#define EMB_SHOWDIRY (1) // Y向显示坐标和数据坐标的差异
|
||||||
|
#define OUTLINESTEPFACTOR 100 // 生成轮廓花样针步乘以的系数,单位是0.01,所以乘以100
|
||||||
|
|
||||||
|
#define PI10000 31416 //180度
|
||||||
|
#define PI20000 62832
|
||||||
|
#define ANGLECORR 10466 //60度对应的弧度值
|
||||||
|
|
||||||
|
#define MODE_THICKEN 0 //密针方式
|
||||||
|
#define MODE_LOCK 1 //锁针方式
|
||||||
|
|
||||||
|
#define NEEDLENONE 0 //无针
|
||||||
|
#define NEEDLELEFT 1 //左针
|
||||||
|
#define NEEDLERIGHT 2 //右针
|
||||||
|
#define NEEDLEDOUBLE 3 //双针
|
||||||
|
#define NEEDLENOTSET 4 //未设置
|
||||||
|
#define LAYOUTNEEDLENUM 24
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
u8 buf8[4];
|
||||||
|
u32 buf32;
|
||||||
|
} U32ToU8;
|
||||||
|
|
||||||
|
enum MirrorType {
|
||||||
|
HorizontalMirror = 1, // 1: 水平镜像
|
||||||
|
VerticalMirror, // 2: 垂直镜像
|
||||||
|
BothMirror // 3: 水平和垂直镜像
|
||||||
|
};
|
||||||
|
|
||||||
|
class EmbData: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
EmbData();
|
||||||
|
~EmbData();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clear();
|
||||||
|
QByteArray & getDsDat();//得到转换后的ds16数据
|
||||||
|
QByteArray getDispDat(double showWidth,double showHeight);//得到转换后的绘图数据
|
||||||
|
inline DataDs16FileHead * getDsDatHead(){return m_pEmbDs16Head;}//得到转换后的ds16数据的文件头
|
||||||
|
void setDsDatHeadFileID(u32 fileid);//设置数据区文件头的fileid
|
||||||
|
void getAbsDatRangeXY();//得到绝对坐标的maxXY和minXY
|
||||||
|
void appendAEmbAbsFile(QString filePath,QByteArray array,int mirror = 0);//附加一个绝对坐标的花样文件
|
||||||
|
int addLockStitchs(u8 mode, u8 needles, u8 num);
|
||||||
|
QByteArray lockReinforce(u8 needles, u8 num, DsAbsItem * absDataPtr, int datasize);//锁针加固方式
|
||||||
|
QByteArray thickenReinforce(u8 needles, u8 num, DsAbsItem * absDataPtr, int datasize);//密针加固方式
|
||||||
|
void addResew(QByteArray& data, DsAbsItem * ptr, u8 ctrl ,bool resewFlag = true);//加回针或者锁针
|
||||||
|
void evenNumberAddLock(QByteArray& data, DsAbsItem * absDataPtr,int lockNeedles, int num);//偶数次添加锁针加固
|
||||||
|
void oddNumberAddLock(QByteArray& data, DsAbsItem * absDataPtr,int lockNeedles, int num);//奇数次添加锁针加固
|
||||||
|
int angleCorrection(s16 oft);//角度修正
|
||||||
|
int angleCorrectionXY(s32 px, s32 nx, s32 py, s32 ny);//角度修正
|
||||||
|
void reFitByStep(s32 stepLen);//按固定针步重新拟合(用户可设置的参数,暂未用到)
|
||||||
|
void reFitLine(s32 stepLen);//按固定针步重新拟合直线(用户可设置的参数)
|
||||||
|
void reFitLineDoubleHead(s32 stepLen);//按固定针步重新拟合直线(用户可设置的参数),双头组合机型
|
||||||
|
int moveStartPoint(short left, short front);//移动起始点,左边,前边
|
||||||
|
QByteArray & lolaComp(s16 valuePos, s16 valueNeg, s16 valueZero);//罗拉补偿
|
||||||
|
void setLastStepAngle();//设置最后一个针步的角度
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline QString getFileName(){return m_pEmbDs16Head->fileName;}//得到花版名称
|
||||||
|
inline QString getFilePath(){return m_filePath;}//得到花版路径
|
||||||
|
inline u32 getStitchNums(){return m_pEmbDs16Head->itemNums;}//得到数据的针数
|
||||||
|
inline int getDatWidth(){return m_pEmbDs16Head->maxX - m_pEmbDs16Head->minX;}//得到数据的图形宽度
|
||||||
|
inline int getDatHeight(){return m_pEmbDs16Head->maxY - m_pEmbDs16Head->minY;}//得到数据的图形高度
|
||||||
|
inline s32 getMaxX(){return m_pEmbDs16Head->maxX;}//得到数据最大X+
|
||||||
|
inline s32 getMinX(){return m_pEmbDs16Head->minX;}//得到数据最小X-
|
||||||
|
inline s32 getMaxY(){return m_pEmbDs16Head->maxY;}//得到数据最大Y+
|
||||||
|
inline s32 getMinY(){return m_pEmbDs16Head->minY;}//得到数据最小Y-
|
||||||
|
inline s32 getBeginX(){if(m_pEmbDs16Head == NULL){return 0;} return m_pEmbDs16Head->beginX;}
|
||||||
|
inline s32 getBeginX2(){if(m_pEmbDs16Head == NULL){return 0;} return m_pEmbDs16Head->beginX2;}
|
||||||
|
inline s32 getBeginY(){if(m_pEmbDs16Head == NULL){return 0;} return m_pEmbDs16Head->beginY;}
|
||||||
|
inline s32 getBeginY2(){if(m_pEmbDs16Head == NULL){return 0;} return m_pEmbDs16Head->beginY2;}
|
||||||
|
inline s32 getAnchorX(){return m_pEmbDs16Head->anchorX;}//得到数据定位点
|
||||||
|
inline s32 getAnchorY(){return m_pEmbDs16Head->anchorY;}//得到数据定位点
|
||||||
|
|
||||||
|
inline void setSplitLen(u16 len){m_splitLen = len;}//分割数据长度
|
||||||
|
// inline int setSplitLen(u16 len){return len;}//分割数据长度
|
||||||
|
inline void setOftNeedleSize(s32 len){m_oftNeedleSize = len;}//双头组合机型去除偏移针步的针步大小
|
||||||
|
|
||||||
|
public:
|
||||||
|
void moveDataBeginPonit(s32 left, s32 front);
|
||||||
|
void setAbsDat(QByteArray & dat);
|
||||||
|
QByteArray & getAbsDat(void);
|
||||||
|
int getPosInfoFromNeedleIdx(int stitchIdx, int & posx, int & posy, int & colorIdx, int & dr, int & ar, int & dxV, int & dyV);
|
||||||
|
void setStartPosition(int x, int y);//设置起始点
|
||||||
|
void setStartPositionDoubleHead(int left,int front);//计算并设置起始点-双头组合机型
|
||||||
|
void setStartPositionFromLeftFront(int left,int front);//根据左边前边计算并设置起始点
|
||||||
|
void reCreatDispDat();//重新计算范围并生成绘制数据
|
||||||
|
void setAnchorPosition(int x, int y);//设置定位点
|
||||||
|
|
||||||
|
public:
|
||||||
|
double getAngle(double x1, double y1, double x2, double y2);
|
||||||
|
int setDatSizeChange(int dsx, int dsy);//设置尺寸变化(缩放)
|
||||||
|
int setMirror(MirrorType mirror);//设置镜像
|
||||||
|
|
||||||
|
int splittingArc(double posX1, double posY1,double posX2, double posY2,double xc, double yc, double rc,double dr1,double dr2,int step,QByteArray &cutData, DsAbsItem item);// 分割圆弧
|
||||||
|
int splittingLine(double posX1, double posY1,double posX2, double posY2,int stepMin, int stepMax,QByteArray &cutData, DsAbsItem item); // 分割直线
|
||||||
|
|
||||||
|
// 偏心刀平板切割机补偿算法
|
||||||
|
int setCutcontrastData(); // 增加对比数据
|
||||||
|
int setCutCornerStep(); // 增加拐点数据
|
||||||
|
int setCutEccentricCompensation(); // 偏心刀刀尖补偿
|
||||||
|
int setCutAddCutterComption(); // 增加两端补偿
|
||||||
|
int setCutRotaryCutterData(); // 增加转刀数据
|
||||||
|
int setCutDecCornerStep(); // 删除拐点数据
|
||||||
|
int setCutFitSplitStep(); // 分割切刀数据
|
||||||
|
int setCutFitStepData(); // 拟合切刀数据
|
||||||
|
|
||||||
|
// 飞行切割平板切割机补偿算法
|
||||||
|
int setCut2CornerStep(); // 增加拐点数据
|
||||||
|
int setCut2ModifyDataDir(); // 修改数据方向
|
||||||
|
int setCut2FitSplitStep(); // 分割切刀数据
|
||||||
|
int setCut2JudgInterval(); // 判断区间
|
||||||
|
int setCut2AddCutterComption(); // 增加圆刀数据两端补偿
|
||||||
|
int setCut2AddCutterComption2(); // 增加圆刀数据两端补偿 yct
|
||||||
|
int setCut2SortNewData(); // 排序&组成新数据
|
||||||
|
int setCut2AddOffsetData(); // 增加偏移数据
|
||||||
|
int setCut2CalMaxSpd(); // 计算最大行进速度
|
||||||
|
void recalculateAngles(); //重新计算角度
|
||||||
|
|
||||||
|
//计算角度ar
|
||||||
|
s32 calculateAngles(double curX, double curY, double lastX, double lastY); //计算绝对角度ar
|
||||||
|
//切割结尾补偿 移动结尾点
|
||||||
|
void cutDataEndCompensate(DsAbsItem &curItem,DsAbsItem &preItem,double comDistance);
|
||||||
|
//切割结尾小横切
|
||||||
|
void cutDataVertCut(DsAbsItem &curItem,double comDistance, QByteArray & cutAbsData,int &newstepnum);
|
||||||
|
//切割开头的补偿 移动起始点
|
||||||
|
void cutDataStartCompensate(DsAbsItem &curItem,DsAbsItem &preItem, DsAbsItem &nextItem, double comDistance);
|
||||||
|
|
||||||
|
bool isCutCtrl(u8 &ctrl);
|
||||||
|
|
||||||
|
void optimizationOrder(QVector<QVector<QByteArray> > &visited, DsAbsItem &absItem,int winNum,u8 ctrl);//数据优化顺序
|
||||||
|
|
||||||
|
u32 CalcDisplacement(u32 pps1, u32 pps2, u32 calcTime);
|
||||||
|
s16 Rot001ToPitk(s32 ang001);
|
||||||
|
int setCutMoveParameters(); // 计算切刀移动参数
|
||||||
|
|
||||||
|
int setRotate(int dr);//设置旋转
|
||||||
|
int setRotate90(bool flag);//旋转+-90度 flag :true代表顺时针方向
|
||||||
|
int getNextElementIndex(int curIndex);//获得下一个图元的第一缝纫针步
|
||||||
|
int getPreOrThisElementIndex(int curIndex);//上一个图元(当前为跨步时)或当前图元(当前为缝纫时)的第一缝纫针步
|
||||||
|
int createEmbDs16FromAbs();//生成DS16数据
|
||||||
|
int createEmbDs16FromAbsDoubleHeadComb();//双头组合机型生成ds16数据
|
||||||
|
void calRange();//计算边界范围
|
||||||
|
|
||||||
|
private:
|
||||||
|
void splitBorderStitchAndAdd(QByteArray & dat,int bx,int by,int ex,int ey);//分割边框针步并添加
|
||||||
|
//此函数转换传入的绝对坐标值,是否取镜像及反复时数据之间的间距
|
||||||
|
void convertAbsDat(QByteArray & dat,int mirror = 0);
|
||||||
|
int calcLine(double x0, double y0, double x1, double y1, s16 step, QByteArray &absAry, DsAbsItem item);
|
||||||
|
|
||||||
|
int reCalcDataChecksum();//重新计算文件CRC
|
||||||
|
void drawNeedleIdxPen(int x, int y, QPainter &painter);//绘制针数索引的跟踪笔
|
||||||
|
void drawFork(int x, int y, QPainter &painter);//绘制针数索引的十字
|
||||||
|
void drawFork(int x, int y, QPainter &painter,int index);//绘制针数索引的十字
|
||||||
|
void drawForkDoubleHead(int x, int y, int x2, int y2, QPainter &painter);//绘制针数索引的十字(双头组合机型)
|
||||||
|
void eraseNeedleIdxPen(QPainter &painter);//擦除针数索引的跟踪笔
|
||||||
|
void eraseNeedleIdxPen(QPainter &painter,int index);//擦除针数索引的跟踪笔
|
||||||
|
void eraseNeedleIdxPenDoubleHead(QPainter &painter);//擦除针数索引的跟踪笔
|
||||||
|
bool isFlipDispYMac();//判断是否是Y轴旋转的类型(显示数据)
|
||||||
|
bool isFlipDispXMac();//判断是否是X轴旋转的类型(显示数据)
|
||||||
|
private:
|
||||||
|
void getCurvePointFillLine(QList<DsAbsItem> &inList, double indRunLen,QList<DsAbsItem> &outList);
|
||||||
|
int getTotalDistanceFillLine(QList<DsAbsItem> *pPointList, double &dTotal);
|
||||||
|
bool getPointInSectFillLine(const DsAbsItem &p1, const DsAbsItem &p2, const double &d, DsAbsItem &outp);
|
||||||
|
//距p1点距离为d的点
|
||||||
|
// d > s : out_p在p2延长线上
|
||||||
|
// s >= d >= 0 : out_p在p1、p2线段上
|
||||||
|
// d < 0 : out_p在p1延长线上
|
||||||
|
bool getPointAtSect(const DsAbsItem &p1, const DsAbsItem &p2, const double &d, DsAbsItem &outp);
|
||||||
|
bool checkData(int size);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_editedflag;//数据被编辑的标志
|
||||||
|
int m_spaceX;//横向间隙
|
||||||
|
int m_spaceY;//纵向移动距离
|
||||||
|
|
||||||
|
int m_endPosX;//花样最后点坐标
|
||||||
|
int m_endPosY;//花样最后点坐标
|
||||||
|
|
||||||
|
//用于调节颜色
|
||||||
|
#if(1)
|
||||||
|
QString m_selfilename;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
double m_minX;
|
||||||
|
double m_maxX;
|
||||||
|
double m_minY;
|
||||||
|
double m_maxY;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QByteArray m_embAbsData; // 转换后的绝对坐标数据
|
||||||
|
QByteArray m_embDs16Data;//发给下位机的ds16数据(需要转换)
|
||||||
|
QByteArray m_oneDispDat; //飞梭机单个绘制数据
|
||||||
|
int m_totalJumpNeedle;//总跳针数
|
||||||
|
DataDs16FileHead * m_pEmbDs16Head;//ds16 文件头 //数据转换用的都是DataDs16FileHead
|
||||||
|
double m_factor;//绘制数据与实际数据的缩放率
|
||||||
|
u32 m_fileid;
|
||||||
|
u16 m_splitLen;
|
||||||
|
s32 m_oftNeedleSize;//双头组合机型去除偏移针步的针步大小
|
||||||
|
s32 m_ritStepSize;//拟合针步大小
|
||||||
|
|
||||||
|
//图形预览、刷新
|
||||||
|
public:
|
||||||
|
//显示所有线迹(原色显示)
|
||||||
|
//显示所有线迹(有效区域内的显示原色,其余显示灰色)
|
||||||
|
//显示所有线迹(执行过的显示原色,其余显示灰色)
|
||||||
|
//刷新部分线迹(缝纫中进度显示)
|
||||||
|
enum DISP_MODE {DISP_ALL_NORMAL = 0, DISP_ALL_AREA, DISP_ALL_EXEC, DISP_EXECING};
|
||||||
|
enum DRAW_MODE {DRAW_VIEW = 0, DRAW_PREVIEW};//绘制模式(非预览模式、预览模式)
|
||||||
|
|
||||||
|
public:
|
||||||
|
int setViewInfo(int width, int height);//设置视图尺寸(透明背景)
|
||||||
|
void setViewInfo(QPixmap pix);//设置视图(带背景图片背景)
|
||||||
|
void setEmbData(int type,int redraw = 0);//重置数据
|
||||||
|
//是否重绘 //是否为渐变
|
||||||
|
void setDispMode(DISP_MODE dispmode = DISP_ALL_NORMAL, int redraw = 0);//设置预览模式
|
||||||
|
void setDrawMode(DRAW_MODE drawmode = DRAW_VIEW);//设置绘制模式
|
||||||
|
|
||||||
|
void setExecIndex(int index);//设置进度显示数据
|
||||||
|
void reDraw();//重新绘图
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline QPixmap& getPreviewImage(){return m_canvas;}//返回预览图片
|
||||||
|
|
||||||
|
private:
|
||||||
|
int createDispFromEmbDs16Dat(QByteArray & ds16dat);//创建显示用的数据(为了快速显示)
|
||||||
|
int createDispFromEmbDs16DatForHeadInfo(QByteArray & ds16dat);
|
||||||
|
int createDispFromEmbDs16DatDoubleHeadComb(QByteArray & ds16dat);//双头组合机型创建绘制数据
|
||||||
|
int drawImageByDispFile();//用显示数据画图(是否渐变显示)
|
||||||
|
int drawImageByOneStepLotLine();
|
||||||
|
int drawImageByDispFileDoubleHeadComb();//双头组合机型绘制预览图
|
||||||
|
int findMaxSpHead(DsrHeadEx62 & head,int headCount);
|
||||||
|
void drawMultiTrack(QPainter &painter); //绘制多机头的跟踪图案
|
||||||
|
void drawMultiLine(QPainter &painter, QPen &pen, QRgb rgb, int index); //绘制多机头的线迹
|
||||||
|
|
||||||
|
public:
|
||||||
|
void getOneDispDat(QByteArray &ds16dat); //得到一个绘制数据
|
||||||
|
void resetLayoutDispDat(unsigned char *arrayNeedle1,unsigned char *arrayNeedle2,unsigned char *arrayNeedle3,int leftRightNeedleSpace,int needlesSpace,int needleLayoutSpace12,int needleLayoutSpace23,int reDat = 0);
|
||||||
|
int createDispFromEmbDs16DatForFlyShuttle(int initFlag = 0);//飞梭机绘制数据
|
||||||
|
|
||||||
|
static bool checkFirstEndNeedle(QByteArray ary);//确认起终点的x值是否一致
|
||||||
|
QByteArray rotationAngleAdjustment(int flag);//根据flag对数据进行旋转角度调整
|
||||||
|
private:
|
||||||
|
int m_type; //机型
|
||||||
|
int m_penX, m_penY;//执行过程中绘制跟踪笔的坐标索引
|
||||||
|
QPoint m_penXY2;
|
||||||
|
|
||||||
|
QPixmap m_canvas;//预览图片
|
||||||
|
QPixmap m_penPix;//跟踪笔绘制的临时区域
|
||||||
|
QPixmap m_penPix2;//跟踪笔绘制的临时区域
|
||||||
|
QVector<QPixmap> m_penHeadPix;
|
||||||
|
QVector<QPoint> m_penPoint;
|
||||||
|
|
||||||
|
int m_viewWidth;
|
||||||
|
int m_viewHight;
|
||||||
|
|
||||||
|
QString m_filePath;//文件路径
|
||||||
|
|
||||||
|
private:
|
||||||
|
QByteArray m_dispDat;//绘制图形的绝对数据(进行缩放的)
|
||||||
|
|
||||||
|
QByteArray m_dispDatFront;//飞梭机前排数据
|
||||||
|
QByteArray m_dispDatMiddle;//飞梭机中排数据
|
||||||
|
QByteArray m_dispDatBehind;//飞梭机后排数据
|
||||||
|
|
||||||
|
double m_dispMinX;
|
||||||
|
double m_dispMaxX;
|
||||||
|
double m_dispMinY;
|
||||||
|
double m_dispMaxY;
|
||||||
|
|
||||||
|
QVector<Disp_HeadItem> m_headDispDate; //五头机绘图针步
|
||||||
|
int m_stitchIndex; //进度步数
|
||||||
|
int m_dispIndex; //当前index
|
||||||
|
DISP_MODE m_dispMode;
|
||||||
|
DRAW_MODE m_drawMode;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void siDrawNeedleIdx(int idx);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EMBDATA_H
|
||||||
2535
datafile/hpgl/importhpgl.cpp
Normal file
2535
datafile/hpgl/importhpgl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
323
datafile/hpgl/importhpgl.h
Normal file
323
datafile/hpgl/importhpgl.h
Normal file
@ -0,0 +1,323 @@
|
|||||||
|
#ifndef IMPORTHPGL_H
|
||||||
|
#define IMPORTHPGL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QBitmap>
|
||||||
|
#include <qtextcodec.h>
|
||||||
|
#include "marker.h"
|
||||||
|
#include "machine/comm/config.h"
|
||||||
|
#include "machine/comm/datadef.h"
|
||||||
|
#include "machine/comm/crc16.h"
|
||||||
|
|
||||||
|
#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
|
||||||
|
#define DEFCMD_PU 0xB5 //PU 单个PU
|
||||||
|
#define DEFCMD_PD 0x3D //PD 单个PD
|
||||||
|
#define DEFCMD_LPU 0x5E //PU 连续PU
|
||||||
|
#define DEFCMD_LPD 0x3B //PD 连续PD
|
||||||
|
#define DEFCMD_DI 0x5B //AG 角度
|
||||||
|
#define DEFCMD_SI 0x5D //SI 64位双精度浮点
|
||||||
|
#define DEFCMD_FN 0x4B //FN 字体名
|
||||||
|
#define DEFCMD_LB 0x4D //LB
|
||||||
|
#define DEFCMD_BT 0x9A //BIT 位图
|
||||||
|
#define DEFCMD_CODE 0xE7 //CODE 条形码、二维码
|
||||||
|
#define DEFCMD_NULL 0x00 //NUll 空指令
|
||||||
|
#define DEFCMD_DRILL 0xD2 //DRILL 冲孔
|
||||||
|
#define DEFCMD_NOTCH 0xD3 //NOTCH 剪口
|
||||||
|
|
||||||
|
#define M_IDPMM 40.0
|
||||||
|
#define MMPIXELY 7.936508
|
||||||
|
|
||||||
|
#define PREVIEW_SIDE (10)
|
||||||
|
#define PREVIEW_WIDTH (240)
|
||||||
|
#define PREVIEW_HEIGHT (240)
|
||||||
|
|
||||||
|
#define WIDTHBYTES(bits) (((bits)+31)/32*4)
|
||||||
|
|
||||||
|
#define PixelFormatIndexed 0x00010000 // Indexes into a palette
|
||||||
|
#define PixelFormatGDI 0x00020000 // Is a GDI-supported format
|
||||||
|
#define PixelFormat1bppIndexed (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI)
|
||||||
|
|
||||||
|
#define PLT_PREVIEW_SIDE (15) // 留边大小
|
||||||
|
#define PLT_PREVIEW_WIDTH (156) // 默认预览图区域宽度
|
||||||
|
#define PLT_PREVIEW_HEIGHT (164) // 默认预览图区域高度
|
||||||
|
|
||||||
|
#define PLT_EMB_DATADIRX (1) // X向数据坐标与下位机坐标系统的差异
|
||||||
|
#define PLT_EMB_DATADIRY (-1) // Y向数据坐标与下位机坐标系统的差异
|
||||||
|
#define PLT_EMB_DATADIRR (1) // R向数据坐标与下位机坐标系统的差异
|
||||||
|
#define PLT_EMB_DATASCALE 100 // plt数据转为下位机数据需要扩大10倍,因为下位机单位为0.01mm
|
||||||
|
|
||||||
|
#define PLT_SHOWDIRX (1) // X向显示坐标和数据坐标的差异
|
||||||
|
#define PLT_SHOWDIRY (-1) // Y向显示坐标和数据坐标的差异
|
||||||
|
|
||||||
|
struct SC
|
||||||
|
{
|
||||||
|
double dXMin;
|
||||||
|
double dXMax;
|
||||||
|
double dYMin;
|
||||||
|
double dYMax;
|
||||||
|
int nType;
|
||||||
|
double dLeft;
|
||||||
|
double dBottom;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PLT_Head
|
||||||
|
{
|
||||||
|
char keyStr[3];
|
||||||
|
u16 pressureHigh1;
|
||||||
|
u16 pressureHigh2;
|
||||||
|
u16 pressureHigh3;
|
||||||
|
u16 pressureHigh4;
|
||||||
|
u16 pressureHigh5;
|
||||||
|
u16 pressureHigh6;
|
||||||
|
u16 pressureHigh7;
|
||||||
|
u16 pressureHigh8;
|
||||||
|
u16 pressureHigh9;
|
||||||
|
u16 pressureHigh10;
|
||||||
|
u16 pressureHigh11;
|
||||||
|
u16 pressureHigh12;
|
||||||
|
u16 pressureHigh13;
|
||||||
|
u16 pressureHigh14;
|
||||||
|
u16 pressureHigh15;
|
||||||
|
u16 pressureHigh16;
|
||||||
|
s32 anchorX;
|
||||||
|
s32 anchorY;
|
||||||
|
char endStr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ImportHPGL : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ImportHPGL(QObject *parent = 0);
|
||||||
|
virtual ~ImportHPGL();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline const QString & getFileFullPathName() const {return m_fileFullPathName;} // 文件路径名称
|
||||||
|
|
||||||
|
//获得QR二维码版本
|
||||||
|
//输入参数:nCount 字符个数
|
||||||
|
//返回参数:QR二维码版本
|
||||||
|
int GetQRVesion(int nCount);
|
||||||
|
|
||||||
|
//样点旋转
|
||||||
|
//输入参数:
|
||||||
|
// ptPoint被旋转点,ptPointO旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦
|
||||||
|
//输出参数:
|
||||||
|
// ptPoint旋转后的值
|
||||||
|
void PointRotate(QPoint &ptPoint,QPoint ptPointO,double dSinBeta,double dCosBeta);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//分析S指令
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// bEndOfFile =true 已到文件尾
|
||||||
|
//返回值:
|
||||||
|
// true 正确的G指令
|
||||||
|
// false 不正确的G指令
|
||||||
|
bool S_Code();
|
||||||
|
bool I_Code();
|
||||||
|
bool P_Code();
|
||||||
|
bool PU_Code();
|
||||||
|
bool PD_Code();
|
||||||
|
bool L_Code();
|
||||||
|
bool D_Code();
|
||||||
|
bool SC_Code();
|
||||||
|
bool C_Code();
|
||||||
|
|
||||||
|
//读取一个字符
|
||||||
|
//输出参数:
|
||||||
|
// *pChar 读取的字符
|
||||||
|
//返回值:
|
||||||
|
// 1 成功取得一个字符
|
||||||
|
// 0 失败
|
||||||
|
uint ReadChar(char* lpBuf);
|
||||||
|
|
||||||
|
//读取一个非空格、非回车、非换行的字符
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// *pChar 读取的字符
|
||||||
|
//返回值:
|
||||||
|
// true 成功取得一个字符
|
||||||
|
// false 失败
|
||||||
|
bool GetChar(char *pChar);
|
||||||
|
//判断下一个非空格、非回车、非换行的字符是不是','
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//返回值:
|
||||||
|
// true 下一个非空格、非回车、非换行的字符是',', 并且已将','从文件中读出
|
||||||
|
// false 下一个非空格、非回车、非换行的字符不是',', 并且该字符没有从文件中读出
|
||||||
|
bool NextCharIsComma();
|
||||||
|
|
||||||
|
//取一个双精度浮点数
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// dValue 取得的双精度浮点数
|
||||||
|
//返回值:
|
||||||
|
// true 成功取得一个双精度浮点数dValue
|
||||||
|
// false 失败
|
||||||
|
bool GetDoubleData(double &dValue);
|
||||||
|
|
||||||
|
//取一个整数
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// iValue 取得的整数
|
||||||
|
//返回值:
|
||||||
|
// true 成功取得一个整数iValue
|
||||||
|
// false 失败
|
||||||
|
bool GetIntegerData(int &iValue);
|
||||||
|
|
||||||
|
//取坐标值
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// ptPoint 坐标
|
||||||
|
//返回值:
|
||||||
|
// true 成功
|
||||||
|
// false 失败
|
||||||
|
bool GetCoordinate(QPoint &ptPoint);
|
||||||
|
|
||||||
|
//获得线的类型
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// lineType 线型
|
||||||
|
//返回值:
|
||||||
|
// true 成功
|
||||||
|
// false 失败
|
||||||
|
bool GetLineType(LineType &lineType);
|
||||||
|
|
||||||
|
//查找一个指定的字符
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
// cFind 指定的字符
|
||||||
|
//输出参数:
|
||||||
|
// strInfo 从开始位置到指定字符之前的内容(不包括最后的指定字符)
|
||||||
|
//返回值:
|
||||||
|
// true 成功取得一个字符
|
||||||
|
// false 失败
|
||||||
|
bool SearchChar(char cFind,QString &strInfo);
|
||||||
|
|
||||||
|
//将文件的读取位置移到下一个英文字母(26个英文字母)
|
||||||
|
//输入参数:
|
||||||
|
// pFile 切割数据文件
|
||||||
|
//输出参数:
|
||||||
|
// *pChar 读取的字符
|
||||||
|
//返回值:
|
||||||
|
// true 成功将文件的读取位置移到下一个英文字母
|
||||||
|
// false 失败
|
||||||
|
bool MoveToNextEnglishChar();
|
||||||
|
|
||||||
|
//将m_listXY加入到m_pMarker中,并将m_listXY清空
|
||||||
|
void AddPolylineToMarker();
|
||||||
|
|
||||||
|
void AddPoint2listXY(QPoint ptPoint);
|
||||||
|
|
||||||
|
QString m_fileFullPathName; //文件名称
|
||||||
|
int m_iDPMM; //长度数据单位:m_iDPMM(每毫米点)
|
||||||
|
int m_iPenNo; //当前的笔号
|
||||||
|
QPoint m_ptCurrentPos; //笔的当前位置,单位:(1/CMarker::m_iDPMM)毫米
|
||||||
|
LineType m_lineType;//当前线型
|
||||||
|
bool m_bPenUp;//当前刀具的状态 true:刀具状态为抬起 false:刀具状态为落下
|
||||||
|
bool m_bPage;//是否识别到PG指令
|
||||||
|
|
||||||
|
Marker *m_pMarker; //当前使用的唛架,仅能在读文件时使用
|
||||||
|
double m_dScale; //读入文件时将切割数据文件的单位转换成内部数据单位时的比例
|
||||||
|
QPen m_penPen;//笔绘画笔
|
||||||
|
QPen m_cutPen;//切割画笔
|
||||||
|
QPen m_halfCutPen;//半透切割画笔
|
||||||
|
|
||||||
|
QList <QPoint> m_listXY; //还没有确定抬落刀的坐标
|
||||||
|
//QPainterPath m_polylinePainterPath;//绘图路径-线段
|
||||||
|
|
||||||
|
unsigned char m_chTerminator;//标志终结符,除了NULL LF ESC及;十进制分别为0,5,27,59;外的所有字符,默认为ETX 十进制3
|
||||||
|
int m_nTerminatorMode;//模式0:打印1:不打印 默认值为1
|
||||||
|
|
||||||
|
double m_dTextHeight;//字的高度 单位cm
|
||||||
|
double m_dTextWidth;//字的宽度 单位cm
|
||||||
|
int m_nLableOrigin;//字符串相对于原点位置
|
||||||
|
double m_dTextAngle;//指定每行文本输出时相对于设备x轴的角度,其单位为1/10度
|
||||||
|
QPoint m_ptP1;//解析IP指令中的坐标点
|
||||||
|
QPoint m_ptP2;//解析IP指令中的坐标点
|
||||||
|
SC m_sc;//解析SC指令
|
||||||
|
double m_dScaleX;//通过 IP和SC指令算出的缩放比例
|
||||||
|
double m_dScaleY;//通过 IP和SC指令算出的缩放比例
|
||||||
|
QPoint m_ptOrigin;//通过 IP和SC指令算出的原点
|
||||||
|
int m_nLength;//用于PG分页,记录累计长度
|
||||||
|
char* m_pFileBuf;//存放从文件中读取的全部字符
|
||||||
|
int m_nCharCount;//已经读取的字符个数
|
||||||
|
int m_nFileLength;//文件长度
|
||||||
|
QString m_workPath;
|
||||||
|
|
||||||
|
bool m_bFontItalic; //文字斜体
|
||||||
|
int m_iFontSize; //字体榜数
|
||||||
|
QString m_strFontName;//字体名称
|
||||||
|
|
||||||
|
bool HFD_Code();//设置头文件
|
||||||
|
private:
|
||||||
|
QByteArray m_embAbsData; // 转换后的绝对坐标数据
|
||||||
|
int m_minX;
|
||||||
|
int m_maxX;
|
||||||
|
int m_minY;
|
||||||
|
int m_maxY;
|
||||||
|
u8 m_stepCtrl;
|
||||||
|
PLT_Head m_headData;// 头文件数据
|
||||||
|
|
||||||
|
public:
|
||||||
|
//输入参数:
|
||||||
|
// pFile 需要读入的RS274D文件
|
||||||
|
// pMarker 解析到的数据保存到此唛架
|
||||||
|
//返回值:
|
||||||
|
// true 读入文件成功
|
||||||
|
// false 读入文件失败
|
||||||
|
bool Read(QString strPathName);
|
||||||
|
bool Write(QString strPathName,Marker *pMarker);
|
||||||
|
int createPreviewImage(QImage * pImg = NULL, int saveflag = 0, int penwidth = 1, int reDraw = 0); // 生成预览文件
|
||||||
|
void convertDataToEmbAbs(); // 转换为绝对数据
|
||||||
|
void setStepCtrl(u8 ctrl);//设置针步属性
|
||||||
|
QByteArray getEmbAbsData(); // 得到转换后的数据
|
||||||
|
|
||||||
|
//void creatPolylinePainterPath();//获得文件图形的范围
|
||||||
|
//QPainterPath GetPolylinePainterPath();
|
||||||
|
|
||||||
|
//初始化参数,读取参数前,需将参数值重置,避免造成参数值读取错误
|
||||||
|
void IniPara();
|
||||||
|
|
||||||
|
QPoint GetTextOrigin(QPoint pt,QString strText);
|
||||||
|
double GetTextAngle(double dX,double dY);
|
||||||
|
void SetScale();
|
||||||
|
bool IsSecretFile(QString strPatnName);
|
||||||
|
int BitMapDtat(QString strFileName,QString strSecretFile);
|
||||||
|
bool ReadSecretFile(QString stePathName); // 打开位图文件
|
||||||
|
|
||||||
|
bool setPltHead(PLT_Head head, QString path);
|
||||||
|
PLT_Head getPltHead();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
//输入参数:
|
||||||
|
// bUp 刀的状态,true:抬起状态 false:落下状态
|
||||||
|
// ptPoint 矢量字体中点阵中的一个坐标
|
||||||
|
void AddTextPointToLine(bool bUp,QPoint ptPoint);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // IMPORTHPGL_H
|
||||||
262
datafile/hpgl/marker.cpp
Normal file
262
datafile/hpgl/marker.cpp
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
#include "marker.h"
|
||||||
|
|
||||||
|
Marker::Marker(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_iDPMM = 40;
|
||||||
|
m_listPolyline.clear();
|
||||||
|
m_nProducts = 0;
|
||||||
|
m_nActualMatchRegions = 0;
|
||||||
|
m_nMatchRegions = 0;
|
||||||
|
m_strProductCode = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Marker::~Marker()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Marker::Marker(const Marker &a): QObject()
|
||||||
|
{
|
||||||
|
m_iDPMM = a.m_iDPMM;
|
||||||
|
m_listPolyline.clear();
|
||||||
|
m_listPolyline.append(a.m_listPolyline);
|
||||||
|
m_nProducts = a.m_nProducts;
|
||||||
|
m_nActualMatchRegions = a.m_nActualMatchRegions;
|
||||||
|
m_nMatchRegions = a.m_nMatchRegions;
|
||||||
|
m_strProductCode = a.m_strProductCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Marker Marker::operator=(const Marker &a)
|
||||||
|
{
|
||||||
|
m_iDPMM = a.m_iDPMM;
|
||||||
|
m_listPolyline.clear();
|
||||||
|
m_listPolyline.append(a.m_listPolyline);
|
||||||
|
m_nProducts = a.m_nProducts;
|
||||||
|
m_nActualMatchRegions = a.m_nActualMatchRegions;
|
||||||
|
m_nMatchRegions = a.m_nMatchRegions;
|
||||||
|
m_strProductCode = a.m_strProductCode;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Marker::Initialize()
|
||||||
|
{
|
||||||
|
m_iDPMM = 40;
|
||||||
|
m_listPolyline.clear();
|
||||||
|
m_nProducts = 0;
|
||||||
|
m_nActualMatchRegions = 0;
|
||||||
|
m_nMatchRegions = 0;
|
||||||
|
m_strProductCode = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
QRect Marker::GetRect()
|
||||||
|
{
|
||||||
|
QRect rect;
|
||||||
|
|
||||||
|
CRPPolyline RPPolyline;
|
||||||
|
rect.setRect(0,0,0,0);
|
||||||
|
|
||||||
|
for(int i = 0; i < m_listPolyline.size(); i++)
|
||||||
|
{
|
||||||
|
RPPolyline = m_listPolyline.at(i);
|
||||||
|
if (RPPolyline.m_nDrawingType == 0)
|
||||||
|
{
|
||||||
|
rect |= RectofPolyline(RPPolyline.m_listPoint);
|
||||||
|
}
|
||||||
|
else if (RPPolyline.m_nDrawingType == 3)
|
||||||
|
{
|
||||||
|
rect |= QRect(RPPolyline.m_text.m_ptPostLU,RPPolyline.m_text.m_ptPostRD);
|
||||||
|
}
|
||||||
|
else if (RPPolyline.m_nDrawingType == 1)
|
||||||
|
{
|
||||||
|
rect |= QRect(RPPolyline.m_bitmapInfo.m_ptAbPostLU,RPPolyline.m_bitmapInfo.m_ptAbPostRD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRect Marker::RectofPolyline(const QList<QPoint> &listPoint)
|
||||||
|
{
|
||||||
|
if(listPoint.empty())
|
||||||
|
{
|
||||||
|
return QRect(0,0,0,0);
|
||||||
|
}
|
||||||
|
int iXMin = INT_MAX;
|
||||||
|
int iXMax = INT_MIN;
|
||||||
|
int iYMin = INT_MAX;
|
||||||
|
int iYMax = INT_MIN;
|
||||||
|
|
||||||
|
int iValueX;
|
||||||
|
int iValueY;
|
||||||
|
|
||||||
|
int iPointCount = listPoint.size();
|
||||||
|
for(int i = 0 ;i < iPointCount; i++)
|
||||||
|
{
|
||||||
|
iValueX = listPoint.at(i).x();
|
||||||
|
iValueY = listPoint.at(i).y();
|
||||||
|
|
||||||
|
if( iValueX > iXMax )
|
||||||
|
{
|
||||||
|
iXMax = iValueX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(iValueX < iXMin )
|
||||||
|
{
|
||||||
|
iXMin = iValueX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( iValueY > iYMax )
|
||||||
|
{
|
||||||
|
iYMax = iValueY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(iValueY < iYMin )
|
||||||
|
{
|
||||||
|
iYMin = iValueY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QRect(QPoint(iXMin,iYMin),QPoint(iXMax,iYMax));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double CNotch::angle_2(int startx, int starty, int endx, int endy)
|
||||||
|
{
|
||||||
|
//直线与X轴之间的夹角 X轴向量OE(1,0)
|
||||||
|
double dAngle = 0;
|
||||||
|
if((endx == startx) && (endy == starty))
|
||||||
|
{
|
||||||
|
return dAngle;
|
||||||
|
}
|
||||||
|
//求直线的向量坐标
|
||||||
|
double dX = endx - startx;
|
||||||
|
double dY = endy - starty;
|
||||||
|
dAngle = qAcos((dX)/(qSqrt(dX*dX + dY*dY)));
|
||||||
|
return dAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNotch::CovertToOutputByOffset(int nOffSetX, int nOffsetY)
|
||||||
|
{
|
||||||
|
double a = 0;
|
||||||
|
double b = 0;
|
||||||
|
double c = 0;
|
||||||
|
//范围在[0,2pi)之间
|
||||||
|
double dAngle = angle_2(m_ptStart.x(),m_ptStart.y(),m_ptEnd.x(),m_ptEnd.y());
|
||||||
|
m_nAngle = dAngle*180.0/CONST_PI*100.0 + 0.5;
|
||||||
|
//double dX = m_ptEnd.x - m_ptStart.x;
|
||||||
|
//double dY = m_ptEnd.y - m_ptStart.y;
|
||||||
|
//double dLen = sqrt(dX*dX + dY*dY);
|
||||||
|
//m_ptCorrect.x = nOffSetY/dLen * dX + m_ptStart.x;
|
||||||
|
//m_ptCorrect.y = nOffsetY/dLen * dY + m_ptStart.y;
|
||||||
|
QPoint ptY;
|
||||||
|
ptY.setX(nOffsetY*cos(dAngle) + m_ptStart.x() + 0.5);
|
||||||
|
ptY.setY(nOffsetY*sin(dAngle) + m_ptStart.y() + 0.5);
|
||||||
|
|
||||||
|
if (nOffSetX == 0)
|
||||||
|
{
|
||||||
|
m_ptCorrect.setX(ptY.x());
|
||||||
|
m_ptCorrect.setY(ptY.y());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nX = m_ptEnd.x() - m_ptStart.x();
|
||||||
|
int nY = m_ptEnd.y() - m_ptStart.y();
|
||||||
|
|
||||||
|
if (nX == 0)
|
||||||
|
{
|
||||||
|
a = 0;
|
||||||
|
b = 1;
|
||||||
|
c = -ptY.y();
|
||||||
|
}
|
||||||
|
if (nY == 0)
|
||||||
|
{
|
||||||
|
a = 1;
|
||||||
|
b = 0;
|
||||||
|
c = -ptY.x();
|
||||||
|
}
|
||||||
|
|
||||||
|
double k = double(m_ptStart.x() - m_ptEnd.x())/double(m_ptEnd.y() - m_ptStart.y());
|
||||||
|
c = ptY.y() - k*ptY.x();
|
||||||
|
a = k;
|
||||||
|
b = -1;
|
||||||
|
int nRadius = abs(nOffSetX);
|
||||||
|
QPoint ptInter1;
|
||||||
|
QPoint ptInter2;
|
||||||
|
if (IntOfLineCircle(a,b,c,ptY.x(),ptY.y(),nRadius,ptInter1,ptInter2) == 2)
|
||||||
|
{
|
||||||
|
//向量
|
||||||
|
int nYv = ptInter1.y() - ptY.y();
|
||||||
|
int nXv = ptInter1.x() - ptY.x();
|
||||||
|
//判断该点在起点到终点连线的哪一侧?>0 右侧
|
||||||
|
if((nXv*nY -nYv*nX)>0)
|
||||||
|
{
|
||||||
|
if (nOffSetX > 0)//右侧
|
||||||
|
{
|
||||||
|
m_ptCorrect.setX(ptInter1.x());
|
||||||
|
m_ptCorrect.setY(ptInter1.y());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_ptCorrect.setX(ptInter2.x());
|
||||||
|
m_ptCorrect.setY(ptInter2.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (nOffSetX < 0)//左侧
|
||||||
|
{
|
||||||
|
m_ptCorrect.setX(ptInter1.x());
|
||||||
|
m_ptCorrect.setY(ptInter1.y());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_ptCorrect.setX(ptInter2.x());
|
||||||
|
m_ptCorrect.setY(ptInter2.y());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CNotch::IntOfLineCircle(double a, double b, double c, int xc, int yc, int nR, QPoint &lpptIntersection1, QPoint &lpptIntersection2)
|
||||||
|
{
|
||||||
|
//点:(x0,y0)
|
||||||
|
//线:Ax+By+C=0
|
||||||
|
//①距离=ABS(A*x0+B*y0+C) / SQRT(A*A+B*B)
|
||||||
|
double dis = 0;
|
||||||
|
dis = abs(a*xc+b*yc+c)/sqrt(a*a+b*b);
|
||||||
|
|
||||||
|
int rel = 0;
|
||||||
|
if(dis < nR)
|
||||||
|
{
|
||||||
|
rel = 0;
|
||||||
|
}
|
||||||
|
else if(dis == nR)
|
||||||
|
{
|
||||||
|
rel = 1;
|
||||||
|
}
|
||||||
|
else if(dis > nR)
|
||||||
|
{
|
||||||
|
double k = -a/b;
|
||||||
|
double b1 = 2*xc-2*k*(b-yc);
|
||||||
|
double sval = (b1/100.0)*(b1/100.0)*10000.0-4*a*c;
|
||||||
|
if(sval < 0)
|
||||||
|
{
|
||||||
|
qDebug()<<sval;
|
||||||
|
}
|
||||||
|
double tmp = sqrt(sval);
|
||||||
|
double x1 = (b1+tmp)/(2*a);
|
||||||
|
double y1 = k*x1+b;
|
||||||
|
double x2 = (b1-tmp)/(2*a);
|
||||||
|
double y2 = k*x2+b;
|
||||||
|
|
||||||
|
lpptIntersection1.setX(x1);
|
||||||
|
lpptIntersection1.setY(y1);
|
||||||
|
|
||||||
|
lpptIntersection2.setX(x2);
|
||||||
|
lpptIntersection2.setY(y2);
|
||||||
|
|
||||||
|
rel = 2;
|
||||||
|
}
|
||||||
|
return rel;
|
||||||
|
}
|
||||||
418
datafile/hpgl/marker.h
Normal file
418
datafile/hpgl/marker.h
Normal file
@ -0,0 +1,418 @@
|
|||||||
|
#ifndef MARKER_H
|
||||||
|
#define MARKER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPoint>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QBitmap>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <qmath.h>
|
||||||
|
|
||||||
|
#define CONST_PI 3.14159265359
|
||||||
|
|
||||||
|
struct LineType
|
||||||
|
{
|
||||||
|
//具体参照HPGL英文版手册216页 当LT没有设置值时,线型为实线
|
||||||
|
bool bDefault;//LT是否设置值
|
||||||
|
int nLinetype;//线型 取值为-8~8 ,99 =0 实线 =1 虚线
|
||||||
|
int nPatternLength;//图案长度 缺省为P1、P2距离的4%
|
||||||
|
int nMode;//0相对模式 缺省值 解释为P1、P2距离的百分比 1绝对模式,以毫米解释图案长度
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CBitmapInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//原始读取的的坐标
|
||||||
|
QPoint m_ptPostLU; //位图的左上角在整个图中的XY位置
|
||||||
|
QPoint m_ptPostLD; //位图的左下角在整个图中的XY位置
|
||||||
|
QPoint m_ptPostRU; //位图的右上角在整个图中的XY位置
|
||||||
|
QPoint m_ptPostRD; //位图的右下角在整个图中的XY位置
|
||||||
|
|
||||||
|
//换算后的坐标
|
||||||
|
QPoint m_ptAbPostLU; //位图的左上角在整个图中的XY位置
|
||||||
|
QPoint m_ptAbPostLD; //位图的左下角在整个图中的XY位置
|
||||||
|
QPoint m_ptAbPostRU; //位图的右上角在整个图中的XY位置
|
||||||
|
QPoint m_ptAbPostRD; //位图的右下角在整个图中的XY位置
|
||||||
|
|
||||||
|
int m_iTransparent;//为1时则为透明显示; 为0则为非透明显示
|
||||||
|
int m_iBKColor;//背景颜色(在透明显示时背景颜色的点将不被显示)
|
||||||
|
|
||||||
|
int m_iWidth;// GDI+中BitmapData的Width,单位:像素
|
||||||
|
int m_iHeight;//GDI+中BitmapData的Height,单位:像素
|
||||||
|
int m_iStride;//GDI+中BitmapData的Stride(每行的字节数)
|
||||||
|
int m_iPixelFormat;//GDI+中BitmapData的PixelFormat
|
||||||
|
|
||||||
|
int m_iBytes;//int压缩后位图数据大小(字节数)
|
||||||
|
QBitmap m_pBitmap;//位图数据(压缩后的位图数据)
|
||||||
|
|
||||||
|
CBitmapInfo()
|
||||||
|
{
|
||||||
|
m_ptPostLU = QPoint(0,0);
|
||||||
|
m_ptPostLD = QPoint(0,0);
|
||||||
|
m_ptPostRU = QPoint(0,0);
|
||||||
|
m_ptPostRD = QPoint(0,0);
|
||||||
|
m_ptAbPostLU = QPoint(0,0);
|
||||||
|
m_ptAbPostLD = QPoint(0,0);
|
||||||
|
m_ptAbPostRU = QPoint(0,0);
|
||||||
|
m_ptAbPostRD = QPoint(0,0);
|
||||||
|
m_iTransparent = 0;
|
||||||
|
m_iBKColor = 0;
|
||||||
|
m_iWidth = 0;
|
||||||
|
m_iHeight = 0;
|
||||||
|
m_iStride = 0;
|
||||||
|
m_iPixelFormat = 1;
|
||||||
|
m_iBytes = 0;
|
||||||
|
//m_pBitmap = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
~CBitmapInfo() {}
|
||||||
|
CBitmapInfo operator=(const CBitmapInfo &a)
|
||||||
|
{
|
||||||
|
m_ptPostLU = a.m_ptPostLU;
|
||||||
|
m_ptPostLD = a.m_ptPostLD;
|
||||||
|
m_ptPostRU = a.m_ptPostRU;
|
||||||
|
m_ptPostRD = a.m_ptPostRD;
|
||||||
|
m_ptAbPostLU = a.m_ptAbPostLU;
|
||||||
|
m_ptAbPostLD = a.m_ptAbPostLD;
|
||||||
|
m_ptAbPostRU = a.m_ptAbPostRU;
|
||||||
|
m_ptAbPostRD = a.m_ptAbPostRD;
|
||||||
|
m_iTransparent = a.m_iTransparent;
|
||||||
|
m_iBKColor = a.m_iBKColor;
|
||||||
|
m_iWidth = a.m_iWidth;
|
||||||
|
m_iHeight = a.m_iHeight;
|
||||||
|
m_iStride = a.m_iStride;
|
||||||
|
m_iPixelFormat = a.m_iPixelFormat;
|
||||||
|
m_iBytes = a.m_iBytes;
|
||||||
|
m_pBitmap = a.m_pBitmap;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CRPArc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QPoint m_ptCenter;
|
||||||
|
int m_nRadius;
|
||||||
|
bool m_bCircle;//是圆还是圆弧1:圆 0 :圆弧
|
||||||
|
QPoint m_ptStart;//圆弧起始点
|
||||||
|
QPoint m_ptEnd;//圆弧结束点
|
||||||
|
|
||||||
|
CRPArc()
|
||||||
|
{
|
||||||
|
m_bCircle = true;
|
||||||
|
}
|
||||||
|
~CRPArc() {}
|
||||||
|
CRPArc(CRPArc &a)
|
||||||
|
{
|
||||||
|
m_ptCenter = a.m_ptCenter;
|
||||||
|
m_nRadius = a.m_nRadius;
|
||||||
|
m_bCircle = a.m_bCircle;
|
||||||
|
m_ptStart = a.m_ptStart;
|
||||||
|
m_ptEnd = a.m_ptEnd;
|
||||||
|
}
|
||||||
|
CRPArc operator=(const CRPArc &a)
|
||||||
|
{
|
||||||
|
m_ptCenter = a.m_ptCenter;
|
||||||
|
m_nRadius = a.m_nRadius;
|
||||||
|
m_bCircle = a.m_bCircle;
|
||||||
|
m_ptStart = a.m_ptStart;
|
||||||
|
m_ptEnd = a.m_ptEnd;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CRPText
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString m_strText;//字符串
|
||||||
|
QString m_strFontName;//字体名称
|
||||||
|
QPoint m_ptTextPos;//文字起点坐标
|
||||||
|
double m_dTextAngle;//文字角度
|
||||||
|
int m_nHeight;//文字高度
|
||||||
|
int m_nWidth;//文字宽度
|
||||||
|
int m_nWeight;//加粗
|
||||||
|
bool m_bItalic;//斜体
|
||||||
|
|
||||||
|
//文字坐标
|
||||||
|
QPoint m_ptPostLU; //文字的左上角在整个图中的XY位置
|
||||||
|
QPoint m_ptPostLD; //文字的左下角在整个图中的XY位置
|
||||||
|
QPoint m_ptPostRU; //文字的右上角在整个图中的XY位置
|
||||||
|
QPoint m_ptPostRD; //文字的右下角在整个图中的XY位置
|
||||||
|
|
||||||
|
|
||||||
|
CRPText()
|
||||||
|
{
|
||||||
|
m_strText = "";
|
||||||
|
m_strFontName = "";
|
||||||
|
m_ptTextPos = QPoint(0,0);
|
||||||
|
m_dTextAngle = 0;
|
||||||
|
m_nHeight = 0;
|
||||||
|
m_nWidth = 0;
|
||||||
|
m_nWeight = 0;
|
||||||
|
m_bItalic = false;
|
||||||
|
m_ptPostLU = QPoint(0,0);
|
||||||
|
m_ptPostLD = QPoint(0,0);
|
||||||
|
m_ptPostRU = QPoint(0,0);
|
||||||
|
m_ptPostRD = QPoint(0,0);
|
||||||
|
}
|
||||||
|
~CRPText() {}
|
||||||
|
CRPText(CRPText &a)
|
||||||
|
{
|
||||||
|
m_strText = a.m_strText;
|
||||||
|
m_strFontName = a.m_strFontName;
|
||||||
|
m_ptTextPos = a.m_ptTextPos;
|
||||||
|
m_dTextAngle = a.m_dTextAngle;
|
||||||
|
m_nHeight = a.m_nHeight;
|
||||||
|
m_nWidth = a.m_nWidth;
|
||||||
|
m_nWeight = a.m_nWeight;
|
||||||
|
m_bItalic = a.m_bItalic;
|
||||||
|
m_ptPostLU = a.m_ptPostLU;
|
||||||
|
m_ptPostLD = a.m_ptPostLD;
|
||||||
|
m_ptPostRU = a.m_ptPostRU;
|
||||||
|
m_ptPostRD = a.m_ptPostRD;
|
||||||
|
}
|
||||||
|
CRPText operator=( const CRPText &a)
|
||||||
|
{
|
||||||
|
m_strText = a.m_strText;
|
||||||
|
m_strFontName = a.m_strFontName;
|
||||||
|
m_ptTextPos = a.m_ptTextPos;
|
||||||
|
m_dTextAngle = a.m_dTextAngle;
|
||||||
|
m_nHeight = a.m_nHeight;
|
||||||
|
m_nWidth = a.m_nWidth;
|
||||||
|
m_nWeight = a.m_nWeight;
|
||||||
|
m_bItalic = a.m_bItalic;
|
||||||
|
m_ptPostLU = a.m_ptPostLU;
|
||||||
|
m_ptPostLD = a.m_ptPostLD;
|
||||||
|
m_ptPostRU = a.m_ptPostRU;
|
||||||
|
m_ptPostRD = a.m_ptPostRD;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CCode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int m_nLX;//左上角X位置
|
||||||
|
int m_nLY;//左上角Y位置
|
||||||
|
int m_nSizeX;//X方向大小
|
||||||
|
int m_nSizeY;//Y方向大小
|
||||||
|
int m_nAngle;//角度(逆时针方向为正),单位:0.01度
|
||||||
|
int m_nType;//类型(0:条形码,1:二维码)
|
||||||
|
int m_nCount;//字符串个数(字符串的字节数)
|
||||||
|
QString m_strCode;//字符串
|
||||||
|
QBitmap *m_pBitmap;//生成的位图数据
|
||||||
|
|
||||||
|
CCode()
|
||||||
|
{
|
||||||
|
m_nLX = 0;
|
||||||
|
m_nLY = 0;
|
||||||
|
m_nSizeX = 0;
|
||||||
|
m_nSizeY = 0;
|
||||||
|
m_nAngle = 0;
|
||||||
|
m_nType = 0;
|
||||||
|
m_nCount = 0;
|
||||||
|
m_strCode = "";
|
||||||
|
}
|
||||||
|
~CCode() {}
|
||||||
|
CCode(CCode &a)
|
||||||
|
{
|
||||||
|
m_nLX = a.m_nLX;
|
||||||
|
m_nLY = a.m_nLY;
|
||||||
|
m_nSizeX = a.m_nSizeX;
|
||||||
|
m_nSizeY = a.m_nSizeY;
|
||||||
|
m_nAngle = a.m_nAngle;
|
||||||
|
m_nType = a.m_nType;
|
||||||
|
m_nCount = a.m_nCount;
|
||||||
|
m_strCode = a.m_strCode;
|
||||||
|
m_pBitmap = a.m_pBitmap;
|
||||||
|
}
|
||||||
|
CCode operator=(const CCode &a)
|
||||||
|
{
|
||||||
|
m_nLX = a.m_nLX;
|
||||||
|
m_nLY = a.m_nLY;
|
||||||
|
m_nSizeX = a.m_nSizeX;
|
||||||
|
m_nSizeY = a.m_nSizeY;
|
||||||
|
m_nAngle = a.m_nAngle;
|
||||||
|
m_nType = a.m_nType;
|
||||||
|
m_nCount = a.m_nCount;
|
||||||
|
m_strCode = a.m_strCode;
|
||||||
|
m_pBitmap = a.m_pBitmap;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CNotch
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QPoint m_ptStart;//剪口起点
|
||||||
|
QPoint m_ptEnd;//剪口终点
|
||||||
|
int m_nWidth;//剪口宽度
|
||||||
|
int m_nNotchType;//剪口类型
|
||||||
|
QPoint m_ptCorrect;//通过根据刀的X、Y偏移计算得出的实际落刀位置
|
||||||
|
int m_nAngle;//根据交口起点和终点计算得出的角度(逆时针方向为正),单位:0.01度
|
||||||
|
double angle_2(int startx,int starty,int endx,int endy);
|
||||||
|
|
||||||
|
CNotch()
|
||||||
|
{
|
||||||
|
m_ptStart = QPoint(0,0);
|
||||||
|
m_ptEnd = QPoint(0,0);
|
||||||
|
m_nWidth = 0;;
|
||||||
|
m_nNotchType = 0;
|
||||||
|
m_ptCorrect = QPoint(0,0);
|
||||||
|
m_nAngle = 0;
|
||||||
|
}
|
||||||
|
~CNotch() {}
|
||||||
|
CNotch(CNotch &a)
|
||||||
|
{
|
||||||
|
m_ptStart = a.m_ptStart;
|
||||||
|
m_ptEnd = a.m_ptEnd;
|
||||||
|
m_nWidth = a.m_nWidth;
|
||||||
|
m_nNotchType = a.m_nNotchType;
|
||||||
|
m_ptCorrect = a.m_ptCorrect;
|
||||||
|
m_nAngle = a.m_nAngle;
|
||||||
|
}
|
||||||
|
CNotch operator=(const CNotch &a)
|
||||||
|
{
|
||||||
|
m_ptStart = a.m_ptStart;
|
||||||
|
m_ptEnd = a.m_ptEnd;
|
||||||
|
m_nWidth = a.m_nWidth;
|
||||||
|
m_nNotchType = a.m_nNotchType;
|
||||||
|
m_ptCorrect = a.m_ptCorrect;
|
||||||
|
m_nAngle = a.m_nAngle;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
void CovertToOutputByOffset(int nOffSetX,int nOffsetY);
|
||||||
|
int IntOfLineCircle(double a,double b,double c,int xc,int yc,int nR,QPoint &lpptIntersection1,QPoint &lpptIntersection2);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class CDrill
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QPoint m_pt;//冲孔的位置
|
||||||
|
int m_nDrillType;//冲孔类型
|
||||||
|
int m_nAngle;//冲孔的角度(逆时针方向为正),单位:0.01度
|
||||||
|
|
||||||
|
CDrill()
|
||||||
|
{
|
||||||
|
m_pt = QPoint(0,0);
|
||||||
|
m_nDrillType = 0;;
|
||||||
|
m_nAngle = 0;
|
||||||
|
}
|
||||||
|
~CDrill() {}
|
||||||
|
CDrill(CDrill &a)
|
||||||
|
{
|
||||||
|
m_pt = a.m_pt;
|
||||||
|
m_nDrillType = a.m_nDrillType;
|
||||||
|
m_nAngle = a.m_nAngle;
|
||||||
|
}
|
||||||
|
CDrill operator=(const CDrill &a)
|
||||||
|
{
|
||||||
|
m_pt = a.m_pt;
|
||||||
|
m_nDrillType = a.m_nDrillType;
|
||||||
|
m_nAngle = a.m_nAngle;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CRPPolyline
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int m_nDrawingType;//0:直线 1:位图 2:圆 3:文字 4:条形码、二维码 5:钻孔 6:剪口
|
||||||
|
int m_nID;//标识切割线切割顺序 从0开始
|
||||||
|
int m_nPenNo;//选择画笔 1为笔绘 3为半透切割 其它为切割
|
||||||
|
bool m_bSelect;//是否处于选中状态,true:选中状态 false:未选中状态
|
||||||
|
bool m_bPgEnd;//标识该切割线是该页的最后一条线
|
||||||
|
int m_nComType;//补偿类型 0 无补偿 1向右(内)补偿 2向左(外)补偿
|
||||||
|
|
||||||
|
CBitmapInfo m_bitmapInfo;
|
||||||
|
CRPArc m_circle;
|
||||||
|
CRPText m_text;
|
||||||
|
CCode m_code;
|
||||||
|
CDrill m_drill;
|
||||||
|
CNotch m_notch;
|
||||||
|
|
||||||
|
LineType m_lineType;
|
||||||
|
QList<QPoint> m_listPoint;
|
||||||
|
|
||||||
|
CRPPolyline()
|
||||||
|
{
|
||||||
|
m_nDrawingType = 0;
|
||||||
|
m_nID = 0;
|
||||||
|
m_nPenNo = 0;
|
||||||
|
m_bSelect = false;
|
||||||
|
m_bPgEnd = false;
|
||||||
|
m_lineType.bDefault = true;
|
||||||
|
m_listPoint.clear();
|
||||||
|
m_nComType = 0;
|
||||||
|
}
|
||||||
|
~CRPPolyline() {}
|
||||||
|
CRPPolyline(const CRPPolyline &a)
|
||||||
|
{
|
||||||
|
m_nDrawingType = a.m_nDrawingType;
|
||||||
|
m_nID = a.m_nID;
|
||||||
|
m_nPenNo = a.m_nPenNo;
|
||||||
|
m_bSelect = a.m_bSelect;
|
||||||
|
m_bPgEnd = a.m_bPgEnd;
|
||||||
|
m_lineType = a.m_lineType;
|
||||||
|
m_listPoint.clear();
|
||||||
|
m_listPoint.append(a.m_listPoint);
|
||||||
|
m_text = a.m_text;
|
||||||
|
m_nComType = a.m_nComType;
|
||||||
|
m_circle = a.m_circle;
|
||||||
|
m_text = a.m_text;
|
||||||
|
m_code = a.m_code;
|
||||||
|
m_notch = a.m_notch;
|
||||||
|
m_drill = a.m_drill;
|
||||||
|
m_bitmapInfo = a.m_bitmapInfo;
|
||||||
|
}
|
||||||
|
CRPPolyline operator=( const CRPPolyline &a)
|
||||||
|
{
|
||||||
|
m_nDrawingType = a.m_nDrawingType;
|
||||||
|
m_nID = a.m_nID;
|
||||||
|
m_nPenNo = a.m_nPenNo;
|
||||||
|
m_bSelect = a.m_bSelect;
|
||||||
|
m_bPgEnd = a.m_bPgEnd;
|
||||||
|
m_lineType = a.m_lineType;
|
||||||
|
m_listPoint.clear();
|
||||||
|
m_listPoint.append(a.m_listPoint);
|
||||||
|
m_text = a.m_text;
|
||||||
|
m_nComType = a.m_nComType;
|
||||||
|
m_circle = a.m_circle;
|
||||||
|
m_text = a.m_text;
|
||||||
|
m_code = a.m_code;
|
||||||
|
m_notch = a.m_notch;
|
||||||
|
m_drill = a.m_drill;
|
||||||
|
m_bitmapInfo = a.m_bitmapInfo;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Marker : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Marker(QObject *parent = 0);
|
||||||
|
virtual ~Marker();
|
||||||
|
Marker(const Marker &a);
|
||||||
|
Marker operator=(const Marker &a);
|
||||||
|
void Initialize();
|
||||||
|
QRect GetRect();
|
||||||
|
QRect RectofPolyline(const QList <QPoint> &listPoint);
|
||||||
|
|
||||||
|
double m_iDPMM; //长度数据单位:m_iDPMM(每毫米点)
|
||||||
|
QList <CRPPolyline> m_listPolyline; //切割的点链,单位:1/m_iDPMM mm, X向右为正,Y向上为正
|
||||||
|
int m_nProducts;
|
||||||
|
int m_nActualMatchRegions;
|
||||||
|
int m_nMatchRegions;
|
||||||
|
QString m_strProductCode;//产品型号
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MARKER_H
|
||||||
79
datafile/hpgl/plotbitmap.cpp
Normal file
79
datafile/hpgl/plotbitmap.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "plotbitmap.h"
|
||||||
|
|
||||||
|
PlotBitmap::PlotBitmap(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//QBitmap PlotBitmap::Create1BPPBitmap(int bTransparent, int crBkColor, int iWidth, int iHeight, int iStride, int nPixFormat, char *pBmpData)
|
||||||
|
QBitmap PlotBitmap::Create1BPPBitmap(int iWidth,int iHeight,unsigned char *pBmpData)
|
||||||
|
{
|
||||||
|
QPen pen;
|
||||||
|
pen.setWidth(1);
|
||||||
|
pen.setColor(QColor(Qt::black));
|
||||||
|
|
||||||
|
//QImage::Format_RGBA8888 代表彩色图
|
||||||
|
QImage image = QImage(pBmpData, iWidth, iHeight, QImage::Format_RGB888);
|
||||||
|
//image.save("D:\\1.png");
|
||||||
|
|
||||||
|
QBitmap pixmap = QBitmap(iWidth,iHeight);
|
||||||
|
QPainter *pixPainter = new QPainter();
|
||||||
|
pixPainter->setPen(pen);
|
||||||
|
pixPainter->begin(&pixmap);
|
||||||
|
pixmap.fill(Qt::white);//用白色填充
|
||||||
|
pixPainter->drawImage(0,0,image);
|
||||||
|
//pixmap.save("D:\\1.bmp");
|
||||||
|
|
||||||
|
#if(0)//转灰度图
|
||||||
|
QImage gimage = QImage();
|
||||||
|
uchar* pImageData1 = NULL,*pImageData2 = NULL;
|
||||||
|
|
||||||
|
pImageData1 = image.bits();
|
||||||
|
|
||||||
|
gimage = image.convertToFormat(QImage::Format_Indexed8);
|
||||||
|
|
||||||
|
QVector<QRgb> table;
|
||||||
|
for( int i = 0 ; i < 256 ; ++i )
|
||||||
|
{
|
||||||
|
table.append(qRgb(i,i,i));
|
||||||
|
}
|
||||||
|
|
||||||
|
gimage.setColorTable(table);
|
||||||
|
|
||||||
|
for(int i =0; i< gimage.width();i++)
|
||||||
|
{
|
||||||
|
for(int j=0; j< gimage.height();j++)
|
||||||
|
{
|
||||||
|
QRgb pix_value = gimage.pixel(i,j);
|
||||||
|
gimage.setPixel(i,j,qGray(pix_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pImageData2 = gimage.bits();
|
||||||
|
gimage.save("D:\\1.bmp");
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置unsigned char中某位的值
|
||||||
|
//dat 需要设置的unsigned char
|
||||||
|
//index 设置位
|
||||||
|
//val 设置值0或者1
|
||||||
|
void PlotBitmap::SetUncharBit(unsigned char &dat, int index, int val)
|
||||||
|
{
|
||||||
|
unsigned int bitmod = 0x01;
|
||||||
|
if(index >= 0 && index < 8)
|
||||||
|
{
|
||||||
|
bitmod <<= index;
|
||||||
|
if (val == 0)
|
||||||
|
{
|
||||||
|
dat &= ~bitmod;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dat |= bitmod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
datafile/hpgl/plotbitmap.h
Normal file
64
datafile/hpgl/plotbitmap.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#ifndef PLOTBITMAP_H
|
||||||
|
#define PLOTBITMAP_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QBitmap>
|
||||||
|
#include <QFile>
|
||||||
|
//#include <gdiplus.h>
|
||||||
|
|
||||||
|
//BMP文件头(14字节)
|
||||||
|
typedef struct /**** BMP file header structure ****/
|
||||||
|
{
|
||||||
|
unsigned short bfType; /* 类型 */
|
||||||
|
unsigned int bfSize; /* 整个bmp文件大小 */
|
||||||
|
unsigned short bfReserved1; /* Reserved */
|
||||||
|
unsigned short bfReserved2; /* ... */
|
||||||
|
unsigned int bfOffBits; /* 偏移数,位图文件头+位图信息头+调色板大小 */
|
||||||
|
} BmpHeader;
|
||||||
|
|
||||||
|
//位图信息头(40字节)
|
||||||
|
typedef struct /**** BMP file info structure ****/
|
||||||
|
{
|
||||||
|
unsigned int biSize; /* Size of info header */
|
||||||
|
int biWidth; /* Width of image */
|
||||||
|
int biHeight; /* Height of image */
|
||||||
|
unsigned short biPlanes; /* Number of color planes */
|
||||||
|
unsigned short biBitCount; /* Number of bits per pixel */
|
||||||
|
unsigned int biCompression; /* Type of compression to use */
|
||||||
|
unsigned int biSizeImage; /* Size of image data */
|
||||||
|
int biXPelsPerMeter; /* X pixels per meter */
|
||||||
|
int biYPelsPerMeter; /* Y pixels per meter */
|
||||||
|
unsigned int biClrUsed; /* Number of colors used */
|
||||||
|
unsigned int biClrImportant; /* Number of important colors */
|
||||||
|
} BmpInfo;
|
||||||
|
|
||||||
|
class PlotBitmap : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PlotBitmap(QObject *parent = NULL);
|
||||||
|
|
||||||
|
public:
|
||||||
|
//创建单色的位图
|
||||||
|
//输入参数:
|
||||||
|
// bTransparent 透明显示
|
||||||
|
// crBkColor 背景颜色(在透明显示时位图中颜色为crBkColor的点将不被显示在纸样上)
|
||||||
|
// iWidth 位图的宽,单位:像素
|
||||||
|
// iHeight 位图的高,单位:像素
|
||||||
|
// iStride 位图每行的字节数
|
||||||
|
// nPixFormat 位图点的格式(见GDI+中BitmapData类PixelFormat的定义)
|
||||||
|
// pBmpData 位图数据(保存数据的顺序是从左到右,从上到下)
|
||||||
|
//返回值:
|
||||||
|
// NULL 失败
|
||||||
|
// 非NULL 新生成的位图指针
|
||||||
|
//QBitmap Create1BPPBitmap(int bTransparent,int crBkColor,int iWidth,int iHeight,int iStride,int nPixFormat,char *pBmpData);
|
||||||
|
QBitmap Create1BPPBitmap(int iWidth,int iHeight,unsigned char *pBmpData);
|
||||||
|
|
||||||
|
void SetUncharBit(unsigned char & dat, int index, int val);
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLOTBITMAP_H
|
||||||
107
datafile/hpgl/typedef.h
Normal file
107
datafile/hpgl/typedef.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#ifndef TYPEDEF_H
|
||||||
|
#define TYPEDEF_H
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL ((void *) 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FALSE
|
||||||
|
#define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#define DATA_VALID 0x55AA
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef int BOOL;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
typedef unsigned short int WORD;
|
||||||
|
typedef unsigned long int DWORD;
|
||||||
|
|
||||||
|
typedef unsigned char u8;
|
||||||
|
typedef unsigned short int u16;
|
||||||
|
typedef unsigned int u32;
|
||||||
|
typedef char s8;
|
||||||
|
typedef short int s16;
|
||||||
|
typedef int s32;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
#define U8_MAX ((u8)255)
|
||||||
|
#define S8_MAX ((s8)127)
|
||||||
|
#define S8_MIN ((s8)(-128))
|
||||||
|
#define U16_MAX ((u16)65535u)
|
||||||
|
#define S16_MAX ((s16)32767)
|
||||||
|
#define S16_MIN ((s16)(-32768))
|
||||||
|
#define U32_MAX ((u32)4294967295uL)
|
||||||
|
#define S32_MAX ((s32)2147483647uL)
|
||||||
|
#define S32_MIN ((s32)(-2147483648uL))
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
#ifndef LOBYTE
|
||||||
|
#define LOBYTE(w) ((BYTE)(((WORD)(w)) & 0xff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIBYTE
|
||||||
|
#define HIBYTE(w) ((BYTE)((((WORD)(w)) >> 8) & 0xff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOWORD
|
||||||
|
#define LOWORD(l) ((WORD)(((DWORD)(l)) & 0xffff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIWORD
|
||||||
|
#define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xffff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAKEWORD
|
||||||
|
#define MAKEWORD(a, b) ((WORD)((BYTE)(a)) | (((WORD)((BYTE)(b))) << 8))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAKEDWORD
|
||||||
|
#define MAKEDWORD(a, b) ((DWORD)((WORD)(a)) | (((DWORD)((WORD)(b))) << 16))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOHFBYTE
|
||||||
|
#define LOHFBYTE(b) ((BYTE)((b) & 0x0f))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIHFBYTE
|
||||||
|
#define HIHFBYTE(b) ((BYTE)(((b) >> 4) & 0x0f))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAKEBYTE
|
||||||
|
#define MAKEBYTE(a, b) ((BYTE)((BYTE)((a) & 0x0f)) | ((BYTE)(((BYTE)((b) & 0x0f)) << 4)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef PI
|
||||||
|
|
||||||
|
#define PI 3.1415926535897932
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TYPEDEF_H
|
||||||
918
datafile/hpgl/vectorfont.cpp
Normal file
918
datafile/hpgl/vectorfont.cpp
Normal file
@ -0,0 +1,918 @@
|
|||||||
|
#include "vectorfont.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <qmath.h>
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
VectorFont::VectorFont(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
m_iDPMM = 40;
|
||||||
|
m_pChinese_char = NULL;
|
||||||
|
m_pEnglish_char = NULL;
|
||||||
|
m_nChinese_char_count = 0;
|
||||||
|
m_nEnglish_char_count = 0;
|
||||||
|
IniVectorFont();
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorFont::~VectorFont()
|
||||||
|
{
|
||||||
|
if(m_pChinese_char != NULL)
|
||||||
|
{
|
||||||
|
delete []m_pChinese_char;
|
||||||
|
m_pChinese_char = NULL;
|
||||||
|
}
|
||||||
|
if(m_pEnglish_char != NULL)
|
||||||
|
{
|
||||||
|
delete []m_pEnglish_char;
|
||||||
|
m_pEnglish_char = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VectorFont::IniVectorFont()
|
||||||
|
{
|
||||||
|
QFile fntFile;
|
||||||
|
QString strCharFileName;
|
||||||
|
|
||||||
|
BYTE byte[10];
|
||||||
|
int nCharCount_C;
|
||||||
|
int nCharCount_E;
|
||||||
|
CChinese_char Chinese_char1;
|
||||||
|
CEnglish_char English_char1;
|
||||||
|
int nCountChar;
|
||||||
|
|
||||||
|
|
||||||
|
QString appPath = QCoreApplication::applicationDirPath();
|
||||||
|
QChar separator = QChar('/');
|
||||||
|
if(!appPath.contains(separator)) // 判断分隔符
|
||||||
|
{
|
||||||
|
separator = QChar('\\');
|
||||||
|
}
|
||||||
|
m_workPath = appPath + separator;
|
||||||
|
|
||||||
|
|
||||||
|
strCharFileName = m_workPath + "english.fnt";
|
||||||
|
//qDebug()<< "strCharFileName" << strCharFileName;
|
||||||
|
fntFile.setFileName(strCharFileName);
|
||||||
|
|
||||||
|
if(!fntFile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qDebug() <<"english file open failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fntFile.seek(0);
|
||||||
|
fntFile.read((char*)byte,10);
|
||||||
|
|
||||||
|
m_nInternalLeading_E=(int)((WORD)byte[0] | ((WORD)byte[1] << 8));
|
||||||
|
m_nHeight_E=(int)((WORD)byte[2] | ((WORD)byte[3] << 8));
|
||||||
|
m_nDescent_E=(int)((WORD)byte[4] | ((WORD)byte[5] << 8));
|
||||||
|
nCharCount_E=(int)((DWORD)byte[6] | ((DWORD)byte[7] << 8) | ((DWORD)byte[9] << 16) | ((DWORD)byte[9] << 24));
|
||||||
|
//m_aEnglish_char.clear();
|
||||||
|
m_pEnglish_char = new CEnglish_char[nCharCount_E];
|
||||||
|
m_nEnglish_char_count = nCharCount_E;
|
||||||
|
fntFile.seek(10);
|
||||||
|
|
||||||
|
nCountChar=nCharCount_E;
|
||||||
|
while (nCountChar > 0)
|
||||||
|
{
|
||||||
|
fntFile.read((char*)byte,10);
|
||||||
|
|
||||||
|
English_char1.m_wCharCode=(WORD)byte[0] | ((WORD)byte[1] << 8);
|
||||||
|
English_char1.m_wBytes=(WORD)byte[2] | ((WORD)byte[3] << 8);
|
||||||
|
English_char1.m_wWidth=(WORD)byte[4] | ((WORD)byte[5] << 8);
|
||||||
|
English_char1.m_dwPosition=(DWORD)byte[6] | ((DWORD)byte[7] << 8) | ((DWORD)byte[9] << 16) | ((DWORD)byte[9] << 24);
|
||||||
|
|
||||||
|
m_pEnglish_char[nCharCount_E-nCountChar] = English_char1;
|
||||||
|
//m_aEnglish_char.append(English_char1);
|
||||||
|
|
||||||
|
nCountChar--;
|
||||||
|
}
|
||||||
|
fntFile.close();
|
||||||
|
|
||||||
|
strCharFileName = m_workPath + "Hz.fnt";
|
||||||
|
//qDebug()<< "strCharFileName" << strCharFileName;
|
||||||
|
fntFile.setFileName(strCharFileName);
|
||||||
|
if(!fntFile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qDebug() <<"chinese file open failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fntFile.seek(0);
|
||||||
|
fntFile.read((char*)byte,8);
|
||||||
|
|
||||||
|
m_nWidth_C=(int)((WORD)byte[0] | ((WORD)byte[1] << 8));
|
||||||
|
m_nHeight_C=(int)((WORD)byte[2] | ((WORD)byte[3] << 8));
|
||||||
|
nCharCount_C=(int)((DWORD)byte[4] | ((DWORD)byte[5] << 8) | ((DWORD)byte[6] << 16) | ((DWORD)byte[7] << 24));
|
||||||
|
|
||||||
|
//m_aChinese_char.clear();
|
||||||
|
m_pChinese_char = new CChinese_char[nCharCount_C];
|
||||||
|
m_nChinese_char_count = nCharCount_C;
|
||||||
|
|
||||||
|
fntFile.seek(8);
|
||||||
|
nCountChar=nCharCount_C;
|
||||||
|
while (nCountChar > 0)
|
||||||
|
{
|
||||||
|
fntFile.read((char*)byte,8);
|
||||||
|
|
||||||
|
Chinese_char1.m_wCharCode=(WORD)byte[0] | ((WORD)byte[1] << 8);
|
||||||
|
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--;
|
||||||
|
}
|
||||||
|
fntFile.close();
|
||||||
|
|
||||||
|
m_dFontAngle = 0;
|
||||||
|
m_dFontHeight = 0.375 * 10 * m_iDPMM;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//输入参数:
|
||||||
|
// ptPointLU 显示字符串的左上角坐标(即TextOut(...)的x,y值)
|
||||||
|
// pbyData 字符的描述数据
|
||||||
|
// wBytes 字符的描述数据个数
|
||||||
|
// nLeft,nDown 字符的左下角坐标(即以英汉字库的公共单位及坐标水平绘制字符串时,字符的的左下角坐标)
|
||||||
|
// nFontScale 字库的长度比例
|
||||||
|
void VectorFont::PlotChar(QPoint ptPointLU,BYTE *pbyData,WORD wBytes,int nLeft,int nDown,int nFontScale)
|
||||||
|
{
|
||||||
|
BYTE byByteX,byByteY;
|
||||||
|
QPoint ptCurrentPos,ptCenter,ptPointS,ptPointE;
|
||||||
|
QPoint ptPoint1;
|
||||||
|
WORD wIndex1;
|
||||||
|
WORD wDirection,wLength;
|
||||||
|
BOOL bPenUp,bVerTextCommand,bClockwise;
|
||||||
|
WORD wRadius,wArcS,wSpan;
|
||||||
|
int nRadius;
|
||||||
|
double dAngleS,dAngleE,dAngleOffsetS,dAngleOffsetE;
|
||||||
|
double dx1,dy1,dx2,dy2,dxc,dyc,dr,dD,dH,dBulge;
|
||||||
|
double dCos,dSin;
|
||||||
|
double dLToDScale;
|
||||||
|
int nHeight;
|
||||||
|
|
||||||
|
if (wBytes == 0) return;
|
||||||
|
|
||||||
|
nHeight=(m_nInternalLeading_E + m_nHeight_E) * m_nHeight_E;
|
||||||
|
//nHeight=(m_nInternalLeading_E + m_nHeight_E) * m_nHeight_C; //之前
|
||||||
|
dLToDScale=(double)nHeight / m_dFontHeight;
|
||||||
|
|
||||||
|
m_dRake = m_dFontAngle/180.0*PI;
|
||||||
|
dCos=cos(m_dRake);
|
||||||
|
dSin=sin(m_dRake);
|
||||||
|
|
||||||
|
ptCurrentPos=QPoint(nLeft,nDown);
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
bVerTextCommand=false;
|
||||||
|
bPenUp=false;
|
||||||
|
wIndex1=0;
|
||||||
|
while (wIndex1 < wBytes) {
|
||||||
|
switch (pbyData[wIndex1]) {
|
||||||
|
case 0x0:
|
||||||
|
wIndex1++;
|
||||||
|
break;
|
||||||
|
case 0x1:
|
||||||
|
wIndex1++;
|
||||||
|
bPenUp=false;
|
||||||
|
break;
|
||||||
|
case 0x2:
|
||||||
|
wIndex1++;
|
||||||
|
bPenUp=true;
|
||||||
|
break;
|
||||||
|
case 0x3:
|
||||||
|
wIndex1++;
|
||||||
|
wIndex1++;
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0x4:
|
||||||
|
wIndex1++;
|
||||||
|
wIndex1++;
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0x5:
|
||||||
|
wIndex1++;
|
||||||
|
bPenUp=true;
|
||||||
|
break;
|
||||||
|
case 0x6:
|
||||||
|
wIndex1++;
|
||||||
|
bPenUp=true;
|
||||||
|
break;
|
||||||
|
case 0x7:
|
||||||
|
wIndex1++;
|
||||||
|
wIndex1++;
|
||||||
|
bPenUp=true;
|
||||||
|
break;
|
||||||
|
case 0x8:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1=wIndex1+3;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wIndex1++;
|
||||||
|
ptCurrentPos.setX(ptCurrentPos.x() + (char)pbyData[wIndex1] * nFontScale);
|
||||||
|
wIndex1++;
|
||||||
|
ptCurrentPos.setY(ptCurrentPos.y() + (char)pbyData[wIndex1] * nFontScale);
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
if (bPenUp)
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
else
|
||||||
|
LineTo(ptPoint1);
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0x9:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1++;
|
||||||
|
byByteX=pbyData[wIndex1];
|
||||||
|
wIndex1++;
|
||||||
|
byByteY=pbyData[wIndex1];
|
||||||
|
while ((byByteX != 0) || (byByteY != 0)) {
|
||||||
|
wIndex1++;
|
||||||
|
byByteX=pbyData[wIndex1];
|
||||||
|
wIndex1++;
|
||||||
|
byByteY=pbyData[wIndex1];
|
||||||
|
}
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wIndex1++;
|
||||||
|
byByteX=pbyData[wIndex1];
|
||||||
|
wIndex1++;
|
||||||
|
byByteY=pbyData[wIndex1];
|
||||||
|
while ((byByteX != 0) || (byByteY != 0)) {
|
||||||
|
ptCurrentPos.setX(ptCurrentPos.x() + (char)byByteX * nFontScale);
|
||||||
|
ptCurrentPos.setY(ptCurrentPos.y() + (char)byByteY * nFontScale);
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
if (bPenUp)
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
else
|
||||||
|
LineTo(ptPoint1);
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
byByteX=pbyData[wIndex1];
|
||||||
|
wIndex1++;
|
||||||
|
byByteY=pbyData[wIndex1];
|
||||||
|
}
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0xA:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1=wIndex1+3;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wIndex1++;
|
||||||
|
wRadius=(WORD)pbyData[wIndex1];
|
||||||
|
wIndex1++;
|
||||||
|
if (((char)pbyData[wIndex1]) < 0) bClockwise=true;
|
||||||
|
else bClockwise=false;
|
||||||
|
wArcS=(WORD)pbyData[wIndex1];
|
||||||
|
wArcS=wArcS & 0x70;
|
||||||
|
wArcS=wArcS >> 4;
|
||||||
|
wSpan=(WORD)pbyData[wIndex1];
|
||||||
|
wSpan=wSpan & 0x7;
|
||||||
|
|
||||||
|
//计算圆心
|
||||||
|
ptCenter=ptCurrentPos;
|
||||||
|
ptCenter.setX(ptCenter.x() - ((double)wRadius * (double)nFontScale * cos((double)wArcS * 45.0 / 180.0 * 3.14159265359))+0.5);
|
||||||
|
ptCenter.setY(ptCenter.y() - ((double)wRadius * (double)nFontScale * sin((double)wArcS * 45.0 / 180.0 * 3.14159265359))+0.5);
|
||||||
|
|
||||||
|
dAngleS=(double)wArcS * 45.0 / 180.0 * 3.14159265359;
|
||||||
|
if (bClockwise) dAngleE=dAngleS - (double)wSpan * 45.0 / 180.0 * 3.14159265359;
|
||||||
|
else dAngleE=dAngleS + (double)wSpan * 45.0 / 180.0 * 3.14159265359;
|
||||||
|
|
||||||
|
if (bClockwise) {
|
||||||
|
ptPointS.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleE)+0.5);
|
||||||
|
ptPointS.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleE)+0.5);
|
||||||
|
ptPointE.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleS)+0.5);
|
||||||
|
ptPointE.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleS)+0.5);
|
||||||
|
ptCurrentPos=ptPointS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ptPointS.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleS)+0.5);
|
||||||
|
ptPointS.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleS)+0.5);
|
||||||
|
ptPointE.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleE)+0.5);
|
||||||
|
ptPointE.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleE)+0.5);
|
||||||
|
ptCurrentPos=ptPointE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptCenter=CPToLP(ptCenter,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointS=CPToLP(ptPointS,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointE=CPToLP(ptPointE,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
nRadius=(double)wRadius * (double)nFontScale / dLToDScale + 0.5;
|
||||||
|
Arc(ptCenter.x() - nRadius,ptCenter.y() - nRadius,
|
||||||
|
ptCenter.x() + nRadius,ptCenter.y() + nRadius,
|
||||||
|
ptPointS.x(),ptPointS.y(),ptPointE.x(),ptPointE.y());
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0xB:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1=wIndex1+6;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wIndex1++;
|
||||||
|
dAngleOffsetS=(double)((WORD)pbyData[wIndex1]);
|
||||||
|
wIndex1++;
|
||||||
|
dAngleOffsetE=(double)((WORD)pbyData[wIndex1]);
|
||||||
|
wIndex1++;
|
||||||
|
wRadius=(WORD)pbyData[wIndex1];
|
||||||
|
wRadius=wRadius << 8;
|
||||||
|
wIndex1++;
|
||||||
|
wRadius=wRadius | (WORD)pbyData[wIndex1];
|
||||||
|
wIndex1++;
|
||||||
|
if (((char)pbyData[wIndex1]) < 0) bClockwise=true;
|
||||||
|
else bClockwise=false;
|
||||||
|
wArcS=(WORD)pbyData[wIndex1];
|
||||||
|
wArcS=wArcS & 0x70;
|
||||||
|
wArcS=wArcS >> 4;
|
||||||
|
wSpan=(WORD)pbyData[wIndex1];
|
||||||
|
wSpan=wSpan & 0x7;
|
||||||
|
|
||||||
|
//计算圆心
|
||||||
|
ptCenter=ptCurrentPos;
|
||||||
|
ptCenter.setX(ptCenter.x() - (double)wRadius * (double)nFontScale * cos((double)wArcS * 45.0 / 180.0 * 3.14159265359)+0.5);
|
||||||
|
ptCenter.setY(ptCenter.y() - (double)wRadius * (double)nFontScale * sin((double)wArcS * 45.0 / 180.0 * 3.14159265359)+0.5);
|
||||||
|
|
||||||
|
dAngleS=(double)wArcS * 45.0;
|
||||||
|
dAngleS=dAngleOffsetS * 45.0 / 256.0 + dAngleS;
|
||||||
|
if (bClockwise) dAngleE=-(double)wSpan * 45.0;
|
||||||
|
else dAngleE=(double)wSpan * 45.0;
|
||||||
|
dAngleE=dAngleOffsetE * 45.0 / 256.0 + dAngleE;
|
||||||
|
dAngleE=dAngleOffsetE * 45.0 / 256.0 + dAngleE;
|
||||||
|
dAngleS=dAngleS / 180.0 * 3.14159265359;
|
||||||
|
dAngleE=dAngleE / 180.0 * 3.14159265359;
|
||||||
|
|
||||||
|
if (bClockwise) {
|
||||||
|
ptPointS.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleE)+0.5);
|
||||||
|
ptPointS.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleE)+0.5);
|
||||||
|
ptPointE.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleS)+0.5);
|
||||||
|
ptPointE.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleS)+0.5);
|
||||||
|
ptCurrentPos=ptPointS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ptPointS.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleS)+0.5);
|
||||||
|
ptPointS.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleS)+0.5);
|
||||||
|
ptPointE.setX(ptCenter.x() + (double)wRadius * (double)nFontScale * cos(dAngleE)+0.5);
|
||||||
|
ptPointE.setY(ptCenter.y() + (double)wRadius * (double)nFontScale * sin(dAngleE)+0.5);
|
||||||
|
ptCurrentPos=ptPointE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptCenter=CPToLP(ptCenter,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointS=CPToLP(ptPointS,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointE=CPToLP(ptPointE,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
nRadius=(double)wRadius * (double)nFontScale / dLToDScale + 0.5;
|
||||||
|
|
||||||
|
Arc(ptCenter.x() - nRadius,ptCenter.y() - nRadius,
|
||||||
|
ptCenter.x() + nRadius,ptCenter.y() + nRadius,
|
||||||
|
ptPointS.x(),ptPointS.y(),ptPointE.x(),ptPointE.y());
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0xC:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1=wIndex1+4;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wIndex1++;
|
||||||
|
dx1=(double)((char)pbyData[wIndex1]) * (double)nFontScale;
|
||||||
|
wIndex1++;
|
||||||
|
dy1=(double)((char)pbyData[wIndex1]) * (double)nFontScale;
|
||||||
|
wIndex1++;
|
||||||
|
dBulge=(double)((char)pbyData[wIndex1]);
|
||||||
|
if (((char)pbyData[wIndex1]) < 0) bClockwise=true;
|
||||||
|
else bClockwise=false;
|
||||||
|
|
||||||
|
dD=sqrt(dx1*dx1 + dy1*dy1);
|
||||||
|
dH=fabs(dBulge) * dD / 127.0 / 2.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);
|
||||||
|
|
||||||
|
if (bPenUp) MoveTo(ptPoint1);
|
||||||
|
else LineTo(ptPoint1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (bClockwise) {
|
||||||
|
dx2=-dy1;
|
||||||
|
dy2=dx1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dx2=dy1;
|
||||||
|
dy2=-dx1;
|
||||||
|
}
|
||||||
|
dx2=dx2 / dD * dH + dx1 / 2.0;
|
||||||
|
dy2=dy2 / dD * dH + dy1 / 2.0;
|
||||||
|
|
||||||
|
CircleCR(0.0,0.0,dx2,dy2,dx1,dy1,dxc,dyc,dr);
|
||||||
|
ptCenter.setX(ptCurrentPos.x() + dxc + 0.5);
|
||||||
|
ptCenter.setY(ptCurrentPos.y() + dyc + 0.5);
|
||||||
|
|
||||||
|
if (bClockwise)
|
||||||
|
{
|
||||||
|
ptPointS.setX(ptCurrentPos.x() + dx1 + 0.5);
|
||||||
|
ptPointS.setY(ptCurrentPos.y() + dy1 + 0.5 );
|
||||||
|
ptPointE=ptCurrentPos;
|
||||||
|
ptCurrentPos=ptPointS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptPointS=ptCurrentPos;
|
||||||
|
ptPointE.setX(ptCurrentPos.x() + dx1 + 0.5);
|
||||||
|
ptPointE.setY(ptCurrentPos.y() + dy1 + 0.5);
|
||||||
|
ptCurrentPos=ptPointE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptCenter=CPToLP(ptCenter,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointS=CPToLP(ptPointS,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointE=CPToLP(ptPointE,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
nRadius=dr / dLToDScale + 0.5;
|
||||||
|
|
||||||
|
Arc(ptCenter.x() - nRadius,ptCenter.y() - nRadius,ptCenter.x() + nRadius,ptCenter.y() + nRadius,
|
||||||
|
ptPointS.x(),ptPointS.y(),ptPointE.x(),ptPointE.y());
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
}
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0xD:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1=wIndex1+4;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wIndex1++;
|
||||||
|
while ((pbyData[wIndex1] != 0) || (pbyData[wIndex1+1] != 0)) {
|
||||||
|
dx1=(double)((char)pbyData[wIndex1]) * (double)nFontScale;
|
||||||
|
wIndex1++;
|
||||||
|
dy1=(double)((char)pbyData[wIndex1]) * (double)nFontScale;
|
||||||
|
wIndex1++;
|
||||||
|
dBulge=(double)((char)pbyData[wIndex1]);
|
||||||
|
if (((char)pbyData[wIndex1]) < 0) bClockwise=true;
|
||||||
|
else bClockwise=false;
|
||||||
|
|
||||||
|
dD=sqrt(dx1*dx1 + dy1*dy1);
|
||||||
|
dH=fabs(dBulge) * dD / 127.0 / 2.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);
|
||||||
|
|
||||||
|
if (bPenUp)
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
else
|
||||||
|
LineTo(ptPoint1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (bClockwise) {
|
||||||
|
dx2=-dy1;
|
||||||
|
dy2=dx1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dx2=dy1;
|
||||||
|
dy2=-dx1;
|
||||||
|
}
|
||||||
|
dx2=dx2 / dD * dH + dx1 / 2.0;
|
||||||
|
dy2=dy2 / dD * dH + dy1 / 2.0;
|
||||||
|
|
||||||
|
CircleCR(0.0,0.0,dx2,dy2,dx1,dy1,dxc,dyc,dr);
|
||||||
|
ptCenter.setX(ptCurrentPos.x() + dxc + 0.5);
|
||||||
|
ptCenter.setY(ptCurrentPos.y() + dyc + 0.5);
|
||||||
|
|
||||||
|
if (bClockwise)
|
||||||
|
{
|
||||||
|
ptPointS.setX(ptCurrentPos.x() + dx1 + 0.5);
|
||||||
|
ptPointS.setY(ptCurrentPos.y() + dy1 + 0.5);
|
||||||
|
ptPointE=ptCurrentPos;
|
||||||
|
ptCurrentPos=ptPointS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptPointS=ptCurrentPos;
|
||||||
|
ptPointE.setX(ptCurrentPos.x() + dx1 + 0.5);
|
||||||
|
ptPointE.setY(ptCurrentPos.y() + dy1 + 0.5);
|
||||||
|
ptCurrentPos=ptPointE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptCenter=CPToLP(ptCenter,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointS=CPToLP(ptPointS,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
ptPointE=CPToLP(ptPointE,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
nRadius=dr / dLToDScale + 0.5;
|
||||||
|
|
||||||
|
Arc(ptCenter.x() - nRadius,ptCenter.y() - nRadius,ptCenter.x() + nRadius,ptCenter.y() + nRadius,
|
||||||
|
ptPointS.x(),ptPointS.y(),ptPointE.x(),ptPointE.y());
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
MoveTo(ptPoint1);
|
||||||
|
}
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
case 0xE:
|
||||||
|
bVerTextCommand=true;
|
||||||
|
wIndex1++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (bVerTextCommand) {
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wDirection=(WORD)(pbyData[wIndex1] % 16);
|
||||||
|
wLength=(WORD)(pbyData[wIndex1] / 16) * (WORD)nFontScale;
|
||||||
|
ptCurrentPos=GetNextCoodinate(wDirection,wLength,ptCurrentPos);
|
||||||
|
|
||||||
|
ptPoint1=CPToLP(ptCurrentPos,nHeight,ptPointLU,dSin,dCos,dLToDScale);
|
||||||
|
if (bPenUp) MoveTo(ptPoint1);
|
||||||
|
else LineTo(ptPoint1);
|
||||||
|
|
||||||
|
wIndex1++;
|
||||||
|
}
|
||||||
|
bVerTextCommand=false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint VectorFont::CPToLP(QPoint ptCP,int nHeight,QPoint ptPointLU,double dSin,double dCos,double dScale)
|
||||||
|
{
|
||||||
|
double dx,dy;
|
||||||
|
QPoint ptPoint1;
|
||||||
|
|
||||||
|
dx=(double)ptCP.x();
|
||||||
|
dy=(double)ptCP.y()-(double)nHeight;
|
||||||
|
ptPoint1.setX(ptPointLU.x() + ((dx*dCos - dy*dSin) / dScale + 0.5));
|
||||||
|
ptPoint1.setY(ptPointLU.y() + ((dx*dSin + dy*dCos) / dScale + 0.5));
|
||||||
|
|
||||||
|
return ptPoint1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//抬笔移动到点(x,y)
|
||||||
|
void VectorFont::MoveTo(long x, long y)
|
||||||
|
{
|
||||||
|
if(x == 0){}
|
||||||
|
if(y == 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
//抬笔移动到点ptPoint
|
||||||
|
void VectorFont::MoveTo(QPoint ptPoint)
|
||||||
|
{
|
||||||
|
emit siMoveTo(true,ptPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
//从当前位置画线到点(x,y)
|
||||||
|
void VectorFont::LineTo(long x, long y)
|
||||||
|
{
|
||||||
|
if(x == 0){}
|
||||||
|
if(y == 0){}
|
||||||
|
}
|
||||||
|
|
||||||
|
//从当前位置画线到点ptPoint
|
||||||
|
void VectorFont::LineTo(QPoint ptPoint)
|
||||||
|
{
|
||||||
|
emit siLineTo(false,ptPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
//从(x,y)点开始写字,nCount为字节数
|
||||||
|
void VectorFont::TextOutString(int x, int y, const char* lpszString, int nCount)
|
||||||
|
{
|
||||||
|
QString strEnglish,strChinese;
|
||||||
|
QFile fileEnglish,fileChinese;
|
||||||
|
BYTE *pbyData;
|
||||||
|
int nLeft;
|
||||||
|
BYTE byByte1,byByte2;
|
||||||
|
WORD wCharCode;
|
||||||
|
int nIndex1,nIndex2,nIndex3,nIndex4;
|
||||||
|
bool bEnglishChar;
|
||||||
|
|
||||||
|
strEnglish = m_workPath + "english.fnt";
|
||||||
|
strChinese = m_workPath + "Hz.fnt";
|
||||||
|
|
||||||
|
fileEnglish.setFileName(strEnglish);
|
||||||
|
if(!fileEnglish.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qDebug() <<"file open failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileChinese.setFileName(strChinese);
|
||||||
|
if(!fileChinese.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qDebug() <<"file open failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nLeft=0;
|
||||||
|
nIndex1=0;
|
||||||
|
while (nIndex1 < nCount)
|
||||||
|
{
|
||||||
|
pbyData=NULL;
|
||||||
|
byByte1=(BYTE)lpszString[nIndex1];
|
||||||
|
if ((byByte1 >= 128) && ((nIndex1+1) < nCount))
|
||||||
|
{
|
||||||
|
bEnglishChar=false;
|
||||||
|
|
||||||
|
nIndex1++;
|
||||||
|
byByte2=(BYTE)lpszString[nIndex1];
|
||||||
|
wCharCode=(((WORD)byByte1) << 8) | (WORD)byByte2;
|
||||||
|
|
||||||
|
nIndex2=0;
|
||||||
|
nIndex3=m_nChinese_char_count - 1;
|
||||||
|
if (m_pChinese_char[nIndex2].m_wCharCode == wCharCode) nIndex4=nIndex2;
|
||||||
|
else if (m_pChinese_char[nIndex3].m_wCharCode == wCharCode) nIndex4=nIndex3;
|
||||||
|
else nIndex4=(nIndex2 + nIndex3) / 2;
|
||||||
|
while (((nIndex3 - nIndex2) > 1) &&
|
||||||
|
(m_pChinese_char[nIndex4].m_wCharCode != wCharCode))
|
||||||
|
{
|
||||||
|
if (m_pChinese_char[nIndex4].m_wCharCode > wCharCode)
|
||||||
|
{
|
||||||
|
nIndex3=nIndex4;
|
||||||
|
if (nIndex2 > nIndex3) break;
|
||||||
|
nIndex4=(nIndex2 + nIndex3) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nIndex2=nIndex4;
|
||||||
|
if (nIndex2 > nIndex3) break;
|
||||||
|
nIndex4=(nIndex2 + nIndex3) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((m_pChinese_char[nIndex4].m_wCharCode == wCharCode) &&
|
||||||
|
(m_pChinese_char[nIndex4].m_wBytes > 0))
|
||||||
|
{
|
||||||
|
pbyData=new BYTE[m_pChinese_char[nIndex4].m_wBytes + 1];
|
||||||
|
|
||||||
|
fileChinese.seek(m_pChinese_char[nIndex4].m_dwPosition);
|
||||||
|
fileChinese.read((char*)pbyData,m_pChinese_char[nIndex4].m_wBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bEnglishChar=true;
|
||||||
|
wCharCode=(WORD)byByte1;
|
||||||
|
nIndex2=0;
|
||||||
|
nIndex3=m_nEnglish_char_count - 1;
|
||||||
|
if (m_pEnglish_char[nIndex2].m_wCharCode == wCharCode) nIndex4=nIndex2;
|
||||||
|
else if (m_pEnglish_char[nIndex3].m_wCharCode == wCharCode) nIndex4=nIndex3;
|
||||||
|
else nIndex4=(nIndex2 + nIndex3) / 2;
|
||||||
|
while (((nIndex3 - nIndex2) > 1) &&
|
||||||
|
(m_pEnglish_char[nIndex4].m_wCharCode != wCharCode))
|
||||||
|
{
|
||||||
|
if (m_pEnglish_char[nIndex4].m_wCharCode > wCharCode)
|
||||||
|
{
|
||||||
|
nIndex3=nIndex4;
|
||||||
|
if (nIndex2 > nIndex3) break;
|
||||||
|
nIndex4=(nIndex2 + nIndex3) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nIndex2=nIndex4;
|
||||||
|
if (nIndex2 > nIndex3) break;
|
||||||
|
nIndex4=(nIndex2 + nIndex3) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((m_pEnglish_char[nIndex4].m_wCharCode == wCharCode) &&
|
||||||
|
(m_pEnglish_char[nIndex4].m_wBytes > 0)) {
|
||||||
|
pbyData=new BYTE[m_pEnglish_char[nIndex4].m_wBytes + 1];
|
||||||
|
|
||||||
|
fileEnglish.seek(m_pEnglish_char[nIndex4].m_dwPosition);
|
||||||
|
fileEnglish.read((char*)pbyData,m_pEnglish_char[nIndex4].m_wBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pbyData != NULL)
|
||||||
|
{
|
||||||
|
if (bEnglishChar)
|
||||||
|
{
|
||||||
|
PlotChar(QPoint(x,y),pbyData,m_pEnglish_char[nIndex4].m_wBytes,nLeft,0,m_nHeight_C);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlotChar(QPoint(x,y),pbyData,m_pChinese_char[nIndex4].m_wBytes,nLeft,0,m_nInternalLeading_E + m_nHeight_E);
|
||||||
|
}
|
||||||
|
delete []pbyData;
|
||||||
|
if (bEnglishChar) nLeft=nLeft + m_pEnglish_char[nIndex4].m_wWidth * m_nHeight_C;
|
||||||
|
else nLeft=nLeft + m_nWidth_C * (m_nInternalLeading_E + m_nHeight_E);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (bEnglishChar) nLeft=nLeft + m_pEnglish_char[0].m_wWidth * m_nHeight_C;
|
||||||
|
else nLeft=nLeft + m_nWidth_C * (m_nInternalLeading_E + m_nHeight_E);
|
||||||
|
}
|
||||||
|
|
||||||
|
nIndex1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
double dXC,dYC,dRadius;
|
||||||
|
double dx,dy;
|
||||||
|
double dAngleS,dAngleE,dAngle,dStep;
|
||||||
|
double dCos,dSin;
|
||||||
|
int nCount;
|
||||||
|
|
||||||
|
dXC=((double)nLeftRect + (double)nRightRect) / 2.0;
|
||||||
|
dYC=((double)nTopRect + (double)nBottomRect) / 2.0;
|
||||||
|
dRadius=((double)nRightRect - (double)nLeftRect) / 2.0;
|
||||||
|
|
||||||
|
dAngleS=angle_2(dXC,dYC,(double)nXStartArc,(double)nYStartArc);
|
||||||
|
dAngleE=angle_2(dXC,dYC,(double)nXEndArc,(double)nYEndArc);
|
||||||
|
while (dAngleE >= dAngleS) dAngleE=dAngleE - 2.0 * PI;
|
||||||
|
|
||||||
|
if ((nXStartArc == nXEndArc) && (nYStartArc == nYEndArc))
|
||||||
|
{
|
||||||
|
dAngleS=0.0;
|
||||||
|
dAngleE=-2.0 * PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
dSin=qSin(dAngleS);
|
||||||
|
dCos=qCos(dAngleS);
|
||||||
|
dx=dRadius * dCos + dXC;
|
||||||
|
dy=dRadius * dSin + dYC;
|
||||||
|
MoveTo(dx+0.5,dy+0.5);
|
||||||
|
|
||||||
|
nCount=120;
|
||||||
|
dStep=PI / 180.0 * (360.0 / (double)nCount); //3度
|
||||||
|
dAngle=dAngleS;
|
||||||
|
while (dAngle > dAngleE)
|
||||||
|
{
|
||||||
|
dAngle=dAngle - dStep;
|
||||||
|
if (dAngle < dAngleE) dAngle=dAngleE;
|
||||||
|
dSin=qSin(dAngle);
|
||||||
|
dCos=qCos(dAngle);
|
||||||
|
dx=dRadius * dCos + dXC;
|
||||||
|
dy=dRadius * dSin + dYC;
|
||||||
|
LineTo(dx+0.5,dy+0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint VectorFont::GetNextCoodinate(WORD wDirection,WORD wLength,QPoint ptPoint)
|
||||||
|
{
|
||||||
|
QPoint ptPoint1;
|
||||||
|
|
||||||
|
switch (wDirection) {
|
||||||
|
case 0:
|
||||||
|
ptPoint1.setX( ptPoint.x() + (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ptPoint1.setX(ptPoint.x() + (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength/2);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ptPoint1.setX(ptPoint.x() + (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ptPoint1.setX(ptPoint.x() + (int)wLength/2);
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
ptPoint1.setX(ptPoint.x());
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength/2);
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() + (int)wLength/2);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y());
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength/2);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength);
|
||||||
|
break;
|
||||||
|
case 11:
|
||||||
|
ptPoint1.setX(ptPoint.x() - (int)wLength/2);
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
|
ptPoint1.setX(ptPoint.x());
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength);
|
||||||
|
break;
|
||||||
|
case 13:
|
||||||
|
ptPoint1.setX(ptPoint.x() + (int)wLength/2);
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength);
|
||||||
|
break;
|
||||||
|
case 14:
|
||||||
|
ptPoint1.setX(ptPoint.x() + (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength);
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
|
ptPoint1.setX(ptPoint.x() + (int)wLength);
|
||||||
|
ptPoint1.setY(ptPoint.y() - (int)wLength/2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptPoint1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//求两点确定的直线与X轴的夹角,在[0,2pi)之间
|
||||||
|
//输入参数:
|
||||||
|
// (startx,starty) 起点
|
||||||
|
// (endx,endy) 终点
|
||||||
|
//返回值:
|
||||||
|
// 夹角
|
||||||
|
double VectorFont::angle_2(int startx,int starty,int endx,int endy)
|
||||||
|
{
|
||||||
|
//直线与X轴之间的夹角 X轴向量OE(1,0)
|
||||||
|
double dAngle = 0;
|
||||||
|
if((endx == startx) && (endy == starty))
|
||||||
|
{
|
||||||
|
return dAngle;
|
||||||
|
}
|
||||||
|
//求直线的向量坐标
|
||||||
|
double dX = endx - startx;
|
||||||
|
double dY = endy - starty;
|
||||||
|
dAngle = qAcos((dX)/(qSqrt(dX*dX + dY*dY)));
|
||||||
|
return dAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////// 计算三点定圆时的圆心和半径 ///////////////////////////
|
||||||
|
// 输入参数:三个样点(x1,y1),(x2,y2),(x3,y3)
|
||||||
|
// 算法描述:
|
||||||
|
// 过(x1,y1),(x2,y2)的中点作垂线L1,
|
||||||
|
// 过(x2,y2),(x3,y3)的中点作垂线L2,
|
||||||
|
// 求L1,L2的交点.
|
||||||
|
// 输出参数:
|
||||||
|
// 如果不能形成圆返回false,
|
||||||
|
// 否则返回true其中圆心为(cx,cy),半径=cr.
|
||||||
|
// 按逆时针方向画弧时,如cr>0 则(x1,y1)是起点,(x3,y3)是终点,
|
||||||
|
// 如cr<0 则(x3,y3)是起点,(x1,y1)是终点.
|
||||||
|
// 特别说明:此处所说的逆时针是指显示器而言,如果对于对X向右为正,
|
||||||
|
// Y向上为正的坐标系来说此处是顺时针
|
||||||
|
//bool CircleCR(int x1,int y1,int x2,int y2,int x3,int y3,int& cx,int& cy,int& cr);
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool VectorFont::CircleCR(double x1,double y1,double x2,double y2,double x3,double y3,double& cx,double& cy,double& cr)
|
||||||
|
{
|
||||||
|
double a1,b1,c1,a2,b2,c2;
|
||||||
|
if(((x1 ==x2) && (y1==y2)) || ((x1 ==x3) && (y1==y3)) || ((x2 ==x3) && (y2==y3)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
a1 = x1 - x2;
|
||||||
|
b1 = y1 - y2;
|
||||||
|
c1 = -a1 * (x1 + x2) / 2.0 - b1 * (y1 + y2)/2.0;
|
||||||
|
a2 = x3 - x2;
|
||||||
|
b2 = y3 - y2;
|
||||||
|
c2 = -a2 * (x2 + x3) / 2.0 - b2 * (y2 + y3)/2.0;
|
||||||
|
|
||||||
|
double D = a1*b2 - a2*b1;
|
||||||
|
if(D == 0)//两直线平行
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cx = (b1*c2 - b2*c1)/D;
|
||||||
|
cy = (c1*a2 - c2*a1)/D;
|
||||||
|
|
||||||
|
//用圆心和其中一个点求距离得到半径:
|
||||||
|
cr = qSqrt((cx - x1)*(cx - x1) + (cy - y1)*(cy - y1));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
132
datafile/hpgl/vectorfont.h
Normal file
132
datafile/hpgl/vectorfont.h
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#ifndef VECTORFONT_H
|
||||||
|
#define VECTORFONT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPoint>
|
||||||
|
#include "typedef.h"
|
||||||
|
|
||||||
|
class CChinese_char
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WORD m_wCharCode;
|
||||||
|
WORD m_wBytes;
|
||||||
|
DWORD m_dwPosition;
|
||||||
|
|
||||||
|
CChinese_char()
|
||||||
|
{
|
||||||
|
m_wCharCode=0;
|
||||||
|
m_wBytes=0;
|
||||||
|
m_dwPosition=0;
|
||||||
|
}
|
||||||
|
CChinese_char(const CChinese_char &a)
|
||||||
|
{
|
||||||
|
m_wCharCode=a.m_wCharCode;
|
||||||
|
m_wBytes=a.m_wBytes;
|
||||||
|
m_dwPosition=a.m_dwPosition;
|
||||||
|
}
|
||||||
|
CChinese_char(WORD wCharCode,WORD wBytes,DWORD dwPosition)
|
||||||
|
{
|
||||||
|
m_wCharCode=wCharCode;
|
||||||
|
m_wBytes=wBytes;
|
||||||
|
m_dwPosition=dwPosition;
|
||||||
|
}
|
||||||
|
~CChinese_char() {}
|
||||||
|
CChinese_char operator=(const CChinese_char &a)
|
||||||
|
{
|
||||||
|
m_wCharCode=a.m_wCharCode;
|
||||||
|
m_wBytes=a.m_wBytes;
|
||||||
|
m_dwPosition=a.m_dwPosition;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CEnglish_char
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WORD m_wCharCode;
|
||||||
|
WORD m_wBytes;
|
||||||
|
WORD m_wWidth;
|
||||||
|
DWORD m_dwPosition;
|
||||||
|
|
||||||
|
CEnglish_char()
|
||||||
|
{
|
||||||
|
m_wCharCode=0;
|
||||||
|
m_wBytes=0;
|
||||||
|
m_wWidth=0;
|
||||||
|
m_dwPosition=0;
|
||||||
|
}
|
||||||
|
CEnglish_char(const CEnglish_char &a)
|
||||||
|
{
|
||||||
|
m_wCharCode=a.m_wCharCode;
|
||||||
|
m_wBytes=a.m_wBytes;
|
||||||
|
m_wWidth=a.m_wWidth;
|
||||||
|
m_dwPosition=a.m_dwPosition;
|
||||||
|
}
|
||||||
|
CEnglish_char(WORD wCharCode,WORD wBytes,WORD wWidth,DWORD dwPosition)
|
||||||
|
{
|
||||||
|
m_wCharCode=wCharCode;
|
||||||
|
m_wBytes=wBytes;
|
||||||
|
m_wWidth=wWidth;
|
||||||
|
m_dwPosition=dwPosition;
|
||||||
|
}
|
||||||
|
~CEnglish_char() {}
|
||||||
|
CEnglish_char operator=(const CEnglish_char &a)
|
||||||
|
{
|
||||||
|
m_wCharCode=a.m_wCharCode;
|
||||||
|
m_wBytes=a.m_wBytes;
|
||||||
|
m_wWidth=a.m_wWidth;
|
||||||
|
m_dwPosition=a.m_dwPosition;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
class VectorFont : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit VectorFont(QObject *parent = 0);
|
||||||
|
~VectorFont();
|
||||||
|
void IniVectorFont();
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void siLineTo(bool bl,QPoint point);
|
||||||
|
void siMoveTo(bool bl,QPoint point);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
protected:
|
||||||
|
|
||||||
|
double m_iDPMM; //长度数据单位:m_iDPMM(每毫米点)
|
||||||
|
double m_dRake; //倾斜角(第1个字符原点到最后1个字符原点的连线的角度),单位:弧度
|
||||||
|
|
||||||
|
QString m_workPath;
|
||||||
|
|
||||||
|
//QList <CChinese_char> m_aChinese_char;
|
||||||
|
//QList <CEnglish_char> m_aEnglish_char;
|
||||||
|
CChinese_char *m_pChinese_char;
|
||||||
|
CEnglish_char *m_pEnglish_char;
|
||||||
|
int m_nChinese_char_count;
|
||||||
|
int m_nEnglish_char_count;
|
||||||
|
int m_nInternalLeading_E,m_nHeight_E,m_nDescent_E; //m_nHeight_E是windows中字体的Ascent-InternalLeading
|
||||||
|
int m_nHeight_C,m_nWidth_C;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void PlotChar(QPoint ptPointLU,BYTE*pbyData,WORD wBytes,int nLeft,int nDown,int nFontScale);
|
||||||
|
QPoint CPToLP(QPoint ptCP,int nHeight,QPoint ptPointLU,double dSin,double dCos,double dScale);
|
||||||
|
void TextOutString(int x, int y, const char* lpszString, int nCount);
|
||||||
|
void Arc(int nLeftRect,int nTopRect,int nRightRect,int nBottomRect,int nXStartArc,int nYStartArc,int nXEndArc,int nYEndArc);
|
||||||
|
QPoint GetNextCoodinate(WORD wDirection,WORD wLength,QPoint ptPoint);
|
||||||
|
void MoveTo(QPoint ptPoint);
|
||||||
|
void MoveTo(long x,long y);
|
||||||
|
void LineTo(QPoint ptPoint);
|
||||||
|
void LineTo(long x,long y);
|
||||||
|
double angle_2(int startx,int starty,int endx,int endy);
|
||||||
|
bool CircleCR(double x1,double y1,double x2,double y2,double x3,double y3,double& cx,double& cy,double& cr);
|
||||||
|
|
||||||
|
double m_dFontHeight; //字的高度
|
||||||
|
double m_dFontAngle;//指定每行文本输出时相对于设备x轴的角度,其单位为1/10度
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VECTORFONT_H
|
||||||
43
items/assistitem.cpp
Normal file
43
items/assistitem.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "assistitem.h"
|
||||||
|
|
||||||
|
AssistItem::AssistItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssistItem::~AssistItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
AssistItem::AssistItem(const AssistItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
AssistItem & AssistItem::operator= (const AssistItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssistItem::clean()
|
||||||
|
{
|
||||||
|
m_macType = 0;
|
||||||
|
m_showPriority = 0;
|
||||||
|
m_name.clear();
|
||||||
|
m_topImageName.clear();
|
||||||
|
m_enumFunction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssistItem::copyData(const AssistItem &item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_macType = item.m_macType;
|
||||||
|
this->m_showPriority = item.m_showPriority;
|
||||||
|
this->m_name = item.m_name;
|
||||||
|
this->m_topImageName = item.m_topImageName;
|
||||||
|
this->m_enumFunction = item.m_enumFunction;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
items/assistitem.h
Normal file
36
items/assistitem.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef ASSISTITEM_H
|
||||||
|
#define ASSISTITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class AssistItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AssistItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
~AssistItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
AssistItem(const AssistItem & item);
|
||||||
|
AssistItem & operator= (const AssistItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const AssistItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_macType; // 机器类型
|
||||||
|
int m_showPriority; // 显示优先级
|
||||||
|
QString m_name; // label名称
|
||||||
|
QString m_topImageName; // 顶图图标logo名称
|
||||||
|
int m_enumFunction; // 对应的事件的枚举值
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ASSISTITEM_H
|
||||||
333
items/cmdconfig.h
Normal file
333
items/cmdconfig.h
Normal file
@ -0,0 +1,333 @@
|
|||||||
|
#ifndef CMDCONFIG_H
|
||||||
|
#define CMDCONFIG_H
|
||||||
|
|
||||||
|
//点击触发型参数枚举(绣花机超级用户参数、冲缝绣产线软件设置参数、网络管理参数)
|
||||||
|
enum CLICK_ALL_FUNCTION {
|
||||||
|
ROOT_HMICONFIGURATION = 0, //界面配置
|
||||||
|
ROOT_MACHINEPARA, //机器参数
|
||||||
|
ROOT_WORKPARA, //工作参数
|
||||||
|
ROOT_CLEARPATTERN, //花样总清
|
||||||
|
ROOT_VERSIONRECOVERY, //版本恢复
|
||||||
|
ROOT_DEBUGMODE, //界面进入调试模式
|
||||||
|
ROOT_RESOLUTION, //分辨率
|
||||||
|
ROOT_MACTYPE, //机器类型
|
||||||
|
ROOT_PRODUCTTYPE, //产品类型
|
||||||
|
ROOT_SHUTTLECHANGE, //自动换梭
|
||||||
|
ROOT_WATERMARKSET, //主背景水印设置(是否带水印)
|
||||||
|
ROOT_WIFI,
|
||||||
|
ROOT_PARASORTSET, //参数分类设置(是否分类)
|
||||||
|
ROOT_HMIDECRYPT, //界面解密
|
||||||
|
ROOT_CHANGEPASSWORD, //修改一级密码
|
||||||
|
ROOT_IOTCONFIGURATION, //物联网配置-物联网配置
|
||||||
|
ROOT_GATEWAYCONNECTIONMETHOD, //物联网配置-网关连接方式
|
||||||
|
ROOT_RACKNUMBERINPUT, //物联网配置-机架号输入
|
||||||
|
ROOT_NETWORKSETTINGS, //物联网配置-网络设置
|
||||||
|
ROOT_DELIVERYTIME, //物联网配置-工厂预计交货时间
|
||||||
|
ROOT_DEBUGPROGRESS, //物联网配置-调试进度
|
||||||
|
ROOT_DELETEINI, //删除配置文件
|
||||||
|
ROOT_DELETE_DEF_PATH, //删除默认文件路径
|
||||||
|
PSE_SOFTWAREPARA_IMPORTPARA, //参数导入
|
||||||
|
PSE_SOFTWAREPARA_EXPORTPARA, //参数导出
|
||||||
|
PSE_SOFTWAREPARA_HMIUPDATE, //界面升级
|
||||||
|
PSE_SOFTWAREPARA_MCUPDATE, //主控升级
|
||||||
|
PSE_SOFTWAREPARA_EXIT, //退出程序
|
||||||
|
|
||||||
|
ROOT_KNIFE_MODEL, //刀压设置模式
|
||||||
|
ROOT_MACHINE_MODEL, //机型模式
|
||||||
|
ROOT_X_CORRECTVALUE, //X修正值
|
||||||
|
ROOT_Y_CORRECTVALUE, //Y修正值
|
||||||
|
ROOT_MAXSPEED_MAINSEWWORK, //主轴缝纫工作最高转速
|
||||||
|
ROOT_IF_SPLIT_STEP //是否分割针步
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MC_TYPE { NUM1 = 1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9 };//板卡号
|
||||||
|
|
||||||
|
enum ENUM_ALGORITHM {
|
||||||
|
FIT_SMALL, //拟合小针步
|
||||||
|
MINIMUM_STEP, //直线最小步长
|
||||||
|
MAXIMUM_STEP, //直线最大步长
|
||||||
|
JUDGMENT_DEGREE, //圆弧转角判断度数
|
||||||
|
ARC_COMPENSATION, //圆弧补偿步长
|
||||||
|
ARC_COMPENSATION_1, //切刀1圆弧补偿半径
|
||||||
|
ARC_COMPENSATION_2, //切刀2圆弧补偿半径
|
||||||
|
|
||||||
|
CUT_SPD_MINPPS, //最小切割速度
|
||||||
|
CUT_SPD_MAXPPS, //最大切割速度
|
||||||
|
CUT_ADD_PPSG, //切割加速度
|
||||||
|
CUT_SLOW_ANGLE, //切割降速最小偏差角度
|
||||||
|
CUT_WORK_MINADD, //工作最小加速度
|
||||||
|
CUT_RNF1_COMP, //抬刀补偿
|
||||||
|
CUT_RNF2_COMP, //落刀补偿
|
||||||
|
|
||||||
|
//边走边裁
|
||||||
|
CUT_CRUTCH_ANG, //拐点转角判断度数,单位:10000弧度
|
||||||
|
CUT_LINE_STP, //分割数据步长,单位0.01mm
|
||||||
|
CUT_X_LENGH, //X向可切割长度,单位0.01mm
|
||||||
|
CUT_RNF_COMP, //圆刀退刀补偿 ,单位0.01mm
|
||||||
|
CUT_Vert_COMP, //切割垂直补偿 ,单位0.01mm
|
||||||
|
CUT_ENABLE_BRUSH, //圆刀退刀补偿 ,单位0.01mm
|
||||||
|
};
|
||||||
|
|
||||||
|
//此头文件定义了常用功能的枚举
|
||||||
|
enum SHORTCUT_FUNCTION {
|
||||||
|
FUN_ALLTOZERO = 1, // 全部归零
|
||||||
|
FUN_SPINDLEJOG, // 主轴点动
|
||||||
|
FUN_SPINDLEENABLE, // 主轴使能
|
||||||
|
FUN_SPINDLEDISABLE, // 主轴失能
|
||||||
|
FUN_SPINDLETEST, // 主轴研车
|
||||||
|
FUN_SPINDLEROTATE, // 主轴旋转
|
||||||
|
FUN_BACKWORKPOINT, // 回工作点
|
||||||
|
FUN_CUTTINGPOINT, // 回切割点
|
||||||
|
FUN_BACKTOORIGIN, // 回原点
|
||||||
|
FUN_SETOFFSETPOINT, // 定偏移点
|
||||||
|
FUN_BACKOFFSETPOINT, // 回偏移点
|
||||||
|
FUN_SETSTARTPOINT, // 定起始点
|
||||||
|
FUN_BACKSTARTPOINT, // 回起始点
|
||||||
|
FUN_SETFEEDINGPOINT, //定上料点
|
||||||
|
FUN_BACKFEEDINGPOINT, //回上料点
|
||||||
|
FUN_CHECKFRAME, // 边框检查
|
||||||
|
FUN_FORWARDORBACK, // 前进回退
|
||||||
|
FUN_SIMULATEFRAME, //空走边框
|
||||||
|
FUN_PROCESSRESET, //流程复位
|
||||||
|
FUN_MANUALOIL, //手动加油
|
||||||
|
FUN_PATTERNSELECT, // 花样选择
|
||||||
|
FUN_SEWAUTOCHANGESHUTTLE, //自动换梭
|
||||||
|
FUN_SEWBUFF, //缝纫状态
|
||||||
|
FUN_SHUTTLEDISKBUFF, //换梭盘状态
|
||||||
|
FUN_BACKTHREADPOINT, //回穿线点
|
||||||
|
FUN_KNIFE_COLLECT,//刀压采集
|
||||||
|
FUN_KNIFE_TEST,//刀压测试
|
||||||
|
FUN_FAN_AREA,//风机区域
|
||||||
|
FUN_PEN_UP,//画笔上升
|
||||||
|
FUN_PEN_DOWN,//画笔下降
|
||||||
|
FUN_SET_KNIFETEST_POS,//设置刀压检测位置
|
||||||
|
FUN_DISPLAY_COLLECTED_DATA,//显示采集数据
|
||||||
|
FUN_CROSS_CUT,//横切
|
||||||
|
FUN_SETANCHORPOINT, // 定定位点(服装机)
|
||||||
|
FUN_BACKANCHORPOINT, // 回定位点(服装机)
|
||||||
|
FUN_CUT_SETANCHORPOINT,
|
||||||
|
FUN_BACKSHUTTLE, //回换梭位(服装机)
|
||||||
|
FUN_NEEDLESHUTTLERESET, //针梭校对(服装机)
|
||||||
|
FUN_BACKZEROPOINT, //回零点
|
||||||
|
FUN_GOTO_FINISH, //回结束点
|
||||||
|
FUN_SHUTTLETOHEAD, //将旋梭从梭盘到机头
|
||||||
|
FUN_HEADTOSHUTTLE, //将旋梭从机头到梭盘
|
||||||
|
FUN_COUNTRESET, //底线计数清零
|
||||||
|
FUN_OUTPUTRESET, //产量清零
|
||||||
|
FUN_NEDDLEZEROPOS, //对针零位
|
||||||
|
FUN_SHUTTLEZEROPOS, //对梭零位
|
||||||
|
FUN_MT_ALLZ, // 所有主轴 零位
|
||||||
|
FUN_MT_ALLG, // 所有主轴 勾线
|
||||||
|
FUN_MT_ALLM, // 所有主轴 点动
|
||||||
|
FUN_MAINSHAFT_ADJUST, // 针梭校对
|
||||||
|
FUN_SIMULATED_STATUS, // 模拟缝纫状态
|
||||||
|
FUN_MANUAL_THREAD_CUTTING, // 手动剪线
|
||||||
|
FUN_HEAD_LIFTUPDOWN, //机头升降
|
||||||
|
FUN_HEAD_LIFTING, //机头上升
|
||||||
|
FUN_HEAD_LOWERING, //机头下降
|
||||||
|
FUN_HEAD_LIFTING2, //机头上升2
|
||||||
|
FUN_HEAD_LOWERING2, //机头下降2
|
||||||
|
FUN_WORK_HEAD_SET, //工作机头设置
|
||||||
|
FUN_NS_RESET,//缝纫针梭复位
|
||||||
|
FUN_GOTO_FEEDT,//回穿线点
|
||||||
|
FUN_MAKEUP_NOHEAD, // 取消补缝
|
||||||
|
FUN_MAKEUP_HEAD1, // 机头1补缝
|
||||||
|
FUN_MAKEUP_HEAD2, // 机头2补缝
|
||||||
|
FUN_MAKEUP_HEAD3, // 机头3补缝
|
||||||
|
FUN_MAKEUP_HEAD4, // 机头4补缝
|
||||||
|
FUN_MAKEUP_HEAD5, // 机头5补缝
|
||||||
|
ASSIST_ThCutAct1,//机头1 剪线动作
|
||||||
|
ASSIST_ThCutAct2,//机头2 剪线动作
|
||||||
|
ASSIST_ThCutAct3,//机头3 剪线动作
|
||||||
|
ASSIST_ThCutAct4,//机头4 剪线动作
|
||||||
|
ASSIST_ThCutAct5,//机头5 剪线动作
|
||||||
|
FUN_SPD_SELECT,//速度选择
|
||||||
|
FUN_MS_TO_ANGLE,//主轴去指定角度
|
||||||
|
FUN_WIRE_MS_RUN,//主轴研车
|
||||||
|
FUN_ROT_TO_ANGLE,//旋转电机去指定角度
|
||||||
|
FUN_AUTO_PULL,//自动拉料
|
||||||
|
FUN_CUT_UD,//剪底面线
|
||||||
|
FUN_CUT_WIRE,//剪电阻丝
|
||||||
|
FUN_GOTO_PULLPOS,//回拉料起始点
|
||||||
|
FUN_JAW_WORK,//夹布工作状态
|
||||||
|
FUN_JAW_FEED,//夹布上料状态
|
||||||
|
FUN_ZIGZAG_POS1,//去摆动位1
|
||||||
|
FUN_ZIGZAG_POS2,//去摆动位2
|
||||||
|
FUN_YPB_MOVE,//手动拉料
|
||||||
|
FUN_AUTO_CHANGE_ONE_SHUT,//自动换一个梭
|
||||||
|
FUN_INSTALL_FIRST_BOBBIN,//安装第一个梭壳
|
||||||
|
FUN_SHUT_FROM_PLATE_TO_HEAD,//将旋梭从梭盘拿到机头
|
||||||
|
FUN_SHUT_FROM_HEAD_TO_PLATE,//将旋梭从机头拿到梭盘
|
||||||
|
FUN_SHUT_INTO_TAKE_PLATE,//进入更换梭盘状态
|
||||||
|
FUN_SHUT_INTO_INDX_STA,//进入缝纫状态
|
||||||
|
FUN_SHUT_FEED_STATE,//进入送料状态
|
||||||
|
FUN_SHUT_BACK_STATE,//进入收料状态
|
||||||
|
FUN_SHUIILE_LINE,//梭芯底线显示
|
||||||
|
|
||||||
|
//飞梭机
|
||||||
|
FUN_STARTWORK, //启动工作
|
||||||
|
FUN_PAUSEWORK, //暂停
|
||||||
|
FUN_HOOKPOS, //主轴去勾线位
|
||||||
|
FUN_PARKPOS, //主轴去停车位
|
||||||
|
|
||||||
|
FUN_BOARD_LOW_POSITION, // 翻板低位
|
||||||
|
FUN_BOARD_CENTER_POSITION, // 翻板中位
|
||||||
|
|
||||||
|
FUN_RESET_ALL, // 全部复位
|
||||||
|
FUN_ONE_PULLING, // 一键拉料
|
||||||
|
FUN_ONE_CROSS_CUT, // 一键横切
|
||||||
|
FUN_CTB_INTO_SEW_STA, // 进入绗缝状态
|
||||||
|
FUN_CTB_INTO_PULL_STA, // 进入拉料状态
|
||||||
|
FUN_CTB_ONEKEY_CROSSCUT, // 全自动缝纫机一键横切
|
||||||
|
FUN_BOTTOM_CLEARING_COUNT, // 底线清空计数
|
||||||
|
|
||||||
|
//双头组合机型
|
||||||
|
FUN_SET_WORK_HEAD, //设置工作机头 九宫格
|
||||||
|
|
||||||
|
FUN_NULL // 无功能 无功能应该放在最后一位,因为常用功能得最大值就是无功能,否则无法一一对应
|
||||||
|
};
|
||||||
|
|
||||||
|
//辅助功能的枚举
|
||||||
|
enum ASSIST_FUNCTION {
|
||||||
|
ASSIST_SENSOR = 1, // 传感器信号
|
||||||
|
ASSIST_CONTROLACTION, // 控制动作
|
||||||
|
ASSIST_HMIUPGRADE, // 界面升级
|
||||||
|
ASSIST_MCUPGRADE, // 主控升级
|
||||||
|
ASSIST_PARAIMPORT, // 参数导入
|
||||||
|
ASSIST_PARAEXPORT, // 参数导出
|
||||||
|
ASSIST_SOFTWARESET, // 软件设置
|
||||||
|
ASSIST_AUTHORIZATION, // 软件授权
|
||||||
|
ASSIST_NETWORK, // 网络管理
|
||||||
|
ASSIST_WIFI,
|
||||||
|
ASSIST_TIMESET, // 时间设置
|
||||||
|
ASSIST_PRODUCTSTATICS, // 生产统计
|
||||||
|
ASSIST_LOGFILE,//文件日志
|
||||||
|
ASSIST_ERRORLOG,//错误日志
|
||||||
|
ASSIST_BREAKAGELOG,//断线日志
|
||||||
|
ASSIST_MCVERSION, // 版本信息
|
||||||
|
ASSIST_BOTTOMLINEDETECT, //底线检测
|
||||||
|
ASSIST_FACELINEDETECT, //面线检测
|
||||||
|
ASSIST_SPINDLETEST, //主轴研车
|
||||||
|
ASSIST_CHANGEASHUTTLE ,// 自动换一个梭
|
||||||
|
ASSIST_ROOT, //超级用户
|
||||||
|
ASSIST_SHUTDOWN, //关机
|
||||||
|
ASSIST_BOTTOMLINECOUNTRESET, // 底线计数复位
|
||||||
|
ASSIST_DEBUGINFO,//调试信息
|
||||||
|
ASSIST_ScanTest,//扫码测试
|
||||||
|
ASSIST_HMIBACKUPSUPGRADE, // 界面还原
|
||||||
|
ASSIST_NULL // 无功能
|
||||||
|
};
|
||||||
|
|
||||||
|
//花样设置功能的枚举
|
||||||
|
enum PATTERNSET_FUNCTION {
|
||||||
|
PATTERNSET_PATTERNSELECT = 1, // 花样选择
|
||||||
|
PATTERNSET_PATTERNPARA, // 花样参数
|
||||||
|
PATTERNSET_PATTERNCOLOR, // 花样色序
|
||||||
|
PATTERNSET_PATTERNIMPORT, // 花样导入
|
||||||
|
PATTERNSET_PATTERNEXPORT, // 花样导出
|
||||||
|
PATTERNSET_PATTERNDELETE, // 花样删除
|
||||||
|
PATTERNSET_ALGORITHMPARA, // 平板切割算法参数
|
||||||
|
PATTERNSET_PATTERNEDIT, // 花样编辑
|
||||||
|
PATTERNSET_NEEDLEPREVIEW, // 排针预览
|
||||||
|
PATTERNSET_LINEGENER, // 线迹生成
|
||||||
|
PATTERNSET_NULL // 无功能
|
||||||
|
};
|
||||||
|
|
||||||
|
//参数设置参数类型的枚举
|
||||||
|
enum PARASET_FUNCTION {
|
||||||
|
PARASET_POSITION = 1, // 位置参数
|
||||||
|
PARASET_SPEED, // 速度参数
|
||||||
|
PARASET_ACTION, // 动作参数
|
||||||
|
PARASET_DETECT, // 检测参数
|
||||||
|
PARASET_SETTING , // 工作参数
|
||||||
|
PARASET_ALL , // 全部参数
|
||||||
|
PARASET_SHUTTLE //自动换梭参数
|
||||||
|
};
|
||||||
|
|
||||||
|
enum OUTCONTROL_FUN {
|
||||||
|
OUTCONTROL_ENABLE = 1, // 使能
|
||||||
|
OUTCONTROL_DISABLE, // 失能
|
||||||
|
OUTCONTROL_MS_ENABLE, // 主轴电机使能
|
||||||
|
OUTCONTROL_MS_DISABLE, // 主轴电机失能
|
||||||
|
OUTCONTROL_JOGP, // 正转
|
||||||
|
OUTCONTROL_JOGN, // 反转
|
||||||
|
OUTCONTROL_STOP, // 停止
|
||||||
|
OUTCONTROL_ZERO, // 归零
|
||||||
|
OUTCONTROL_LEFT, // 左位
|
||||||
|
OUTCONTROL_MIDDLE, // 中位
|
||||||
|
OUTCONTROL_RIGHT, // 右位
|
||||||
|
OUTCONTROL_UP, // 上升
|
||||||
|
OUTCONTROL_DOWN, // 下降
|
||||||
|
MANUALACTION_RUN, // 执行
|
||||||
|
OUTCONTROL_OPEN, // 打开
|
||||||
|
OUTCONTROL_CLOSE, // 关闭
|
||||||
|
OUTCONTROL_STARTOIL, // 开始
|
||||||
|
OUTCONTROL_STOPOIL, // 停止
|
||||||
|
OUTCONTROL_COCOSTOP, // 输出停止
|
||||||
|
MOTORHEADO_UP, // 缝纫机头1升降
|
||||||
|
MOTORHEADO_DOWN, //缝纫机头1下降
|
||||||
|
MOTORHEADT_UP, // 缝纫机头2升降
|
||||||
|
MOTORHEADT_DOWN, // 缝纫机头2下降
|
||||||
|
ALLTO_ZERO, // 全部归零
|
||||||
|
OUTCONTROL_PULL, //拉料
|
||||||
|
OUTCONTROL_PULLBACK, //退料
|
||||||
|
OUTCONTROL_PULLSTOP, //拉料/退料停止
|
||||||
|
OUTCONTROL_LEFTMOVE, //左移
|
||||||
|
OUTCONTROL_RIGHTMOVE, //右移
|
||||||
|
OUTCONTROL_FORWARD, //前进
|
||||||
|
OUTCONTROL_REVERSE //后退
|
||||||
|
};
|
||||||
|
|
||||||
|
//软件设置的顺序枚举
|
||||||
|
enum ENUM_SOFTWARESET {
|
||||||
|
// SET_THEME = 0, // 主题
|
||||||
|
SET_LANGUAGE = 0, // 语言
|
||||||
|
SET_FONTSIZE, //字体大小
|
||||||
|
SET_CONNECTMODE, //连接方式(通讯方式)
|
||||||
|
SET_TITLEBAR //设置标题栏
|
||||||
|
//参数设置界面参数显示方式
|
||||||
|
};
|
||||||
|
|
||||||
|
//花样参数的顺序枚举
|
||||||
|
enum ENUM_PATTERNPARA {
|
||||||
|
SET_ROTATESTYLE = 0, // 旋转式样
|
||||||
|
SET_HORIZONTALSTYLE, // 水平翻转样式
|
||||||
|
SET_VERTICALSTYLE, // 垂直翻转样式
|
||||||
|
SET_ROTATEANGLE, // 旋转角度
|
||||||
|
SET_SETSTEPSIZE, // 针步大小
|
||||||
|
SET_LOLACOMP, // 罗拉补偿X+
|
||||||
|
SET_LOLACOMPXNEG, // 罗拉补偿X-
|
||||||
|
SET_LOLACOMPXZERO, // 罗拉补偿X=0
|
||||||
|
SET_REINMODE , // 加固方式
|
||||||
|
SET_REINNEEDLE , // 加固针数
|
||||||
|
SET_REINNUM , // 加固次数
|
||||||
|
SET_ANGLECORROFFSET, // 角度修正量
|
||||||
|
SET_ANGLECORRPOSX, // 角度修正x正
|
||||||
|
SET_ANGLECORRNEGX, // 角度修正x负
|
||||||
|
SET_ANGLECORRPOSY, // 角度修正y正
|
||||||
|
SET_ANGLECORRNEGY, // 角度修正y负
|
||||||
|
SET_SETLEFT, // 左边
|
||||||
|
SET_SETFRONT , // 前边
|
||||||
|
SET_SCANX, // 缩放x
|
||||||
|
SET_SCANY , // 缩放y
|
||||||
|
SET_STARTX, // 起始点x
|
||||||
|
SET_STARTY , // 起始点y
|
||||||
|
SET_ANCHORX, // 定位点x
|
||||||
|
SET_ANCHORY, // 定位点y
|
||||||
|
SET_EQUAL, //等比缩放
|
||||||
|
SET_ROTATIONANGLE, //旋转角度调整
|
||||||
|
SET_BISECT, //
|
||||||
|
SET_OFTNEEDLE // 去除偏移最小针步设置
|
||||||
|
};
|
||||||
|
|
||||||
|
//网络管理设置的顺序枚举
|
||||||
|
enum ENUM_NETWORKSET {
|
||||||
|
SET_MQTT_SERVERIP = 0, // 网关服务器IP
|
||||||
|
SET_MQTT_SERVERPORT, // 网关服务器端口
|
||||||
|
SET_MACHINE_SERVERIP, // 机器服务器IP
|
||||||
|
SET_MACHINE_SERVERPORT, // 机器服务器端口
|
||||||
|
SET_LOCALIP, // 本地IP
|
||||||
|
SET_LOCALPORT, // 本地端口
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CMDCONFIG_H
|
||||||
37
items/errorcodestateitem.cpp
Normal file
37
items/errorcodestateitem.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "errorcodestateitem.h"
|
||||||
|
|
||||||
|
ErrorCodeStateItem::ErrorCodeStateItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorCodeStateItem::~ErrorCodeStateItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorCodeStateItem::ErrorCodeStateItem(const ErrorCodeStateItem &item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorCodeStateItem &ErrorCodeStateItem::operator=(const ErrorCodeStateItem &item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ErrorCodeStateItem::clean()
|
||||||
|
{
|
||||||
|
m_code = 0;
|
||||||
|
m_name.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ErrorCodeStateItem::copyData(const ErrorCodeStateItem &item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_code = item.m_code ; // 代码
|
||||||
|
this->m_name = item.m_name ; // 代码对应的名称
|
||||||
|
}
|
||||||
|
}
|
||||||
33
items/errorcodestateitem.h
Normal file
33
items/errorcodestateitem.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef ERRORCODESTATEITEM_H
|
||||||
|
#define ERRORCODESTATEITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ErrorCodeStateItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ErrorCodeStateItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
~ErrorCodeStateItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
ErrorCodeStateItem(const ErrorCodeStateItem & item);
|
||||||
|
ErrorCodeStateItem & operator= (const ErrorCodeStateItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const ErrorCodeStateItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
unsigned int m_code; // 代码
|
||||||
|
QString m_name; // 代码对应的名称
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ERRORCODESTATEITEM_H
|
||||||
63
items/fileitem.cpp
Normal file
63
items/fileitem.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include "fileitem.h"
|
||||||
|
|
||||||
|
FileItem::FileItem(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileItem::~FileItem()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileItem::FileItem(const FileItem & item) :
|
||||||
|
QObject(item.parent())
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileItem & FileItem::operator=(const FileItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileItem::clear()
|
||||||
|
{
|
||||||
|
m_filePathName.clear(); // 文件路径
|
||||||
|
m_showInfo.clear(); // 显示信息
|
||||||
|
m_imagePath.clear(); // 图片路径
|
||||||
|
m_previewImage = QImage(); // 图形预览
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝
|
||||||
|
void FileItem::copyData(const FileItem & item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_filePathName = item.m_filePathName; // 文件路径
|
||||||
|
this->m_showInfo = item.m_showInfo; // 显示信息
|
||||||
|
this->m_imagePath = item.m_imagePath; // 图片路径
|
||||||
|
this->m_previewImage = item.m_previewImage; // 图形预览
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (1)
|
||||||
|
void FileItem::setFileInfo(QString & path, QString & show, QImage & previewImg)
|
||||||
|
#else
|
||||||
|
void FileItem::setFileInfo(QString path, QString show, QImage previewImg)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
m_filePathName = path; // 文件路径
|
||||||
|
m_showInfo = show; // 显示信息
|
||||||
|
m_previewImage = previewImg; // 预览图形
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FileItem::setFileInfo(QString path, QString show, QString imagePath)
|
||||||
|
{
|
||||||
|
m_filePathName = path; // 文件路径
|
||||||
|
m_showInfo = show; // 显示信息
|
||||||
|
m_imagePath = imagePath; // 图片路径
|
||||||
|
}
|
||||||
48
items/fileitem.h
Normal file
48
items/fileitem.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef FILEITEM_H
|
||||||
|
#define FILEITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
// 文件条目项
|
||||||
|
class FileItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FileItem(QObject *parent = NULL);
|
||||||
|
FileItem(const FileItem & item);
|
||||||
|
~FileItem();
|
||||||
|
public:
|
||||||
|
FileItem &operator=(const FileItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clear();
|
||||||
|
private:
|
||||||
|
void copyData(const FileItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
#if (1)
|
||||||
|
void setFileInfo(QString & path, QString & show, QImage & previewImg);
|
||||||
|
#else
|
||||||
|
void setFileInfo(QString path, QString show, QImage previewImg);
|
||||||
|
#endif
|
||||||
|
void setFileInfo(QString path, QString show, QString imagePath);
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline const QString & getFilePath() const {return m_filePathName;} // 文件路径
|
||||||
|
inline const QString & getShowInfo() const {return m_showInfo;} // 显示信息
|
||||||
|
inline const QString & getImagePath() const {return m_imagePath;} // 图片路径
|
||||||
|
inline const QImage & getPreviewImage() const {return m_previewImage;} // 图形预览
|
||||||
|
private:
|
||||||
|
QImage m_previewImage; // 图形预览
|
||||||
|
QString m_filePathName; // 文件路径名称
|
||||||
|
QString m_imagePath; // 图片路径
|
||||||
|
QString m_showInfo; // 显示信息(文件名称)
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILEITEM_H
|
||||||
593
items/itemsmanage.cpp
Normal file
593
items/itemsmanage.cpp
Normal file
@ -0,0 +1,593 @@
|
|||||||
|
#include "itemsmanage.h"
|
||||||
|
extern QString createStrList(QStringList list);
|
||||||
|
|
||||||
|
ParaItem makeAParaItem(
|
||||||
|
int64_t mcenSel,
|
||||||
|
int paraType,
|
||||||
|
int paraTypeSort,
|
||||||
|
int indexInPara,
|
||||||
|
int bitInWord,
|
||||||
|
int readonly,
|
||||||
|
int valueType,
|
||||||
|
QString paraName,
|
||||||
|
int64_t value,
|
||||||
|
int64_t minval,
|
||||||
|
int64_t maxval,
|
||||||
|
int64_t defvalue,
|
||||||
|
int afterpoint,
|
||||||
|
QString unitstr,
|
||||||
|
QString valuestr,
|
||||||
|
QString selList,
|
||||||
|
int selIdx,
|
||||||
|
int defIdx,
|
||||||
|
int showPriority,
|
||||||
|
int authority)
|
||||||
|
{
|
||||||
|
ParaItem item;
|
||||||
|
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.mcenSel = mcenSel; /* 机型选择 */
|
||||||
|
item.paraType = paraType; /* 参数类型(机器参数、工作参数、花样设置参数...) */
|
||||||
|
item.paraTypeSort = paraTypeSort; /* 参数类型分类(机器参数的速度参数、机器参数的动作参数...) */
|
||||||
|
|
||||||
|
item.indexInPara = indexInPara; /* 参数索引,-1,提示型显示; >= 0,该条目在参数中的位置*/
|
||||||
|
item.bitInWord = bitInWord; /* 参数位索引 */
|
||||||
|
item.readonly = readonly; /* 只读标志 */
|
||||||
|
item.valueType = valueType; /* 参数值类型 = 0, 无值; = 1, 数字输入型; = 2, 开关选择型; = 3, 列表选择型 */
|
||||||
|
|
||||||
|
item.paraName = paraName; /* 参数名称 */
|
||||||
|
|
||||||
|
item.value = value; /* int输入型或选择型参数值 */
|
||||||
|
item.minVal = minval; /* int输入型参数值范围下限 */
|
||||||
|
item.maxVal = maxval; /* int输入型参数值范围上限 */
|
||||||
|
item.defValue = defvalue; /* int输入型或选择型默认参数值 */
|
||||||
|
item.afterPoint = afterpoint; /* int输入型保留小数位数 */
|
||||||
|
item.unitStr = unitstr; /* int输入型单位字符串 */
|
||||||
|
item.valueStr = valuestr; /* 字符输入型参数字符串 */
|
||||||
|
|
||||||
|
item.selList = selList; /* 列表选择型的参数列表, 通过"\n"来分割 */
|
||||||
|
item.selIdx = selIdx; /* 当前选择项索引 */
|
||||||
|
item.defIdx = defIdx; /* 默认选择项索引 */
|
||||||
|
item.showPriority = showPriority; /* 显示优先级 */
|
||||||
|
item.authority = authority; /* 显示优先级 */
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool comparePriority(const ParaItem &item1, const ParaItem &item2)
|
||||||
|
{
|
||||||
|
int pr1, pr2;
|
||||||
|
pr1 = item1.showPriority;
|
||||||
|
pr2 = item2.showPriority;
|
||||||
|
if (pr1 < 0)
|
||||||
|
{
|
||||||
|
pr1 = 0;
|
||||||
|
}
|
||||||
|
if (pr2 < 0)
|
||||||
|
{
|
||||||
|
pr2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (pr1 < pr2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//各个机型通用参数-软件设置参数
|
||||||
|
void initSoftwareParasList(QList <ParaItem> & parasList)
|
||||||
|
{
|
||||||
|
//软件设置参数---------------------------
|
||||||
|
//软件设置参数-主题;单位:无 ,范围1-3,默认1
|
||||||
|
/*
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_SOFTWARESET,
|
||||||
|
0 ,
|
||||||
|
SET_THEME, 0, 1, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Theme"),//主题
|
||||||
|
1, 1, 3, 1, 0, "", "",
|
||||||
|
QCoreApplication::translate("GLOBAL", "Theme1:1;Theme2:2;Theme3:3"),//主题1:1;主题2:2;主题3:3
|
||||||
|
0, 0, 0x0001, operate));
|
||||||
|
*/
|
||||||
|
|
||||||
|
//不加油:0;按工作时间间断加油:1;按工作针数间歇加油:2;持续加油:3
|
||||||
|
QString strLanguage = createStrList
|
||||||
|
({QCoreApplication::translate("GLOBAL", "Chinese"), //0, 中文
|
||||||
|
QCoreApplication::translate("GLOBAL", "English"), //1, 英文
|
||||||
|
QCoreApplication::translate("GLOBAL", "Ukrainian"), //2, 乌克兰文
|
||||||
|
QCoreApplication::translate("GLOBAL", "French"),//3, 法文
|
||||||
|
QCoreApplication::translate("GLOBAL", "Russian"),//4, 俄语
|
||||||
|
QCoreApplication::translate("GLOBAL", "German")//5, 德文
|
||||||
|
});
|
||||||
|
|
||||||
|
//软件设置参数-语言;单位:无 ,范围0-1,默认0
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_SOFTWARESET,
|
||||||
|
0 ,
|
||||||
|
SET_LANGUAGE, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Language"),//语言
|
||||||
|
0, chinese, german, 0, 0, "", "",
|
||||||
|
strLanguage,0, 0, 0x0002, operate));
|
||||||
|
|
||||||
|
// #ifdef Q_OS_WIN
|
||||||
|
//软件设置参数-字体大小
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_SOFTWARESET,
|
||||||
|
0 ,
|
||||||
|
SET_FONTSIZE, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Fontsize"),//字体大小
|
||||||
|
0, 8, 16, 0, 0, "", "",
|
||||||
|
(""),
|
||||||
|
0, 0, 0x0002, operate));
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
//软件设置参数---------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
//各个机型通用参数-时间设置参数
|
||||||
|
void initTimeParasList(QList <ParaItem> & parasList)
|
||||||
|
{
|
||||||
|
//时间设置参数---------------------------
|
||||||
|
//时间设置参数-年;单位:无 ,范围1000-9999,默认1000
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_TIMESET,
|
||||||
|
0 ,
|
||||||
|
1, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Year"),//年
|
||||||
|
1000, 1000, 9999, 1000, 0, "", "",
|
||||||
|
"", 0, 0, 0x0000, operate));
|
||||||
|
|
||||||
|
//时间设置参数-月;单位:无 ,范围1-12,默认1
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_TIMESET,
|
||||||
|
0 ,
|
||||||
|
2, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Month"),//月
|
||||||
|
1, 1, 12, 1, 0, "", "",
|
||||||
|
"", 0, 0, 0x0001, operate));
|
||||||
|
|
||||||
|
//时间设置参数-日;单位:无 ,范围1-31,默认1
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_TIMESET,
|
||||||
|
0 ,
|
||||||
|
3, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Day"),//日
|
||||||
|
1, 1, 31, 1, 0, "", "",
|
||||||
|
"", 0, 0, 0x0002, operate));
|
||||||
|
|
||||||
|
//时间设置参数-时;单位:无 ,范围0-23,默认0
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_TIMESET,
|
||||||
|
0 ,
|
||||||
|
4, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Hour"),//时
|
||||||
|
0, 0, 23, 0, 0, "", "",
|
||||||
|
"", 0, 0, 0x0003, operate));
|
||||||
|
|
||||||
|
//时间设置参数-分;单位:无 ,范围0-59,默认0
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_TIMESET,
|
||||||
|
0 ,
|
||||||
|
5, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Minute"),//分
|
||||||
|
0, 0, 59, 0, 0, "", "",
|
||||||
|
"", 0, 0, 0x0004, operate));
|
||||||
|
|
||||||
|
//时间设置参数-秒;单位:无 ,范围0-59,默认0
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_TIMESET,
|
||||||
|
0 ,
|
||||||
|
6, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Second"),//秒
|
||||||
|
0, 0, 59, 0, 0, "", "",
|
||||||
|
"", 0, 0, 0x0005, operate));
|
||||||
|
//时间设置参数---------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
//各个机型通用参数-网络管理参数
|
||||||
|
void initNetworkParasList(QList <ParaItem> & parasList)
|
||||||
|
{
|
||||||
|
|
||||||
|
//网络管理参数-服务器IP设置;单位:无 ,范围无,默认192.168.16.253
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_NETWORKSET,
|
||||||
|
0 ,
|
||||||
|
SET_MACHINE_SERVERIP, 0, 0, PARA_VALUE_TYPE_STRINPUT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Server IP settings"),//服务器IP设置
|
||||||
|
0, 0, 0, 0, 0, "", "192.168.16.253",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0007, operate));
|
||||||
|
|
||||||
|
//网络管理参数-服务器端口设置;单位:无 ,范围0-65535,默认5000
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_NETWORKSET,
|
||||||
|
0 ,
|
||||||
|
SET_MACHINE_SERVERPORT, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Server port settings"),//服务器端口设置
|
||||||
|
5000, 0, U16_MAX, 5000, 0, "", "",
|
||||||
|
"", 0, 0,0x0008, operate));
|
||||||
|
|
||||||
|
//网络管理参数-本地IP设置;单位:无 ,范围无,默认192.168.16.41
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_NETWORKSET,
|
||||||
|
0 ,
|
||||||
|
SET_LOCALIP, 0, 0, PARA_VALUE_TYPE_STRINPUT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Local IP settings"),//本地IP设置
|
||||||
|
0, 0, 0, 0, 0, "", "192.168.16.41",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0009, operate));
|
||||||
|
|
||||||
|
//网络管理参数-本地端口设置;单位:无 ,范围0-65535,默认5001
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_NETWORKSET,
|
||||||
|
0 ,
|
||||||
|
SET_LOCALPORT, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Local port settings"),//本地端口设置
|
||||||
|
5001, 0, U16_MAX, 5001, 0, "", "",
|
||||||
|
"", 0, 0,0x000A, operate));
|
||||||
|
//网络管理参数---------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
OutCtrlItem makeAOutCtrlItem(int macType, int showPriority, QString name, int def,
|
||||||
|
QString btn1Str, bool btn1Visible, int btn1ClickFun, int btn1PreFun, int btn1RelFun,
|
||||||
|
QString btn2Str, bool btn2Visible, int btn2ClickFun, int btn2PreFun, int btn2RelFun,
|
||||||
|
QString btn3Str, bool btn3Visible, int btn3ClickFun, int btn3PreFun, int btn3RelFun,
|
||||||
|
QString btn4Str, bool btn4Visible, int btn4ClickFun, int btn4PreFun, int btn4RelFun,
|
||||||
|
QString btn5Str, bool btn5Visible, int btn5ClickFun, int btn5PreFun, int btn5RelFun)
|
||||||
|
{
|
||||||
|
OutCtrlItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_macType = macType;
|
||||||
|
item.m_showPriority = showPriority;
|
||||||
|
item.m_name = name;
|
||||||
|
item.m_def = def;
|
||||||
|
|
||||||
|
item.m_btn1Str = btn1Str;
|
||||||
|
item.m_btn1Visible = btn1Visible;
|
||||||
|
item.m_btn1ClickFun = btn1ClickFun;
|
||||||
|
item.m_btn1PreFun = btn1PreFun;
|
||||||
|
item.m_btn1RelFun = btn1RelFun;
|
||||||
|
|
||||||
|
item.m_btn2Str = btn2Str;
|
||||||
|
item.m_btn2Visible = btn2Visible;
|
||||||
|
item.m_btn2ClickFun = btn2ClickFun;
|
||||||
|
item.m_btn2PreFun = btn2PreFun;
|
||||||
|
item.m_btn2RelFun = btn2RelFun;
|
||||||
|
|
||||||
|
item.m_btn3Str = btn3Str;
|
||||||
|
item.m_btn3Visible = btn3Visible;
|
||||||
|
item.m_btn3ClickFun = btn3ClickFun;
|
||||||
|
item.m_btn3PreFun = btn3PreFun;
|
||||||
|
item.m_btn3RelFun = btn3RelFun;
|
||||||
|
|
||||||
|
item.m_btn4Str = btn4Str;
|
||||||
|
item.m_btn4Visible = btn4Visible;
|
||||||
|
item.m_btn4ClickFun = btn4ClickFun;
|
||||||
|
item.m_btn4PreFun = btn4PreFun;
|
||||||
|
item.m_btn4RelFun = btn4RelFun;
|
||||||
|
|
||||||
|
item.m_btn5Str = btn5Str;
|
||||||
|
item.m_btn5Visible = btn5Visible;
|
||||||
|
item.m_btn5ClickFun = btn5ClickFun;
|
||||||
|
item.m_btn5PreFun = btn5PreFun;
|
||||||
|
item.m_btn5RelFun = btn5RelFun;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortCutItem makeAShortCutItem(int macType, int showPriority, QString name, QString topImageName, int enumFunction)
|
||||||
|
{
|
||||||
|
ShortCutItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_macType = macType;
|
||||||
|
item.m_showPriority = showPriority;
|
||||||
|
item.m_name = name;
|
||||||
|
item.m_topImageName = topImageName;
|
||||||
|
item.m_enumFunction = enumFunction;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加辅助功能item
|
||||||
|
AssistItem makeAAssistItem(int macType, int showPriority, QString name, QString topImageName, int enumFunction)
|
||||||
|
{
|
||||||
|
AssistItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_macType = macType;
|
||||||
|
item.m_showPriority = showPriority;
|
||||||
|
item.m_name = name;
|
||||||
|
item.m_topImageName = topImageName;
|
||||||
|
item.m_enumFunction = enumFunction;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
PatternSetItem makeAPatternSetItem(int macType, int showPriority, QString name, QString topImageName, int enumFunction)
|
||||||
|
{
|
||||||
|
PatternSetItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_macType = macType;
|
||||||
|
item.m_showPriority = showPriority;
|
||||||
|
item.m_name = name;
|
||||||
|
item.m_topImageName = topImageName;
|
||||||
|
item.m_enumFunction = enumFunction;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initRootHMIConfigurationList(QList<ParaItem> ¶sList)
|
||||||
|
{
|
||||||
|
//超级用户界面配置参数-分辨率;单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_RESOLUTION, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Resolution"),//分辨率
|
||||||
|
0, 0, 2, 0, 0, "", "",
|
||||||
|
"1920x1080:0;1024x600:1;800x480:2;",
|
||||||
|
0, 0, 0x0001, root));
|
||||||
|
|
||||||
|
//软件设置参数-通讯方式;单位:无 ,范围0-2,默认0
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
SET_CONNECTMODE, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Communication method"),//通讯方式
|
||||||
|
0, 0, 1, 0, 0, "", "",
|
||||||
|
QCoreApplication::translate("GLOBAL", "Network:0;SerialPort:1"),//网口:0;串口:1
|
||||||
|
0, 0, 0x0011, operate));
|
||||||
|
|
||||||
|
QString strYesNo = createStrList
|
||||||
|
({QCoreApplication::translate("GLOBAL", "No"), //0, 否
|
||||||
|
QCoreApplication::translate("GLOBAL", "Yes"), //1, 是
|
||||||
|
});
|
||||||
|
|
||||||
|
QList<mcSelect> mcTypeList;
|
||||||
|
mcSelect mc;
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "McHighSingleQui"); //高速单针机
|
||||||
|
mc.mcIdx = MACHINE_HIGHSPEEDSINGLEQUI;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "FiveHeadPrecisionSewing"); //五头精密缝
|
||||||
|
mc.mcIdx = MACHINE_FIVEHEADPRECISIONSEWING;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "ClothingMac"); //服装机
|
||||||
|
mc.mcIdx = MACHINE_CLOTHINGMAC;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
// mc.mcName = QCoreApplication::translate("GLOBAL", "Multineedlerotary"); //多针旋梭
|
||||||
|
// mc.mcIdx = MACHINE_MULTINEEDLEROTARY;
|
||||||
|
// mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "ThickWiringMac"); //粗布布线机
|
||||||
|
mc.mcIdx = MACHINE_THICK_WIRING;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "FlyShuttle"); //飞梭机
|
||||||
|
mc.mcIdx = MACHINE_FLYSHUTTLE;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "GlassFibre"); //玻璃纤维
|
||||||
|
mc.mcIdx = MACHINE_GLASSFIBRE;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "DoubleLayered"); //双层绗缝机
|
||||||
|
mc.mcIdx = MACHINE_DOUBLE_LAYERED;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "DLQScheBoard"); //双层绗缝调度主板
|
||||||
|
mc.mcIdx = MACHINE_DLQSCHE_BOARD;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
// mc.mcName = QCoreApplication::translate("GLOBAL", "SingleMutilNeedle"); //单排多针旋梭
|
||||||
|
// mc.mcIdx = MACHINE_SINGLE_MUTIL_NEEDLE;
|
||||||
|
// mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "DoubleSizedBedSheets"); //床单机双边缝
|
||||||
|
mc.mcIdx = MACHINE_DOUBLE_BEDSHEETS;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "Multi-headRotaryShuttleMc"); //L2000多针机 改为 多头旋梭机
|
||||||
|
mc.mcIdx = MACHINE_L2000_MULTI;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "Fully automatic quilting machine"); //全自动绗缝机
|
||||||
|
mc.mcIdx = MACHINE_FULLYAUTOMATIC;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "PackageFourSidedTestBoard"); //包四边机测试板
|
||||||
|
mc.mcIdx = MACHINE_PkgFourTestBoard;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "AutoDoubleDoor"); //全自动双龙门单机头
|
||||||
|
mc.mcIdx = MACHINE_AutoDoubleDoor;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "DoubleHeadCombQuiMc"); //双头组合绗缝机
|
||||||
|
mc.mcIdx = MACHINE_DOUBLEHEADQUI;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "CuttingWalk"); //边走边裁
|
||||||
|
mc.mcIdx = MACHINE_CUTTINGWALK;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
|
||||||
|
mc.mcName = QCoreApplication::translate("GLOBAL", "FourHeadCombQuiMc"); //四头组合绗缝机
|
||||||
|
mc.mcIdx = MACHINE_FOURHEADQUI;
|
||||||
|
mcTypeList.append(mc);
|
||||||
|
QString strValue;
|
||||||
|
for(int i = 0; i < mcTypeList.size(); i++)
|
||||||
|
{
|
||||||
|
//01/** McHighSingleQui:0;
|
||||||
|
QString index = QString("%1/%2").arg(i + 1, 2, 10, QChar('0')).arg(mcTypeList.size());
|
||||||
|
strValue += index + " " + mcTypeList.at(i).mcName + ":" + QString::number(mcTypeList.at(i).mcIdx) + ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
//机器类型
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_MACTYPE, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Machine type"),//机器类型
|
||||||
|
//值,最小值,最大值,默认值
|
||||||
|
MACHINE_HIGHSPEEDSINGLEQUI, MACHINE_HIGHSPEEDSINGLEQUI, MACHINE_FOURHEADQUI, MACHINE_HIGHSPEEDSINGLEQUI, 0, "", "",
|
||||||
|
strValue,
|
||||||
|
0, 0, 0x0012, operate));
|
||||||
|
|
||||||
|
//超级用户界面配置参数-产品类型;单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_PRODUCTTYPE, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Product type"),//产品类型
|
||||||
|
PRODUCT_NULL, PRODUCT_NULL, PRODUCT_NULL, PRODUCT_NULL, 0, "", "",
|
||||||
|
QCoreApplication::translate("GLOBAL","ProductNull:")+QString::number(PRODUCT_NULL),//无
|
||||||
|
0, 0, 0x0013, root));
|
||||||
|
|
||||||
|
if(g_emMacType != MACHINE_L2000_MULTI)
|
||||||
|
{
|
||||||
|
//超级用户界面配置参数-是否有自动换梭功能;单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_SHUTTLECHANGE, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Whether there is a Automatic shuttle change function"),//是否有自动换梭功能
|
||||||
|
1, 0, 1, 1, 0, "", "",
|
||||||
|
strYesNo,
|
||||||
|
1, 1, 0x0016, root));
|
||||||
|
}
|
||||||
|
|
||||||
|
//超级用户界面配置参数-主背景是否带水印;单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_WATERMARKSET, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Is there a GetonAgain logo"),//是否有再登高标志
|
||||||
|
1, 0, 1, 1, 0, "", "",
|
||||||
|
strYesNo,
|
||||||
|
1, 1, 0x0017, root));
|
||||||
|
|
||||||
|
//超级用户界面配置参数-参数是否分类显示;单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_PARASORTSET, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Parameter is classified"),//参数是否分类显示
|
||||||
|
0, 0, 1, 0, 0, "", "",
|
||||||
|
strYesNo,
|
||||||
|
0, 0, 0x0018, root));
|
||||||
|
|
||||||
|
//是否WIFI
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_WIFI, 0, 0, PARA_VALUE_TYPE_SW,
|
||||||
|
QCoreApplication::translate("GLOBAL", "WIFI"),//WIFI
|
||||||
|
0, 0, 1, 0, 0, "", "",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0018, root));
|
||||||
|
|
||||||
|
//主轴缝纫工作最高转速
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_HMICONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_MAXSPEED_MAINSEWWORK, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Max Speed Of Main Sew Work"),
|
||||||
|
0, 0, 4000, 0, 0, "", "",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0018, root));
|
||||||
|
}
|
||||||
|
|
||||||
|
//物联网配置参数
|
||||||
|
void initRootIOTConfigurationList(QList<ParaItem> ¶sList)
|
||||||
|
{
|
||||||
|
//超级用户物联网配置-网关连接方式;单位:无
|
||||||
|
// parasList.append(makeAParaItem(0,
|
||||||
|
// PARA_TYPE_IOTCONFIGURATION,
|
||||||
|
// 0 ,
|
||||||
|
// ROOT_GATEWAYCONNECTIONMETHOD, 0, 0, PARA_VALUE_TYPE_LIST,
|
||||||
|
// QCoreApplication::translate("GLOBAL", "Gateway connection method"),//网关连接方式
|
||||||
|
// 0, 0, 2, 0, 0, "", "",
|
||||||
|
// QCoreApplication::translate("GLOBAL","Serial port:0; Network port:1"),
|
||||||
|
// 0, 0, 0x0011, root));
|
||||||
|
|
||||||
|
//超级用户物联网配置-机架号输入; 单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_IOTCONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_RACKNUMBERINPUT, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Input rack number"),//机架号输入
|
||||||
|
0, 0, INT_MAX, 0, 0, "", "",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0012, root));
|
||||||
|
|
||||||
|
//超级用户物联网配置-网络设置; 单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_IOTCONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_NETWORKSETTINGS, 0, 0, PARA_VALUE_TYPE_CLICK,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Network settings"),//网络设置
|
||||||
|
0, 0, 0, 0, 0, "", "",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0013, root));
|
||||||
|
|
||||||
|
//超级用户物联网配置-工厂预计交货时间; 单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_IOTCONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_DELIVERYTIME, 0, 0, PARA_VALUE_TYPE_STRINPUT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Factory expects delivery time"),//工厂预计交货时间
|
||||||
|
0, 0, 0, 0, 0, "", "",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0014, root));
|
||||||
|
|
||||||
|
//超级用户物联网配置-调试进度; 单位:无
|
||||||
|
parasList.append(makeAParaItem(0,
|
||||||
|
PARA_TYPE_IOTCONFIGURATION,
|
||||||
|
0 ,
|
||||||
|
ROOT_DEBUGPROGRESS, 0, 0, PARA_VALUE_TYPE_INT,
|
||||||
|
QCoreApplication::translate("GLOBAL", "Debugging progress"),//调试进度
|
||||||
|
0, 1, 100, 0, 0, "", "",
|
||||||
|
"",
|
||||||
|
0, 0, 0x0015, root));
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaSetItem makeAParaSetItem(int macType, int showPriority, QString name, QString topImageName, int paraType)
|
||||||
|
{
|
||||||
|
ParaSetItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_macType = macType;
|
||||||
|
item.m_showPriority = showPriority;
|
||||||
|
item.m_name = name;
|
||||||
|
item.m_topImageName = topImageName;
|
||||||
|
item.m_paraType = paraType;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorItem makeASensorItem(int byte, int bit, QString name, int type)
|
||||||
|
{
|
||||||
|
SensorItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_byte_offset = byte;
|
||||||
|
item.m_bit_offset = bit;
|
||||||
|
item.m_name = name;
|
||||||
|
item.m_type = type;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorCodeStateItem makeAErrorStateItem(int code, QString name)
|
||||||
|
{
|
||||||
|
ErrorCodeStateItem item;
|
||||||
|
item.clean();
|
||||||
|
|
||||||
|
item.m_code = code;
|
||||||
|
item.m_name = name;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
102
items/itemsmanage.h
Normal file
102
items/itemsmanage.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#ifndef ITEMSMANAGE_H
|
||||||
|
#define ITEMSMANAGE_H
|
||||||
|
|
||||||
|
#include "paraitem.h"
|
||||||
|
#include "outctrlitem.h"
|
||||||
|
#include "shortcutitem.h"
|
||||||
|
#include "assistitem.h"
|
||||||
|
#include "patternsetitem.h"
|
||||||
|
#include "parasetitem.h"
|
||||||
|
#include "nineitem.h"
|
||||||
|
#include "sensoritem.h"
|
||||||
|
#include "errorcodestateitem.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
|
struct mcSelect
|
||||||
|
{
|
||||||
|
QString mcName;
|
||||||
|
int mcIdx;
|
||||||
|
};
|
||||||
|
|
||||||
|
//添加快捷功能item
|
||||||
|
ShortCutItem makeAShortCutItem(int macType,int showPriority,
|
||||||
|
QString name,QString topImageName,
|
||||||
|
int enumFunction);
|
||||||
|
|
||||||
|
//添加辅助功能item
|
||||||
|
AssistItem makeAAssistItem(int macType,int showPriority,
|
||||||
|
QString name,QString topImageName,
|
||||||
|
int enumFunction);
|
||||||
|
|
||||||
|
//花样设置功能item
|
||||||
|
PatternSetItem makeAPatternSetItem(int macType,int showPriority,
|
||||||
|
QString name,QString topImageName,
|
||||||
|
int enumFunction);
|
||||||
|
|
||||||
|
//参数设置功能item
|
||||||
|
ParaSetItem makeAParaSetItem(int macType,int showPriority,
|
||||||
|
QString name,QString topImageName,
|
||||||
|
int paraType);
|
||||||
|
|
||||||
|
//传感器信号item
|
||||||
|
SensorItem makeASensorItem(int byte,int bit,QString name,int type = -1);
|
||||||
|
|
||||||
|
//错误代码/状态item
|
||||||
|
ErrorCodeStateItem makeAErrorStateItem(int code,QString name);
|
||||||
|
|
||||||
|
//添加控制动作item
|
||||||
|
OutCtrlItem makeAOutCtrlItem(int macType,int showPriority,QString name,int def,
|
||||||
|
QString btn1Str,bool btn1Visible,
|
||||||
|
int btn1ClickFun,int btn1PreFun,int btn1RelFun,
|
||||||
|
QString btn2Str,bool btn2Visible,
|
||||||
|
int btn2ClickFun,int btn2PreFun,int btn2RelFun,
|
||||||
|
QString btn3Str,bool btn3Visible,
|
||||||
|
int btn3ClickFun,int btn3PreFun,int btn3RelFun,
|
||||||
|
QString btn4Str,bool btn4Visible,
|
||||||
|
int btn4ClickFun,int btn4PreFun,int btn4RelFun,
|
||||||
|
QString btn5Str,bool btn5Visible,
|
||||||
|
int btn5ClickFun,int btn5PreFun,int btn5RelFun);
|
||||||
|
|
||||||
|
|
||||||
|
//添加参数item
|
||||||
|
ParaItem makeAParaItem(
|
||||||
|
int64_t mcenSel, /* 机型选择 */
|
||||||
|
int paraType, /* 参数类型(机器参数、工作参数、花样设置参数...) */
|
||||||
|
int paraTypeSort, /* 参数类型分类(机器参数的速度参数、机器参数的动作参数...) */
|
||||||
|
int indexInPara, /* 参数索引,-1,提示型显示; >= 0,该条目在参数中的位置*/
|
||||||
|
int bitInWord, /* 参数位索引 */
|
||||||
|
int readonly, /* 只读标志 */
|
||||||
|
int valueType, /* 参数值类型 = 0, 无值; = 1, 数字输入型; = 2, 开关选择型; = 3, 列表选择; = 4, 字符输入型*/
|
||||||
|
|
||||||
|
QString paraName, /* 参数名称 */
|
||||||
|
|
||||||
|
int64_t value, /* int输入型或选择型参数值 */
|
||||||
|
int64_t minval, /* int输入型参数值范围下限 */
|
||||||
|
int64_t maxval, /* int输入型参数值范围上限 */
|
||||||
|
int64_t defvalue, /* int输入型或选择型默认参数值 */
|
||||||
|
int afterpoint, /* int输入型保留小数位数 */
|
||||||
|
QString unitstr, /* int输入型单位字符串 */
|
||||||
|
QString valuestr, /* 字符输入型参数字符串 */
|
||||||
|
|
||||||
|
QString selList, /* 列表选择型的参数列表, 通过"\n"来分割 */
|
||||||
|
int selIdx, /* 当前选择项索引 */
|
||||||
|
int defIdx, /* 默认选择项索引 */
|
||||||
|
|
||||||
|
int showPriority, /* 显示优先级 */
|
||||||
|
int authority /* 参数权限 */
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//比较参数优先级
|
||||||
|
bool comparePriority(const ParaItem & item1, const ParaItem & item2);
|
||||||
|
|
||||||
|
//各个机型通用参数
|
||||||
|
void initSoftwareParasList(QList <ParaItem> & parasList);//软件参数
|
||||||
|
void initTimeParasList(QList <ParaItem> & parasList);//时间设置参数
|
||||||
|
void initNetworkParasList(QList <ParaItem> & parasList);//网络管理参数
|
||||||
|
void initRootHMIConfigurationList(QList <ParaItem> & parasList);//界面配置参数
|
||||||
|
void initRootIOTConfigurationList(QList <ParaItem> ¶sList); //物联网配置参数
|
||||||
|
#endif // ITEMSMANAGE_H
|
||||||
44
items/nineitem.cpp
Normal file
44
items/nineitem.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "nineitem.h"
|
||||||
|
|
||||||
|
NineItem::NineItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
NineItem::NineItem(int fun, QString ImageName)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
m_topImageName = ImageName;
|
||||||
|
m_enumFunction = fun;
|
||||||
|
}
|
||||||
|
|
||||||
|
NineItem::~NineItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
NineItem::NineItem(const NineItem &item) : QObject(0)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
NineItem &NineItem::operator=(const NineItem &item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NineItem::clean()
|
||||||
|
{
|
||||||
|
m_topImageName.clear();
|
||||||
|
m_enumFunction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NineItem::copyData(const NineItem &item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_topImageName = item.m_topImageName;
|
||||||
|
this->m_enumFunction = item.m_enumFunction;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
items/nineitem.h
Normal file
30
items/nineitem.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef NINEITEM_H
|
||||||
|
#define NINEITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class NineItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit NineItem(QObject *parent = 0);
|
||||||
|
NineItem(int fun,QString ImageName);
|
||||||
|
~NineItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
NineItem(const NineItem & item);
|
||||||
|
NineItem & operator= (const NineItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const NineItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString m_topImageName; // 顶图图标logo名称
|
||||||
|
int m_enumFunction; // 对应的事件的枚举值
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NINEITEM_H
|
||||||
101
items/outctrlitem.cpp
Normal file
101
items/outctrlitem.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#include "outctrlitem.h"
|
||||||
|
|
||||||
|
OutCtrlItem::OutCtrlItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
OutCtrlItem::~OutCtrlItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
OutCtrlItem::OutCtrlItem(const OutCtrlItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
OutCtrlItem & OutCtrlItem::operator= (const OutCtrlItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutCtrlItem::clean()
|
||||||
|
{
|
||||||
|
m_macType = 0;
|
||||||
|
m_showPriority = 0;
|
||||||
|
m_name.clear(); // 名称
|
||||||
|
m_def = -1;
|
||||||
|
|
||||||
|
m_btn1Str.clear();
|
||||||
|
m_btn1Visible = false;
|
||||||
|
m_btn1ClickFun = -1;
|
||||||
|
m_btn1PreFun = -1;
|
||||||
|
m_btn1RelFun = -1;
|
||||||
|
|
||||||
|
m_btn2Str.clear();
|
||||||
|
m_btn2Visible = false;
|
||||||
|
m_btn2ClickFun = -1;
|
||||||
|
m_btn2PreFun = -1;
|
||||||
|
m_btn2RelFun = -1;
|
||||||
|
|
||||||
|
m_btn3Str.clear();
|
||||||
|
m_btn3Visible = false;
|
||||||
|
m_btn3ClickFun = -1;
|
||||||
|
m_btn3PreFun = -1;
|
||||||
|
m_btn3RelFun = -1;
|
||||||
|
|
||||||
|
m_btn4Str.clear();
|
||||||
|
m_btn4Visible = false;
|
||||||
|
m_btn4ClickFun = -1;
|
||||||
|
m_btn4PreFun = -1;
|
||||||
|
m_btn4RelFun = -1;
|
||||||
|
|
||||||
|
m_btn5Str.clear();
|
||||||
|
m_btn5Visible = false;
|
||||||
|
m_btn5ClickFun = -1;
|
||||||
|
m_btn5PreFun = -1;
|
||||||
|
m_btn5RelFun = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutCtrlItem::copyData(const OutCtrlItem & item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_macType = item.m_macType;
|
||||||
|
this->m_showPriority = item.m_showPriority;
|
||||||
|
this->m_name = item.m_name; // 名称
|
||||||
|
this->m_def = item.m_def;
|
||||||
|
|
||||||
|
this->m_btn1Str = item.m_btn1Str;
|
||||||
|
this->m_btn1Visible = item.m_btn1Visible;
|
||||||
|
this->m_btn1ClickFun = item.m_btn1ClickFun;
|
||||||
|
this->m_btn1PreFun = item.m_btn1PreFun;
|
||||||
|
this->m_btn1RelFun = item.m_btn1RelFun;
|
||||||
|
|
||||||
|
this->m_btn2Str = item.m_btn2Str;
|
||||||
|
this->m_btn2Visible = item.m_btn2Visible;
|
||||||
|
this->m_btn2ClickFun = item.m_btn2ClickFun;
|
||||||
|
this->m_btn2PreFun = item.m_btn2PreFun;
|
||||||
|
this->m_btn2RelFun = item.m_btn2RelFun;
|
||||||
|
|
||||||
|
this->m_btn3Str = item.m_btn3Str;
|
||||||
|
this->m_btn3Visible = item.m_btn3Visible;
|
||||||
|
this->m_btn3ClickFun = item.m_btn3ClickFun;
|
||||||
|
this->m_btn3PreFun = item.m_btn3PreFun;
|
||||||
|
this->m_btn3RelFun = item.m_btn3RelFun;
|
||||||
|
|
||||||
|
this->m_btn4Str = item.m_btn4Str;
|
||||||
|
this->m_btn4Visible = item.m_btn4Visible;
|
||||||
|
this->m_btn4ClickFun = item.m_btn4ClickFun;
|
||||||
|
this->m_btn4PreFun = item.m_btn4PreFun;
|
||||||
|
this->m_btn4RelFun = item.m_btn4RelFun;
|
||||||
|
|
||||||
|
this->m_btn5Str = item.m_btn5Str;
|
||||||
|
this->m_btn5Visible = item.m_btn5Visible;
|
||||||
|
this->m_btn5ClickFun = item.m_btn5ClickFun;
|
||||||
|
this->m_btn5PreFun = item.m_btn5PreFun;
|
||||||
|
this->m_btn5RelFun = item.m_btn5RelFun;
|
||||||
|
}
|
||||||
|
}
|
||||||
68
items/outctrlitem.h
Normal file
68
items/outctrlitem.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#ifndef OUTCTRLITEM_H
|
||||||
|
#define OUTCTRLITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "items/cmdconfig.h"
|
||||||
|
|
||||||
|
typedef short int s16;
|
||||||
|
|
||||||
|
class OutCtrlItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit OutCtrlItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
~OutCtrlItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
OutCtrlItem(const OutCtrlItem & item);
|
||||||
|
OutCtrlItem & operator= (const OutCtrlItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const OutCtrlItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_macType; // 机器类型
|
||||||
|
int m_showPriority; // 显示优先级
|
||||||
|
QString m_name; // 名称
|
||||||
|
int m_def; // 对应的事件宏定义
|
||||||
|
|
||||||
|
QString m_btn1Str; // 按钮1上的文本
|
||||||
|
bool m_btn1Visible; // 按钮1是否可见
|
||||||
|
s16 m_btn1ClickFun; // 按钮1对应的点击事件 -1:代表没有
|
||||||
|
s16 m_btn1PreFun; // 按钮1对应的按下事件 -1:代表没有
|
||||||
|
s16 m_btn1RelFun; // 按钮1对应的抬起事件 -1:代表没有
|
||||||
|
|
||||||
|
QString m_btn2Str; // 按钮2上的文本
|
||||||
|
bool m_btn2Visible; // 按钮2是否可见
|
||||||
|
s16 m_btn2ClickFun; // 按钮2对应的点击事件 -1:代表没有
|
||||||
|
s16 m_btn2PreFun; // 按钮2对应的按下事件 -1:代表没有
|
||||||
|
s16 m_btn2RelFun; // 按钮2对应的抬起事件 -1:代表没有
|
||||||
|
|
||||||
|
QString m_btn3Str; // 按钮3上的文本
|
||||||
|
bool m_btn3Visible; // 按钮3是否可见
|
||||||
|
s16 m_btn3ClickFun; // 按钮3对应的点击事件 -1:代表没有
|
||||||
|
s16 m_btn3PreFun; // 按钮3对应的按下事件 -1:代表没有
|
||||||
|
s16 m_btn3RelFun; // 按钮3对应的抬起事件 -1:代表没有
|
||||||
|
|
||||||
|
QString m_btn4Str; // 按钮4上的文本
|
||||||
|
bool m_btn4Visible; // 按钮4是否可见
|
||||||
|
s16 m_btn4ClickFun; // 按钮4对应的点击事件 -1:代表没有
|
||||||
|
s16 m_btn4PreFun; // 按钮4对应的按下事件 -1:代表没有
|
||||||
|
s16 m_btn4RelFun; // 按钮4对应的抬起事件 -1:代表没有
|
||||||
|
|
||||||
|
QString m_btn5Str; // 按钮5上的文本
|
||||||
|
bool m_btn5Visible; // 按钮5是否可见
|
||||||
|
s16 m_btn5ClickFun; // 按钮5对应的点击事件 -1:代表没有
|
||||||
|
s16 m_btn5PreFun; // 按钮5对应的按下事件 -1:代表没有
|
||||||
|
s16 m_btn5RelFun; // 按钮5对应的抬起事件 -1:代表没有
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OUTCTRLITEM_H
|
||||||
77
items/paraitem.cpp
Normal file
77
items/paraitem.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#include "paraitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
ParaItem::ParaItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaItem::~ParaItem()
|
||||||
|
{
|
||||||
|
paraName.clear();
|
||||||
|
selList.clear();
|
||||||
|
unitStr.clear();
|
||||||
|
valueStr.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaItem::ParaItem(const ParaItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaItem & ParaItem::operator=(const ParaItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParaItem::clean()
|
||||||
|
{
|
||||||
|
mcenSel = 0;
|
||||||
|
paraType = 0;
|
||||||
|
paraTypeSort = 0;
|
||||||
|
indexInPara = -1;
|
||||||
|
bitInWord = 0;
|
||||||
|
readonly = 0;
|
||||||
|
valueType = 0;
|
||||||
|
paraName = "";
|
||||||
|
value = 0;
|
||||||
|
minVal = 0;
|
||||||
|
maxVal = 0;
|
||||||
|
defValue = 0;
|
||||||
|
afterPoint = 0;
|
||||||
|
unitStr = "";
|
||||||
|
valueStr = "";
|
||||||
|
selList = "";
|
||||||
|
selIdx = -1;
|
||||||
|
defIdx = -1;
|
||||||
|
showPriority = 0;
|
||||||
|
authority = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParaItem::copyData(const ParaItem & item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->mcenSel = item.mcenSel;
|
||||||
|
this->paraType = item.paraType;
|
||||||
|
this->paraTypeSort = item.paraTypeSort;
|
||||||
|
this->indexInPara = item.indexInPara;
|
||||||
|
this->bitInWord = item.bitInWord;
|
||||||
|
this->readonly = item.readonly;
|
||||||
|
this->valueType = item.valueType;
|
||||||
|
this->paraName = item.paraName;
|
||||||
|
this->value = item.value;
|
||||||
|
this->minVal = item.minVal;
|
||||||
|
this->maxVal = item.maxVal;
|
||||||
|
this->defValue = item.defValue;
|
||||||
|
this->afterPoint = item.afterPoint;
|
||||||
|
this->unitStr = item.unitStr;
|
||||||
|
this->valueStr = item.valueStr;
|
||||||
|
this->selList = item.selList;
|
||||||
|
this->selIdx = item.selIdx;
|
||||||
|
this->defIdx = item.defIdx;
|
||||||
|
this->showPriority = item.showPriority;
|
||||||
|
this->authority = item.authority;
|
||||||
|
}
|
||||||
|
}
|
||||||
92
items/paraitem.h
Normal file
92
items/paraitem.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#ifndef PARAITEM_H
|
||||||
|
#define PARAITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
#include "items/cmdconfig.h"
|
||||||
|
|
||||||
|
class ParaItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ParaItem(QObject *parent = 0);
|
||||||
|
ParaItem(const ParaItem & item);
|
||||||
|
~ParaItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
ParaItem &operator=(const ParaItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const ParaItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int64_t mcenSel; // 机型选择
|
||||||
|
int paraType; // 参数类型(机器参数、工作参数、花样设置参数...)
|
||||||
|
int paraTypeSort; // 参数类型分类(机器参数的速度参数、机器参数的动作参数...)
|
||||||
|
|
||||||
|
int indexInPara; // 参数索引,-1,提示型显示; >= 0,该条目在参数中的位置
|
||||||
|
int bitInWord; // 参数位索引
|
||||||
|
int readonly; // 只读标志
|
||||||
|
int valueType; // 参数值类型 = 0, 无值; = 1, 数字输入型; = 2, 开关选择型; = 3, 列表选择型; = 4, 字符输入型
|
||||||
|
public:
|
||||||
|
QString paraName; // 参数名称
|
||||||
|
public:
|
||||||
|
int64_t value; // 数字输入型数值
|
||||||
|
int64_t minVal; // 输入值范围下限
|
||||||
|
int64_t maxVal; // 输入值范围上限
|
||||||
|
int64_t defValue; // 默认值
|
||||||
|
int afterPoint; // 保留小数位数
|
||||||
|
QString unitStr; // 单位
|
||||||
|
QString valueStr; // 字符输入型字符
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString selList; // 列表选择型参数列表,通过"\n"来分割
|
||||||
|
int selIdx; // 选择项目
|
||||||
|
int defIdx; // 默认选择
|
||||||
|
public:
|
||||||
|
int showPriority; // 显示优先级
|
||||||
|
int authority; // 参数权限
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#define PARA_VALUE_TYPE_NONE 0 // 无
|
||||||
|
#define PARA_VALUE_TYPE_INT 1 // 数值输入型
|
||||||
|
#define PARA_VALUE_TYPE_SW 2 // 开关型
|
||||||
|
#define PARA_VALUE_TYPE_LIST 3 // 列表选择型
|
||||||
|
#define PARA_VALUE_TYPE_STRINPUT 4 // 字符串输入型
|
||||||
|
#define PARA_VALUE_TYPE_CLICK 5 // 点击触发型
|
||||||
|
|
||||||
|
//参数类型(点击触发型的参数种类)
|
||||||
|
#define PARA_TYPE_MACH 0x00000001 // 主控机器参数
|
||||||
|
#define PARA_TYPE_WORK 0x00000002 // 主控工作参数
|
||||||
|
#define PARA_TYPE_DEF_MC 0x00000004 // 出厂默认机器配置参数(读取有效)
|
||||||
|
#define PARA_TYPE_DEF_WK 0x00000008 // 出厂默认机器工作参数(读取有效)
|
||||||
|
#define PARA_TYPE_PATTERN 0x00000010 // 花样参数
|
||||||
|
#define PARA_TYPE_SOFTWARESET 0x00000020 // 软件设置参数
|
||||||
|
#define PARA_TYPE_TIMESET 0x00000040 // 时间设置参数
|
||||||
|
#define PARA_TYPE_COMMONFUN 0x00000080 // 常用功能设置参数
|
||||||
|
#define PARA_TYPE_NETWORKSET 0x00000100 // 网络管理设置参数
|
||||||
|
#define PARA_TYPE_ROOT 0x00000200 // 超级用户参数
|
||||||
|
#define PARA_TYPE_SPINDLETEST 0x00000400 // 主轴研车参数
|
||||||
|
#define PARA_TYPE_HMICONFIGURATION 0x00000800 // 界面配置
|
||||||
|
#define PARA_TYPE_IOTCONFIGURATION 0x00001000 // 物联网配置
|
||||||
|
#define PARA_TYPE_NETWORKSETTINGS 0x00002000 // 网络设置
|
||||||
|
|
||||||
|
//参数分类
|
||||||
|
#define MC_SORT_SPEED 0x0001 // 速度参数
|
||||||
|
#define MC_SORT_ACTION 0x0002 // 动作参数
|
||||||
|
#define MC_SORT_DETECT 0x0004 // 检测参数
|
||||||
|
#define MC_SORT_POSITION 0x0008 // 位置参数
|
||||||
|
#define MC_SORT_SETTING 0x0010 // 设置参数
|
||||||
|
|
||||||
|
//花样参数分类
|
||||||
|
#define PATTERNPARA_SORT_DSTR 0x0001 // dst和dsr文件花样参数
|
||||||
|
#define PATTERNPARA_SORT_QUI 0x0002 // qui文件花样参数
|
||||||
|
#define PATTERNPARA_SORT_PLT 0x0003 // plt文件花样参数
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PARAITEM_H
|
||||||
44
items/parasetitem.cpp
Normal file
44
items/parasetitem.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "parasetitem.h"
|
||||||
|
|
||||||
|
ParaSetItem::ParaSetItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaSetItem::~ParaSetItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaSetItem::ParaSetItem(const ParaSetItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParaSetItem & ParaSetItem::operator= (const ParaSetItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParaSetItem::clean()
|
||||||
|
{
|
||||||
|
m_macType = 0;
|
||||||
|
m_showPriority = 0;
|
||||||
|
m_name.clear();
|
||||||
|
m_topImageName.clear();
|
||||||
|
m_paraType = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParaSetItem::copyData(const ParaSetItem &item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_macType = item.m_macType;
|
||||||
|
this->m_showPriority = item.m_showPriority;
|
||||||
|
this->m_name = item.m_name;
|
||||||
|
this->m_topImageName = item.m_topImageName;
|
||||||
|
this->m_paraType = item.m_paraType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
36
items/parasetitem.h
Normal file
36
items/parasetitem.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef PARASETITEM_H
|
||||||
|
#define PARASETITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ParaSetItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ParaSetItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
~ParaSetItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
ParaSetItem(const ParaSetItem & item);
|
||||||
|
ParaSetItem & operator= (const ParaSetItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const ParaSetItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_macType; // 机器类型
|
||||||
|
int m_showPriority; // 显示优先级
|
||||||
|
QString m_name; // label名称
|
||||||
|
QString m_topImageName; // 顶图图标logo名称
|
||||||
|
int m_paraType; // 参数类型
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARASETITEM_H
|
||||||
43
items/patternsetitem.cpp
Normal file
43
items/patternsetitem.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "patternsetitem.h"
|
||||||
|
|
||||||
|
PatternSetItem::PatternSetItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
PatternSetItem::~PatternSetItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
PatternSetItem::PatternSetItem(const PatternSetItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
PatternSetItem & PatternSetItem::operator= (const PatternSetItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PatternSetItem::clean()
|
||||||
|
{
|
||||||
|
m_macType = 0;
|
||||||
|
m_showPriority = 0;
|
||||||
|
m_name.clear();
|
||||||
|
m_topImageName.clear();
|
||||||
|
m_enumFunction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PatternSetItem::copyData(const PatternSetItem &item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_macType = item.m_macType;
|
||||||
|
this->m_showPriority = item.m_showPriority;
|
||||||
|
this->m_name = item.m_name;
|
||||||
|
this->m_topImageName = item.m_topImageName;
|
||||||
|
this->m_enumFunction = item.m_enumFunction;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
items/patternsetitem.h
Normal file
36
items/patternsetitem.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef PATTERNSETITEM_H
|
||||||
|
#define PATTERNSETITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class PatternSetItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit PatternSetItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
~PatternSetItem();
|
||||||
|
|
||||||
|
public:
|
||||||
|
PatternSetItem(const PatternSetItem & item);
|
||||||
|
PatternSetItem & operator= (const PatternSetItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const PatternSetItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_macType; // 机器类型
|
||||||
|
int m_showPriority; // 显示优先级
|
||||||
|
QString m_name; // label名称
|
||||||
|
QString m_topImageName; // 顶图图标logo名称
|
||||||
|
int m_enumFunction; // 对应的事件的枚举值
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PATTERNSETITEM_H
|
||||||
46
items/sensoritem.cpp
Normal file
46
items/sensoritem.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "sensoritem.h"
|
||||||
|
|
||||||
|
SensorItem::SensorItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorItem::~SensorItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorItem::SensorItem(const SensorItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorItem & SensorItem::operator= (const SensorItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SensorItem::clean()
|
||||||
|
{
|
||||||
|
m_byte_offset = -1; // 字节偏移值
|
||||||
|
m_bit_offset = -1; // 字节内位偏移值
|
||||||
|
m_name.clear(); // 名称
|
||||||
|
m_type = -1; // 传感器类型
|
||||||
|
}
|
||||||
|
|
||||||
|
void SensorItem::copyData(const SensorItem & item)
|
||||||
|
{
|
||||||
|
m_byte_offset = item.m_byte_offset ; // 字节偏移值
|
||||||
|
m_bit_offset = item.m_bit_offset ; // 字节内位偏移值
|
||||||
|
m_name = item.m_name ; // 名称
|
||||||
|
m_type = item.m_type; // 传感器类型
|
||||||
|
}
|
||||||
|
|
||||||
|
void SensorItem::setItemValue(int woffset, int boffset, QString name, int type)
|
||||||
|
{
|
||||||
|
m_byte_offset = woffset ; // 字节偏移值
|
||||||
|
m_bit_offset = boffset ; // 字节内位偏移值
|
||||||
|
m_name = name ; // 名称
|
||||||
|
m_type = type; // 传感器类型
|
||||||
|
}
|
||||||
35
items/sensoritem.h
Normal file
35
items/sensoritem.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef __SENSORITEM_H__
|
||||||
|
#define __SENSORITEM_H__
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#define MAX_SENSOR_NUM (1024*8)
|
||||||
|
|
||||||
|
class SensorItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SensorItem(QObject *parent = 0);
|
||||||
|
~SensorItem();
|
||||||
|
public:
|
||||||
|
SensorItem(const SensorItem & item);
|
||||||
|
SensorItem & operator= (const SensorItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const SensorItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setItemValue(int woffset, int boffset, QString name, int type = -1);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_byte_offset; // 字节偏移值
|
||||||
|
int m_bit_offset; // 字节内的位偏移值
|
||||||
|
QString m_name; // 名称
|
||||||
|
int m_type; // 传感器类型
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __SENSORITEM_H__
|
||||||
43
items/shortcutitem.cpp
Normal file
43
items/shortcutitem.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "shortcutitem.h"
|
||||||
|
|
||||||
|
ShortCutItem::ShortCutItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortCutItem::~ShortCutItem()
|
||||||
|
{
|
||||||
|
clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortCutItem::ShortCutItem(const ShortCutItem & item) : QObject()
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
ShortCutItem & ShortCutItem::operator= (const ShortCutItem & item)
|
||||||
|
{
|
||||||
|
copyData(item);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShortCutItem::clean()
|
||||||
|
{
|
||||||
|
m_macType = 0;
|
||||||
|
m_showPriority = 0;
|
||||||
|
m_name.clear();
|
||||||
|
m_topImageName.clear();
|
||||||
|
m_enumFunction = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShortCutItem::copyData(const ShortCutItem &item)
|
||||||
|
{
|
||||||
|
if (this != &item)
|
||||||
|
{
|
||||||
|
this->m_macType = item.m_macType;
|
||||||
|
this->m_showPriority = item.m_showPriority;
|
||||||
|
this->m_name = item.m_name;
|
||||||
|
this->m_topImageName = item.m_topImageName;
|
||||||
|
this->m_enumFunction = item.m_enumFunction;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
items/shortcutitem.h
Normal file
35
items/shortcutitem.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SHORTCUTITEM_H
|
||||||
|
#define SHORTCUTITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ShortCutItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ShortCutItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
~ShortCutItem();
|
||||||
|
public:
|
||||||
|
ShortCutItem(const ShortCutItem & item);
|
||||||
|
ShortCutItem & operator= (const ShortCutItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void clean();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copyData(const ShortCutItem & item);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_macType; // 机器类型
|
||||||
|
int m_showPriority; // 显示优先级
|
||||||
|
QString m_name; // label名称
|
||||||
|
QString m_topImageName; // 顶图图标logo名称
|
||||||
|
int m_enumFunction; // 对应的事件的枚举值
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SHORTCUTITEM_H
|
||||||
438
machine/comm/comm.cpp
Normal file
438
machine/comm/comm.cpp
Normal file
@ -0,0 +1,438 @@
|
|||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// File Name: comm.cpp
|
||||||
|
// Brief:
|
||||||
|
// Version: 1.0.0
|
||||||
|
// Create Date: 2017/05/08
|
||||||
|
// Create by: Marshal Lee
|
||||||
|
// Copyright:
|
||||||
|
// Copyright (c) 2017, GetonAgain Co., LTD.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Modify by: Marshal Lee
|
||||||
|
// Modify Date: 2017/05/08
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define _IN_COMM_CPP
|
||||||
|
|
||||||
|
#include "comm.h"
|
||||||
|
#include "crc16.h"
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 读空缓冲区
|
||||||
|
void readBuffEmpty(DataExFuns * funs)
|
||||||
|
{
|
||||||
|
int rslt, len;
|
||||||
|
u8 temp;
|
||||||
|
|
||||||
|
len = funs->getRsvLen();
|
||||||
|
|
||||||
|
while (len > 0)
|
||||||
|
{
|
||||||
|
rslt = funs->getCommData(&temp, 1);
|
||||||
|
if (rslt != 1)
|
||||||
|
{
|
||||||
|
rslt = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
// 功能: 从通讯口接收缓冲区中得到一个数据包, 如果有附加数据,包括附加数据
|
||||||
|
// 参数: pPacket, 数据包指针
|
||||||
|
// 返回: >=0, 成功取得一个数据包,包括定长数据包和可变长度数据包,返回值为数据包长度
|
||||||
|
// -1, 参数错误
|
||||||
|
// -2, CRC错误
|
||||||
|
// -3, 数据不足
|
||||||
|
// -4, 没有找到同步序列
|
||||||
|
// -5,等待接收数据超时
|
||||||
|
// -6, 数据包参数错误
|
||||||
|
// -7, 附加数据CRC错误
|
||||||
|
// -8, 发生未知错误
|
||||||
|
|
||||||
|
// 结果: 如果正确取得数据包,或通讯口没有命令, 循环队列尾指针回向后移动
|
||||||
|
|
||||||
|
int getANormalPacket(DataExFuns * funs, DataPacket * pPacket)
|
||||||
|
{
|
||||||
|
int rslt, len;
|
||||||
|
int i;
|
||||||
|
int phase;
|
||||||
|
int status;
|
||||||
|
int exlen;
|
||||||
|
static int rdstatus = 0;
|
||||||
|
static u8 odBuf[LEN_NORMAL_PACKET];
|
||||||
|
|
||||||
|
u8 temp;
|
||||||
|
u8 rdBuf[LEN_NORMAL_PACKET];
|
||||||
|
DataPacket * pDat;
|
||||||
|
|
||||||
|
u8 getBuf[LEN_NORMAL_PACKET-DP_SYNC_LEN];
|
||||||
|
int getBuflen;
|
||||||
|
int getIdx;
|
||||||
|
|
||||||
|
u8 tmpBuf[LEN_NORMAL_PACKET-DP_SYNC_LEN];
|
||||||
|
int tmpBuflen;
|
||||||
|
|
||||||
|
if (funs == NULL || pPacket == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rslt = 0;
|
||||||
|
i = 0; // 扫描字节计数器
|
||||||
|
getBuflen = 0;
|
||||||
|
getIdx = 0;
|
||||||
|
tmpBuflen = 0;
|
||||||
|
pDat = (DataPacket *)rdBuf;
|
||||||
|
|
||||||
|
if (rdstatus == 0)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
len = funs->getRsvLen(); // 得到接收长度
|
||||||
|
len += getBuflen; // 加上已经获取的长度
|
||||||
|
|
||||||
|
if (len < LEN_NORMAL_PACKET)
|
||||||
|
{
|
||||||
|
rslt = -3;
|
||||||
|
break; // 没有足够数据
|
||||||
|
}
|
||||||
|
|
||||||
|
phase = 0;
|
||||||
|
status = 0;
|
||||||
|
rslt = 0;
|
||||||
|
|
||||||
|
// 从接收缓冲区中找数据包
|
||||||
|
while(((len + phase) >= LEN_NORMAL_PACKET) && (phase < LEN_NORMAL_PACKET))
|
||||||
|
{
|
||||||
|
if (getBuflen == 0)
|
||||||
|
{
|
||||||
|
if (phase == 0 && i > MAX_ONCE_SCAN)
|
||||||
|
{
|
||||||
|
rslt = -4;
|
||||||
|
break; // 查找同步序列超出最大单次扫描字节数
|
||||||
|
}
|
||||||
|
|
||||||
|
rslt = funs->getCommData(&temp, 1);
|
||||||
|
if (rslt != 1)
|
||||||
|
{
|
||||||
|
printf("error at GetCommData rslt\r\n");
|
||||||
|
rslt = -8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rslt = 0;
|
||||||
|
i++; // 扫描字数增加
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temp = getBuf[getIdx];
|
||||||
|
getIdx++;
|
||||||
|
getBuflen--;
|
||||||
|
}
|
||||||
|
|
||||||
|
len--; // 剩余长度减小
|
||||||
|
|
||||||
|
pDat->buff.normal[phase] = temp;
|
||||||
|
if (phase < DP_SYNC_LEN) // 识别同步序列
|
||||||
|
{
|
||||||
|
tmpBuflen = 0;
|
||||||
|
|
||||||
|
if (phase == 0)
|
||||||
|
{
|
||||||
|
if (temp == FLDP_SYNC[0])
|
||||||
|
{
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
else if (temp == VLDP_SYNC[0])
|
||||||
|
{
|
||||||
|
status = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = 0;
|
||||||
|
phase = 0;
|
||||||
|
rslt = 0; // 非同步序列
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (status == 1)
|
||||||
|
{
|
||||||
|
if (temp != FLDP_SYNC[phase])
|
||||||
|
{
|
||||||
|
status = 0;
|
||||||
|
phase = 0;
|
||||||
|
rslt = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (status == 2)
|
||||||
|
{
|
||||||
|
if (temp != VLDP_SYNC[phase])
|
||||||
|
{
|
||||||
|
status = 0;
|
||||||
|
phase = 0;
|
||||||
|
rslt = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("error status in GetANormalPacket\r\n");
|
||||||
|
rslt = -8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmpBuf[tmpBuflen] = temp;
|
||||||
|
tmpBuflen++;
|
||||||
|
}
|
||||||
|
|
||||||
|
phase++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rslt != 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phase >= LEN_NORMAL_PACKET) // 得到数据包
|
||||||
|
{
|
||||||
|
u16 crc;
|
||||||
|
crc = calcCrc16(pDat->normal.content, DP_CONT_LEN);
|
||||||
|
if (crc == pDat->normal.crc)
|
||||||
|
{
|
||||||
|
// 得到正确数据包
|
||||||
|
memcpy(pPacket, pDat, LEN_NORMAL_PACKET);
|
||||||
|
|
||||||
|
// printf("GetANormalPacket ok\r\n");
|
||||||
|
rslt = LEN_NORMAL_PACKET;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// CRC 不正确
|
||||||
|
printf("crc error in GetANormalPacket\r\n");
|
||||||
|
// 拷贝需要再判断的数据
|
||||||
|
if (tmpBuflen != 0)
|
||||||
|
{
|
||||||
|
memcpy(getBuf, tmpBuf, tmpBuflen);
|
||||||
|
}
|
||||||
|
getBuflen = tmpBuflen;
|
||||||
|
getIdx = 0;
|
||||||
|
// continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 没有找到同步序列的情况
|
||||||
|
getBuflen = 0;
|
||||||
|
getIdx = 0;
|
||||||
|
// continue;
|
||||||
|
}
|
||||||
|
}while(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rdstatus == 1)
|
||||||
|
{
|
||||||
|
memcpy(pPacket, odBuf, LEN_NORMAL_PACKET);
|
||||||
|
rslt = LEN_NORMAL_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 附加数据
|
||||||
|
if (rslt == LEN_NORMAL_PACKET)
|
||||||
|
{
|
||||||
|
if (memcmp(pPacket->normal.sync, VLDP_SYNC, DP_SYNC_LEN) == 0) // 是可变长度数据包
|
||||||
|
{
|
||||||
|
exlen = pPacket->vldp.exlen;
|
||||||
|
if (exlen > MAX_EXDP_LEN)
|
||||||
|
{
|
||||||
|
printf("data exlen error, len=%d\r\n", exlen);
|
||||||
|
return -6; // 数据包参数错误
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(pPacket->buff.exData, 0, MAX_EXDP_LEN);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
status = 0; // 作为历史计数器
|
||||||
|
// 读取附加数据
|
||||||
|
do
|
||||||
|
{
|
||||||
|
rslt = funs->getCommData(pPacket->buff.exData, exlen);
|
||||||
|
if (rslt == exlen)
|
||||||
|
{
|
||||||
|
u16 crc;
|
||||||
|
// 校验CRC
|
||||||
|
crc = calcCrc16(pPacket->buff.exData, exlen);
|
||||||
|
if (crc == pPacket->vldp.excrc)
|
||||||
|
{
|
||||||
|
// printf("get exdata ok\r\n");
|
||||||
|
rslt = exlen+LEN_NORMAL_PACKET;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("crc error at get exdata\r\n");
|
||||||
|
rslt = -7; // CRC错误
|
||||||
|
}
|
||||||
|
rdstatus = 0;
|
||||||
|
break; // 得到数据
|
||||||
|
}
|
||||||
|
else if (rslt == 0)
|
||||||
|
{
|
||||||
|
memcpy(odBuf, pPacket, LEN_NORMAL_PACKET);
|
||||||
|
rdstatus = 1;
|
||||||
|
rslt = -3;
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
// 数据不足
|
||||||
|
if (funs->delay != NULL)
|
||||||
|
{
|
||||||
|
funs->delay(1); // 延时等待
|
||||||
|
}
|
||||||
|
len = funs->getRsvLen(); // 得到接收数据长度
|
||||||
|
qDebug()<<"getRsvLen"<<len;
|
||||||
|
if (len != status) // 和上次长度比较
|
||||||
|
{
|
||||||
|
status = len;
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
else // 如果没有变化,则计数器增加
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
if (i > GTEX_TIME_OUT) // 如果无变化计数器值大于超时值
|
||||||
|
{
|
||||||
|
qDebug()<<"call GetCommData timeout";
|
||||||
|
rslt = -5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug()<<"error after call GetCommData";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}while(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 添加数据到发送队列中, 通过通讯口发送数据
|
||||||
|
// 参数: pPacket, 需要发送的数据,已经正确存放在了相应字段。
|
||||||
|
// 结果:
|
||||||
|
// 0, 可以发送, 添加到了发送数据队列中
|
||||||
|
// -1, 参数错误
|
||||||
|
// -2,发送错误
|
||||||
|
// 1, 队列已满, 不能发送
|
||||||
|
int sendAPacket(DataExFuns * funs, DataPacket * pPacket)
|
||||||
|
{
|
||||||
|
int rslt;
|
||||||
|
int freelen, sendlen;
|
||||||
|
|
||||||
|
if (pPacket == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(pPacket->normal.sync, FLDP_SYNC, DP_SYNC_LEN) == 0)
|
||||||
|
{
|
||||||
|
sendlen = LEN_NORMAL_PACKET;
|
||||||
|
}
|
||||||
|
else if (memcmp(pPacket->normal.sync, VLDP_SYNC, DP_SYNC_LEN) == 0)
|
||||||
|
{
|
||||||
|
sendlen = LEN_NORMAL_PACKET + pPacket->vldp.exlen;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("para err, not a corrected packet\r\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
freelen = funs->getTrsFreeLen();
|
||||||
|
|
||||||
|
if (freelen < sendlen)
|
||||||
|
{
|
||||||
|
// printf("buff is full in SendAPacket\r\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rslt = funs->sendCommData(pPacket->datbuff, sendlen);
|
||||||
|
if (rslt != sendlen)
|
||||||
|
{
|
||||||
|
printf("error at call SendCommData, rslt=%d\r\n", rslt);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 打包一个固定长度数据包
|
||||||
|
// 参数:
|
||||||
|
// pPacket, 需要打包的数据包,其中除了sync和crc的部分已经就绪
|
||||||
|
// 结果:
|
||||||
|
// 0, 打包好数据
|
||||||
|
// -1, 参数错误
|
||||||
|
|
||||||
|
int packetAFLDP(DataPacket * pPacket)
|
||||||
|
{
|
||||||
|
if (pPacket == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pPacket->normal.sync, FLDP_SYNC, DP_SYNC_LEN);
|
||||||
|
pPacket->normal.crc = calcCrc16(pPacket->normal.content, DP_CONT_LEN);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 打包一个可变长度数据包
|
||||||
|
// 参数: pPacket, 需要打包的数据包,需要填充其中的 SYNC EXLEN EXCRC 和 EXDAT 等部分
|
||||||
|
// pExdat, 附加数据,可以为空
|
||||||
|
// exlen,附加数据长度,可以为0
|
||||||
|
// 结果:
|
||||||
|
// 0, 打包好数据
|
||||||
|
// -1, 参数错误
|
||||||
|
// -2,
|
||||||
|
|
||||||
|
int packetAVLDP(DataPacket * pPacket, u8 * pExdat, u16 exlen)
|
||||||
|
{
|
||||||
|
if (pPacket == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pExdat == NULL)
|
||||||
|
{
|
||||||
|
exlen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pPacket->vldp.sync, VLDP_SYNC, DP_SYNC_LEN);
|
||||||
|
pPacket->vldp.exlen = exlen;
|
||||||
|
pPacket->vldp.excrc = calcCrc16(pExdat, exlen);
|
||||||
|
pPacket->vldp.crc = calcCrc16(pPacket->normal.content, DP_CONT_LEN);
|
||||||
|
if (exlen != 0)
|
||||||
|
{
|
||||||
|
memcpy(pPacket->vldp.exData, pExdat, exlen);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
228
machine/comm/comm.h
Normal file
228
machine/comm/comm.h
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// File Name: comm.h
|
||||||
|
// Brief:
|
||||||
|
// Version: 1.0.0
|
||||||
|
// Create Date: 2017/05/08
|
||||||
|
// Create by: Marshal Lee
|
||||||
|
// Copyright:
|
||||||
|
// Copyright (c) 2017, GetonAgain Co., LTD.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Modify by: Marshal Lee
|
||||||
|
// Modify Date: 2017/05/08
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef __COMM_H__
|
||||||
|
#define __COMM_H__
|
||||||
|
|
||||||
|
#include "typedef.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <stdio.h>
|
||||||
|
//------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 通讯数据包定义
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
/*
|
||||||
|
一、数据包格式
|
||||||
|
|
||||||
|
1. 固定长度数据包格式
|
||||||
|
|
||||||
|
|-------------------------------------------------------------------|-----------|
|
||||||
|
| 数据识别序列 | 数据内容 | 校验字 |
|
||||||
|
|-------------------------------------------------------------------|-----------|
|
||||||
|
| B0 B1 B2 B3 | B4 B5 | B6 B7 B8 B9 B10 B11 B12 B13 | B14 B15 |
|
||||||
|
|-------------------------------------------------------------------|-----------|
|
||||||
|
| 固定序列如下 | | 参数,不同命令定义不同 | B4--B13的 |
|
||||||
|
| | 数据包ID | 具体定义参考命令详细说明 | |
|
||||||
|
| 'F','L','D','P' | | | 16位CRC |
|
||||||
|
|-------------------------------------------------------------------|-----------|
|
||||||
|
|
||||||
|
2. 可变长度数据包格式
|
||||||
|
|
||||||
|
|---------------------------------------------------------------------------|-----------|----------------
|
||||||
|
| 数据识别序列 | 数据内容 | 校验字 | 附加数据 |
|
||||||
|
|---------------------------------------------------------------------------|-----------|---------------|
|
||||||
|
| B0 B1 B2 B3 | B4 B5 | B6 B7 | B8 B9 | B10 B11 B12 B13 | B14 B15 | B16--Bn |
|
||||||
|
|---------------------------------------------------------------------------|-----------|---------------|
|
||||||
|
| 固定序列如下 | | 附加 | 附加 | 参数,不同命令 | B4--B13的 | 数据内容 |
|
||||||
|
| | 数据包ID | 数据 | 数据 | 定义不同,定义 | | |
|
||||||
|
| 'V','L','D','P' | | 长度 | 校验字 | 参考命令详细说明 | 16位CRC | |
|
||||||
|
|---------------------------------------------------------------------------|-----------|---------------|
|
||||||
|
|
||||||
|
附加数据长度取值范围为 0--1024
|
||||||
|
*/
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
|
#define DP_SYNC_LEN 4 // 数据识别序列长度
|
||||||
|
#define DP_CONT_LEN 10 // 数据内容长度
|
||||||
|
#define DP_CRC_LEN 2 // 校验字长度
|
||||||
|
#define MAX_EXDP_LEN 1024 // 最大附加数据长度
|
||||||
|
|
||||||
|
#define LEN_NORMAL_PACKET (DP_SYNC_LEN+DP_CONT_LEN+DP_CRC_LEN)
|
||||||
|
|
||||||
|
#define MAX_INDP_PARA 8
|
||||||
|
|
||||||
|
#ifdef _IN_COMM_CPP
|
||||||
|
|
||||||
|
//最早
|
||||||
|
//const u8 FLDP_SYNC[DP_SYNC_LEN] =
|
||||||
|
//{
|
||||||
|
// 'F','L','D','P',
|
||||||
|
//};
|
||||||
|
|
||||||
|
//const u8 VLDP_SYNC[DP_SYNC_LEN] =
|
||||||
|
//{
|
||||||
|
// 'V','L','D','P',
|
||||||
|
//};
|
||||||
|
|
||||||
|
//期间
|
||||||
|
//const u8 FLDP_SYNC[DP_SYNC_LEN] =
|
||||||
|
//{
|
||||||
|
// 'F','L','P','S',
|
||||||
|
//};
|
||||||
|
|
||||||
|
//const u8 VLDP_SYNC[DP_SYNC_LEN] =
|
||||||
|
//{
|
||||||
|
// 'V','L','P','S',
|
||||||
|
//};
|
||||||
|
|
||||||
|
//最新
|
||||||
|
const u8 FLDP_SYNC[DP_SYNC_LEN] =
|
||||||
|
{
|
||||||
|
'F','S','F','D',
|
||||||
|
};
|
||||||
|
|
||||||
|
const u8 VLDP_SYNC[DP_SYNC_LEN] =
|
||||||
|
{
|
||||||
|
'V','S','F','D',
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
extern const u8 FLDP_SYNC[DP_SYNC_LEN];
|
||||||
|
extern const u8 VLDP_SYNC[DP_SYNC_LEN];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
u8 datbuff[LEN_NORMAL_PACKET+MAX_EXDP_LEN]; // dat buff 方式
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u8 normal[LEN_NORMAL_PACKET];
|
||||||
|
u8 exData[MAX_EXDP_LEN];
|
||||||
|
} __attribute__ ((packed)) buff; // buff方式
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u8 sync[DP_SYNC_LEN];
|
||||||
|
u8 content[DP_CONT_LEN];
|
||||||
|
u16 crc;
|
||||||
|
} __attribute__ ((packed)) normal; // 通用方式
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u8 sync[DP_SYNC_LEN];
|
||||||
|
u16 cmd;
|
||||||
|
u8 para[8];
|
||||||
|
u16 crc;
|
||||||
|
} __attribute__ ((packed)) fldp; // fldp方式
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u8 sync[DP_SYNC_LEN];
|
||||||
|
u16 cmd;
|
||||||
|
u16 exlen;
|
||||||
|
u16 excrc;
|
||||||
|
u8 para[4];
|
||||||
|
u16 crc;
|
||||||
|
u8 exData[MAX_EXDP_LEN];
|
||||||
|
} __attribute__ ((packed)) vldp; // vldp方式
|
||||||
|
|
||||||
|
} DataPacket;
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int (*sendCommData)(u8 *, int);
|
||||||
|
int (*getCommData)(u8 *, int);
|
||||||
|
int (*getRsvLen)(void);
|
||||||
|
int (*getTrsFreeLen)(void);
|
||||||
|
void (*delay)(u32);
|
||||||
|
} DataExFuns;
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 读空缓冲区
|
||||||
|
void readBuffEmpty(DataExFuns * funs);
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 从通讯口接收缓冲区中得到一个数据包,
|
||||||
|
// 只能取得普通数据包结构. 如果数据包还有附加数据, 那么需要用 GetExCommData 函数取得
|
||||||
|
// 参数: pPacket, 数据包指针
|
||||||
|
// 返回: >=0, 成功取得一个数据包,包括定长数据包和可变长度数据包,返回值为数据包长度
|
||||||
|
// -1, 参数错误
|
||||||
|
// -2, CRC错误
|
||||||
|
// -3, 数据不足
|
||||||
|
// -4, 没有找到同步序列
|
||||||
|
// -5,等待接收数据超时
|
||||||
|
// -6, 数据包参数错误
|
||||||
|
// -7, 附加数据CRC错误
|
||||||
|
// -8, 发生未知错误
|
||||||
|
|
||||||
|
// 结果: 如果正确取得数据包,或通讯口没有命令, 循环队列尾指针回向后移动
|
||||||
|
|
||||||
|
#define MAX_ONCE_SCAN (LEN_NORMAL_PACKET*10) // 一次扫描最大字节数
|
||||||
|
#define GTEX_TIME_OUT 100 // 得到数据包超时时间,单位是ms
|
||||||
|
|
||||||
|
int getANormalPacket(DataExFuns * funs, DataPacket * pPacket);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 添加数据到发送队列中, 通过通讯口发送数据
|
||||||
|
// 参数: pPacket, 需要发送的数据,已经正确存放在了相应字段。
|
||||||
|
// 结果:
|
||||||
|
// 0, 可以发送, 添加到了发送数据队列中
|
||||||
|
// -1, 参数错误
|
||||||
|
// -2,发送错误
|
||||||
|
// 1, 队列已满, 不能发送
|
||||||
|
int sendAPacket(DataExFuns * funs, DataPacket * pPacket);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 打包一个固定长度数据包
|
||||||
|
// 参数:
|
||||||
|
// pPacket, 需要打包的数据包,其中除了sync和crc的部分已经就绪
|
||||||
|
// 结果:
|
||||||
|
// 0, 打包好数据
|
||||||
|
// -1, 参数错误
|
||||||
|
|
||||||
|
int packetAFLDP(DataPacket * pPacket);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 功能: 打包一个可变长度数据包
|
||||||
|
// 参数: pPacket, 需要打包的数据包,需要填充其中的 SYNC EXLEN EXCRC 和 EXDAT 等部分
|
||||||
|
// pExdat, 附加数据,可以为空
|
||||||
|
// exlen,附加数据长度,可以为0
|
||||||
|
// 结果:
|
||||||
|
// 0, 打包好数据
|
||||||
|
// -1, 参数错误
|
||||||
|
// -2,
|
||||||
|
|
||||||
|
int packetAVLDP(DataPacket * pPacket, u8 * pExdat, u16 exlen);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
16
machine/comm/config.h
Normal file
16
machine/comm/config.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef __CONFIG_H__
|
||||||
|
#define __CONFIG_H__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "typedef.h"
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
|
||||||
|
#define EMBROIDERY
|
||||||
|
#define MAX_EXDP_LEN 1024 // 最大附加数据长度
|
||||||
|
|
||||||
|
#define SEW 8 //缝纫
|
||||||
|
#define IMAGE_TYPE (QImage::Format_ARGB32)
|
||||||
|
|
||||||
|
#endif
|
||||||
159
machine/comm/crc16.cpp
Normal file
159
machine/comm/crc16.cpp
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// File Name: crc16.cpp
|
||||||
|
// Brief:
|
||||||
|
// Version: 1.0.0
|
||||||
|
// Create Date: 2017/05/08
|
||||||
|
// Create by: Marshal Lee
|
||||||
|
// Copyright:
|
||||||
|
// Copyright (c) 2017, GetonAgain Co., LTD.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Modify by: Marshal Lee
|
||||||
|
// Modify Date: 2017/05/08
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#include "crc16.h"
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifdef USE_CRC_TABLE
|
||||||
|
|
||||||
|
// 16 位 crc 列表
|
||||||
|
u16 CRC16_LIST[256] =
|
||||||
|
{
|
||||||
|
0x0000, 0x3096, 0x612C, 0x51BA, 0xC419, 0xF48F, 0xA535, 0x95A3,
|
||||||
|
0x8832, 0xB8A4, 0xE91E, 0xD988, 0x4C2B, 0x7CBD, 0x2D07, 0x1D91,
|
||||||
|
0x1064, 0x20F2, 0x7148, 0x41DE, 0xD47D, 0xE4EB, 0xB551, 0x85C7,
|
||||||
|
0x9856, 0xA8C0, 0xF97A, 0xC9EC, 0x5C4F, 0x6CD9, 0x3D63, 0x0DF5,
|
||||||
|
0x20C8, 0x105E, 0x41E4, 0x7172, 0xE4D1, 0xD447, 0x85FD, 0xB56B,
|
||||||
|
0xA8FA, 0x986C, 0xC9D6, 0xF940, 0x6CE3, 0x5C75, 0x0DCF, 0x3D59,
|
||||||
|
0x30AC, 0x003A, 0x5180, 0x6116, 0xF4B5, 0xC423, 0x9599, 0xA50F,
|
||||||
|
0xB89E, 0x8808, 0xD9B2, 0xE924, 0x7C87, 0x4C11, 0x1DAB, 0x2D3D,
|
||||||
|
0x4190, 0x7106, 0x20BC, 0x102A, 0x8589, 0xB51F, 0xE4A5, 0xD433,
|
||||||
|
0xC9A2, 0xF934, 0xA88E, 0x9818, 0x0DBB, 0x3D2D, 0x6C97, 0x5C01,
|
||||||
|
0x51F4, 0x6162, 0x30D8, 0x004E, 0x95ED, 0xA57B, 0xF4C1, 0xC457,
|
||||||
|
0xD9C6, 0xE950, 0xB8EA, 0x887C, 0x1DDF, 0x2D49, 0x7CF3, 0x4C65,
|
||||||
|
0x6158, 0x51CE, 0x0074, 0x30E2, 0xA541, 0x95D7, 0xC46D, 0xF4FB,
|
||||||
|
0xE96A, 0xD9FC, 0x8846, 0xB8D0, 0x2D73, 0x1DE5, 0x4C5F, 0x7CC9,
|
||||||
|
0x713C, 0x41AA, 0x1010, 0x2086, 0xB525, 0x85B3, 0xD409, 0xE49F,
|
||||||
|
0xF90E, 0xC998, 0x9822, 0xA8B4, 0x3D17, 0x0D81, 0x5C3B, 0x6CAD,
|
||||||
|
0x8320, 0xB3B6, 0xE20C, 0xD29A, 0x4739, 0x77AF, 0x2615, 0x1683,
|
||||||
|
0x0B12, 0x3B84, 0x6A3E, 0x5AA8, 0xCF0B, 0xFF9D, 0xAE27, 0x9EB1,
|
||||||
|
0x9344, 0xA3D2, 0xF268, 0xC2FE, 0x575D, 0x67CB, 0x3671, 0x06E7,
|
||||||
|
0x1B76, 0x2BE0, 0x7A5A, 0x4ACC, 0xDF6F, 0xEFF9, 0xBE43, 0x8ED5,
|
||||||
|
0xA3E8, 0x937E, 0xC2C4, 0xF252, 0x67F1, 0x5767, 0x06DD, 0x364B,
|
||||||
|
0x2BDA, 0x1B4C, 0x4AF6, 0x7A60, 0xEFC3, 0xDF55, 0x8EEF, 0xBE79,
|
||||||
|
0xB38C, 0x831A, 0xD2A0, 0xE236, 0x7795, 0x4703, 0x16B9, 0x262F,
|
||||||
|
0x3BBE, 0x0B28, 0x5A92, 0x6A04, 0xFFA7, 0xCF31, 0x9E8B, 0xAE1D,
|
||||||
|
0xC2B0, 0xF226, 0xA39C, 0x930A, 0x06A9, 0x363F, 0x6785, 0x5713,
|
||||||
|
0x4A82, 0x7A14, 0x2BAE, 0x1B38, 0x8E9B, 0xBE0D, 0xEFB7, 0xDF21,
|
||||||
|
0xD2D4, 0xE242, 0xB3F8, 0x836E, 0x16CD, 0x265B, 0x77E1, 0x4777,
|
||||||
|
0x5AE6, 0x6A70, 0x3BCA, 0x0B5C, 0x9EFF, 0xAE69, 0xFFD3, 0xCF45,
|
||||||
|
0xE278, 0xD2EE, 0x8354, 0xB3C2, 0x2661, 0x16F7, 0x474D, 0x77DB,
|
||||||
|
0x6A4A, 0x5ADC, 0x0B66, 0x3BF0, 0xAE53, 0x9EC5, 0xCF7F, 0xFFE9,
|
||||||
|
0xF21C, 0xC28A, 0x9330, 0xA3A6, 0x3605, 0x0693, 0x5729, 0x67BF,
|
||||||
|
0x7A2E, 0x4AB8, 0x1B02, 0x2B94, 0xBE37, 0x8EA1, 0xDF1B, 0xEF8D
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef SHIFT_RIGHT // 如果是右移
|
||||||
|
|
||||||
|
#define CRC_GEN 0xa001 // 使用多项式 0xa001
|
||||||
|
|
||||||
|
#else // 如果是左移
|
||||||
|
|
||||||
|
#define CRC_GEN 0x8005 // 使用多项式 0x8005
|
||||||
|
|
||||||
|
#endif // #ifdef SHIFT_RIGHT
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
u16 addCrc16(u16 crcword, u8 dat)
|
||||||
|
{
|
||||||
|
#ifdef USE_CRC_TABLE // 查表法crc
|
||||||
|
crcword = (crcword >> 8) ^ CRC16_LIST[(crcword ^ dat) & 0xFF];
|
||||||
|
#else
|
||||||
|
u8 i;
|
||||||
|
crcword ^= dat;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
#ifdef SHIFT_RIGHT // 右移计算crc
|
||||||
|
if ((LOBYTE(crcword) & 0x01) != 0)
|
||||||
|
{
|
||||||
|
crcword >>= 1;
|
||||||
|
crcword ^= CRC_GEN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
crcword >>= 1;
|
||||||
|
}
|
||||||
|
#else // 左移计算crc
|
||||||
|
if ((HIBYTE(crcword) & 0x80) != 0)
|
||||||
|
{
|
||||||
|
crcword <<= 1;
|
||||||
|
crcword ^= CRC_GEN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
crcword <<= 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return crcword;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
u16 calcCrc16(u8 * pBuf, int lenBuf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
u16 crcword = CRC_INIT;
|
||||||
|
|
||||||
|
for (i = 0; i < lenBuf; i++)
|
||||||
|
{
|
||||||
|
crcword = addCrc16(crcword, pBuf[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return crcword;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
u8 calcCheckSum8(u8 * pBuf, int lenBuf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
u8 checksum = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < lenBuf; i++)
|
||||||
|
{
|
||||||
|
checksum += pBuf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return checksum;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
u32 calcCheckSum32(u8 * pBuf, int lenBuf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
u32 checksum = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < lenBuf; i++)
|
||||||
|
{
|
||||||
|
checksum += pBuf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return checksum;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
60
machine/comm/crc16.h
Normal file
60
machine/comm/crc16.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// File Name: crc16.h
|
||||||
|
// Brief:
|
||||||
|
// Version: 1.0.0
|
||||||
|
// Create Date: 2017/05/08
|
||||||
|
// Create by: Marshal Lee
|
||||||
|
// Copyright:
|
||||||
|
// Copyright (c) 2017, GetonAgain Co., LTD.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Modify by: Marshal Lee
|
||||||
|
// Modify Date: 2017/05/08
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __CRC16_H__
|
||||||
|
#define __CRC16_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
CRC16 算法模块
|
||||||
|
|
||||||
|
提供查表法和移位法两种 CRC16 算法
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "typedef.h"
|
||||||
|
|
||||||
|
#define USE_CRC_TABLE // 用查表法crc, 否则, 用移位法计算
|
||||||
|
#define SHIFT_RIGHT // 右移位
|
||||||
|
|
||||||
|
#ifdef USE_CRC_TABLE
|
||||||
|
|
||||||
|
#define CRC_INIT 0x0000 // 并且crc初值为0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifdef SHIFT_RIGHT // 如果是右移
|
||||||
|
|
||||||
|
#define CRC_INIT 0xFFFF // crc初值为0xFFFF
|
||||||
|
|
||||||
|
#else // 如果是左移
|
||||||
|
|
||||||
|
#define CRC_INIT 0x0000 // 并且crc初值为0
|
||||||
|
|
||||||
|
#endif // #ifdef SHIFT_RIGHT
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
u16 calcCrc16(u8 * pBuf, int lenBuf);
|
||||||
|
|
||||||
|
|
||||||
|
u8 calcCheckSum8(u8 * pBuf, int lenBuf);
|
||||||
|
|
||||||
|
u32 calcCheckSum32(u8 * pBuf, int lenBuf);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
74
machine/comm/crc32.cpp
Normal file
74
machine/comm/crc32.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// File Name: crc32.c
|
||||||
|
// Brief:
|
||||||
|
// Version: 1.0.0
|
||||||
|
// Create Date: 2018/08/13
|
||||||
|
// Create by: Marshal Lee
|
||||||
|
// Copyright:
|
||||||
|
// Copyright (c) 2019, GetonAgain Co., LTD.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Modify by: Marshal Lee
|
||||||
|
// Modify Date: 2018/08/13
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#include "crc32.h"
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static const u32 CRC32_LIST[256] =
|
||||||
|
{
|
||||||
|
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
|
||||||
|
0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
|
||||||
|
0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
|
||||||
|
0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
|
||||||
|
0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||||
|
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
|
||||||
|
0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
|
||||||
|
0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
|
||||||
|
0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
|
||||||
|
0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||||
|
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
|
||||||
|
0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
|
||||||
|
0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
|
||||||
|
0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
|
||||||
|
0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||||
|
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
|
||||||
|
0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
|
||||||
|
0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
|
||||||
|
0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
|
||||||
|
0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||||
|
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
|
||||||
|
0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
|
||||||
|
0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
|
||||||
|
0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
|
||||||
|
0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||||
|
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
|
||||||
|
0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
|
||||||
|
0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
|
||||||
|
0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
|
||||||
|
0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||||
|
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
|
||||||
|
0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
u32 addCrc32(u32 crcword, u8 dat)
|
||||||
|
{
|
||||||
|
return (crcword >> 8) ^ CRC32_LIST[((crcword ^ dat) & 0xFF)];
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 calcCrc32(u8 * pBuf, int lenBuf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
u32 crcword = CRC32_INIT;
|
||||||
|
|
||||||
|
for (i = 0; i < lenBuf; i++)
|
||||||
|
{
|
||||||
|
crcword = addCrc32(crcword, pBuf[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return crcword;
|
||||||
|
}
|
||||||
33
machine/comm/crc32.h
Normal file
33
machine/comm/crc32.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
// File Name: crc32.h
|
||||||
|
// Brief:
|
||||||
|
// Version: 1.0.0
|
||||||
|
// Create Date: 2018/08/13
|
||||||
|
// Create by: Marshal Lee
|
||||||
|
// Copyright:
|
||||||
|
// Copyright (c) 2019, GetonAgain Co., LTD.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Modify by: Marshal Lee
|
||||||
|
// Modify Date: 2018/08/13
|
||||||
|
//-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __CRC32_H__
|
||||||
|
#define __CRC32_H__
|
||||||
|
|
||||||
|
/*
|
||||||
|
CRC32 算法模块
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "typedef.h"
|
||||||
|
|
||||||
|
#define CRC32_INIT 0xffffffff // crc初值
|
||||||
|
|
||||||
|
|
||||||
|
u32 addCrc32(u32 crcword, u8 dat);
|
||||||
|
u32 calcCrc32(u8 * pBuf, int lenBuf);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
495
machine/comm/datadef.h
Normal file
495
machine/comm/datadef.h
Normal file
@ -0,0 +1,495 @@
|
|||||||
|
#ifndef __DATADEF_H__
|
||||||
|
#define __DATADEF_H__
|
||||||
|
|
||||||
|
#include "typedef.h"
|
||||||
|
#include "config.h"
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define PATTERN_LARGE_NEEDLES 1280000
|
||||||
|
|
||||||
|
// 绝对位置数据
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl; //控制字节
|
||||||
|
u8 attr; //属性字节
|
||||||
|
WORD action;//控制动作
|
||||||
|
double ax; //X位置
|
||||||
|
double ay; //Y位置
|
||||||
|
double ar; //R角度
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DsAbsItem;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
QList<DsAbsItem> absItemList;
|
||||||
|
|
||||||
|
}LineItem;
|
||||||
|
|
||||||
|
// 画图格式数据
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl;//控制字节
|
||||||
|
u8 attr;//属性字节
|
||||||
|
|
||||||
|
WORD action;// 附加动作
|
||||||
|
double bx, by;//绘制起点,第一机头
|
||||||
|
double ex, ey;//绘制终点,第一机头
|
||||||
|
double bx2, by2;//绘制起点,第二机头
|
||||||
|
double ex2, ey2;//绘制终点,第二机头
|
||||||
|
s32 ar;//角度
|
||||||
|
u32 rgb;
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DispItem;
|
||||||
|
|
||||||
|
// 编辑花样格式数据
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl;//控制字节
|
||||||
|
u8 attr;//属性字节
|
||||||
|
|
||||||
|
WORD action;// 附加动作
|
||||||
|
double bx, by;//绘制起点
|
||||||
|
double ex, ey;//绘制终点
|
||||||
|
s16 ar;//角度
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) ViewItem;
|
||||||
|
|
||||||
|
//刀压测试的获取XY增益参数
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
s16 GapArray[25][20]; // X*Y
|
||||||
|
u16 enFlag; // 参数有效标志
|
||||||
|
u8 cellx; // X向格子数
|
||||||
|
u8 celly; // Y向格子数
|
||||||
|
s16 xcellgap; // X向格子间距,单位mm
|
||||||
|
s16 ycellgap; // Y向格子间距,单位mm
|
||||||
|
s16 collectStartX; // X向采集起始位置,单位mm
|
||||||
|
s16 collectStartY; // Y向采集起始位置,单位mm
|
||||||
|
u16 rev[0x200-25*20-6];
|
||||||
|
} __attribute__ ((packed)) KnifeGapPara;
|
||||||
|
|
||||||
|
|
||||||
|
//机头间距表地址
|
||||||
|
typedef struct {
|
||||||
|
unsigned char iswork; //1-8机头是否工作
|
||||||
|
unsigned char doubleHead; //双机头
|
||||||
|
unsigned short int distance1_2; //机头2和机头1的机头间距(单位0.1mm,范围0-5000.0)
|
||||||
|
unsigned short int distance1_3;
|
||||||
|
unsigned short int distance1_4;
|
||||||
|
unsigned short int distance1_5;
|
||||||
|
unsigned short int distance1_6;
|
||||||
|
unsigned short int distance1_7;
|
||||||
|
unsigned short int distance1_8;
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) HeadTable;
|
||||||
|
|
||||||
|
// 画图格式数据
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl;//控制字节
|
||||||
|
u8 attr;//属性字节
|
||||||
|
|
||||||
|
WORD action;// 附加动作
|
||||||
|
s16 bx, by;//绘制起点
|
||||||
|
s16 ex, ey;//绘制终点
|
||||||
|
s16 ar;//角度
|
||||||
|
HeadTable headtable;
|
||||||
|
u32 rgb;
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) Disp_HeadItem;
|
||||||
|
|
||||||
|
// 执行数据定义
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl; // 控制字节
|
||||||
|
u8 attr; // 属性字节
|
||||||
|
s16 dx; // X偏移
|
||||||
|
s16 dy; // Y偏移
|
||||||
|
s16 dr; // R偏移
|
||||||
|
u16 len; // xy分量合成长度
|
||||||
|
u8 action[2]; //附加动作
|
||||||
|
|
||||||
|
u8 rev[4]; // 保留
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DataItem, Ds16Item;
|
||||||
|
|
||||||
|
// ds8格式
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl; // 控制字节
|
||||||
|
u8 attr; // 属性字节
|
||||||
|
s16 dx; // X偏移
|
||||||
|
s16 dy; // Y偏移
|
||||||
|
s16 dr; // R偏移
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) Ds8Item;
|
||||||
|
|
||||||
|
// 兼容dsr格式
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u8 ctrl; // 控制字节
|
||||||
|
u8 attr; // 属性字节
|
||||||
|
u8 dx; // X偏移
|
||||||
|
u8 dy; // Y偏移
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DsrItem, Ds4Item;
|
||||||
|
|
||||||
|
|
||||||
|
// 双字节压缩格式
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
s8 cdx; // X数据
|
||||||
|
s8 cdy; // Y数据
|
||||||
|
|
||||||
|
/*
|
||||||
|
格式定义
|
||||||
|
cdx x分量控制数据
|
||||||
|
cdy y分量控制数据
|
||||||
|
|
||||||
|
每个字节的最低位为控制位,高7个位为数据位。数据位的最高位是符号位。
|
||||||
|
|
||||||
|
两个控制位合在一起形成4种控制数据,定义如下:
|
||||||
|
cdx.0 cdy.0
|
||||||
|
0 0 缝纫数据,数据范围从-128 -- +126, 只有偶数可用(精度0.2mm),单位0.1mm
|
||||||
|
0 1 空走数据,数据范围从-128 -- +126, 只有偶数可用(精度0.2mm),单位0.1mm
|
||||||
|
1 0 大步空走数据,数据范围从-128 -- +126, 只有偶数可用(精度2mm),单位1mm
|
||||||
|
1 1 控制数据,数据位定义为控制码和参数 cdx 为控制码, cdx 为参数
|
||||||
|
|
||||||
|
*/
|
||||||
|
}__attribute__ ((packed)) ToBItem, Ds2Item;
|
||||||
|
|
||||||
|
|
||||||
|
// ctrl 定义
|
||||||
|
// 控制字节, 作为功能码,定义如下
|
||||||
|
|
||||||
|
#define DATA_NULL 0x00 // 文件结束
|
||||||
|
#define DATA_SEWING 0x01 // 缝纫数据, 该数据需要缝纫机针扎一次(主轴可以转动多圈(如果有跳针功能的话)), 同时 X, Y,R 偏移运动dx,dy,dr, 框步进式运动或连续运动
|
||||||
|
#define DATA_OFFSET 0x02 // 偏移数据, 该数据只移动 X, Y,R 偏移 dx,dy,dr,连续运动
|
||||||
|
#define DATA_CUTTING 0x03 // 切刀数据, 该数据需要切刀先运转,同时 X, Y,R 偏移 dx,dy,dr,根据切刀类型选择动框方式
|
||||||
|
#define DATA_LASER 0x04 // 激光数据, 该数据需要激光出光, 同时X, Y,R偏移 dx,dy,dr,框连续运动,激光强度和运动线速度有关系
|
||||||
|
#define DATA_DRAWING 0x05 // 记号数据, 该数据需要记号笔先放下来, 同时X, Y,R偏移dx,dy,dr,框连续运动
|
||||||
|
#define DATA_SEWING_R 0x06 // 右机头缝纫,该数据需要缝纫机针扎一次(主轴可以转动多圈(如果有跳针功能的话)), 同时 X, Y,R 偏移运动dx,dy,dr, 框步进式运动或连续运动
|
||||||
|
|
||||||
|
#define DATA_SECF_SEW 0x11 // 第二框缝纫
|
||||||
|
#define DATA_SECF_OFST 0x12 // 第二框偏移
|
||||||
|
|
||||||
|
#define DATA_SECF_SEW_R 0x16 // 第二框右机头缝纫,该数据需要缝纫机针扎一次(主轴可以转动多圈(如果有跳针功能的话)), 同时 X, Y,R 偏移运动dx,dy,dr, 框步进式运动或连续运动
|
||||||
|
|
||||||
|
// 兼容DSR控制码
|
||||||
|
#define DATA_SYNCSEW 0x07 // 同步缝纫数据, 该数据需要缝纫机针扎一次, 同时 X, Y,R 偏移运动 dx,dy,dr,X2, Y2 也运动 dx,dy,框步进式运动或连续运动
|
||||||
|
#define DATA_PAUSE_OLD 0x08 // 暂停
|
||||||
|
#define DATA_ANGLE_OLD 0x09 // 拐点
|
||||||
|
#define DATA_CUT_OLD 0x0A // 剪线
|
||||||
|
#define DATA_END_OLD 0x10 // 结束码
|
||||||
|
#define DATA_OFFSET_SEC 0x12 // 第二机头偏移(右机头偏移)
|
||||||
|
|
||||||
|
#define DATA_JUMP 0x0B // 跳针数据,该数据要求缝纫机主轴不动, 但 X, Y,R 偏移运动 dx,dy,dr, 框步进式运动或连续运动
|
||||||
|
#define DATA_PUNCH 0x0C // 冲孔数据, 该数据需要冲孔主轴运转一圈,同时 X, Y,R 偏移 dx,dy,dr,
|
||||||
|
#define DATA_EMB 0x0D // 绣花数据,该数据需要平绣针扎一次, 同时 X, Y,偏移运动dx,dy, 框步进式运动
|
||||||
|
#define DATA_CHGND_OLD 0x0E // 换色功能码 lxs 20220628添加
|
||||||
|
#define DATA_SYNCOFST 0x0F // 同步偏移数据
|
||||||
|
#define DATA_MIRROR_SEC 0x17 // 镜像缝纫数据
|
||||||
|
#define DATA_MIRROR_OFT_SEC 0x1F // 镜像偏移数据
|
||||||
|
|
||||||
|
#define DATA_MILLING 0x21 // 铣刀数据
|
||||||
|
#define DATA_DRILL 0x22 // 钻孔数据
|
||||||
|
#define DATA_RKNIFE 0x23 // 圆刀数据, 该数据需要震刀先运转,同时 X, Y,R 偏移 dx,dy,dr,
|
||||||
|
#define DATA_SKNIFE 0x24 // 震刀数据, 该数据需要震刀先运转,同时 X, Y,R 偏移 dx,dy,dr,
|
||||||
|
|
||||||
|
#define DATA_BASE1 0x2A // 基座1数据
|
||||||
|
#define DATA_BASE2 0x2B // 基座2数据
|
||||||
|
#define DATA_BASE3 0x2C // 基座3数据
|
||||||
|
|
||||||
|
#define DATA_EKNIFE1 0x2D // 偏心刀1数据
|
||||||
|
#define DATA_EKNIFE2 0x2E // 偏心刀2数据
|
||||||
|
|
||||||
|
#define DATA_END 0x80 // 结束码
|
||||||
|
#define DATA_PAUSE 0x81 // 暂停功能码
|
||||||
|
#define DATA_CHGND 0x82 // 换色
|
||||||
|
#define DATA_CUTTRD 0x83 // 剪线功能码
|
||||||
|
|
||||||
|
#define DATA_SYNC_CUTTER 0x88 // 左右机头剪线,下位机取名叫 DATA_CUTTRD_R
|
||||||
|
#define DATA_CUTTER_SEC 0x87 // 右机头剪线,下位机取名叫 DATA_CUTTRD_L
|
||||||
|
|
||||||
|
#define DATA_ANGLE 0x89 // 拐点
|
||||||
|
|
||||||
|
// atrr, 属性字节,作为运动属性字节
|
||||||
|
|
||||||
|
// 缝纫针步的属性定义:
|
||||||
|
|
||||||
|
// attr.7, 夹线力度等级H
|
||||||
|
// attr.6, 夹线力度等级L
|
||||||
|
// attr.5, 保留
|
||||||
|
// attr.4, 缝纫回针标志
|
||||||
|
// attr.3, 压脚高度等级H
|
||||||
|
// attr.2, 压脚高度等级L
|
||||||
|
// attr.1, 速度等级H
|
||||||
|
// attr.0, 速度等级L
|
||||||
|
|
||||||
|
#define ATTR_CLAMP_LV 0xC0 // 夹线力度等级
|
||||||
|
#define ATTR_RESEW 0x10 // 回针标志
|
||||||
|
#define ATTR_FOOT_LV 0x0C // 压脚高度等级
|
||||||
|
#define ATTR_SPD_LV 0x03 // 速度等级
|
||||||
|
|
||||||
|
// 缝纫针步的属性定义:
|
||||||
|
// dx, x向偏移值, 有符号数, 范围为 -32768--32767, 单位为 0.01mm
|
||||||
|
// dy, y向偏移值, 有符号数, 范围为 -32768--32767, 单位为 0.01mm
|
||||||
|
// dr, r向偏移值, 有符号数, 范围为 -32768--32767, 单位为 0.0001 弧度
|
||||||
|
// len, xy 分量的合成长度,无符号数,范围0--65535, 单位为 0.01mm
|
||||||
|
|
||||||
|
#define HEAD_NAME_STR_LEN 0x20
|
||||||
|
#define HEAD_FIX_INFO_LEN 0x32
|
||||||
|
|
||||||
|
// 铣刀的属性定义:
|
||||||
|
|
||||||
|
// attr.7, 保留
|
||||||
|
// attr.6, 保留
|
||||||
|
// attr.5, 保留
|
||||||
|
// attr.4, 保留
|
||||||
|
// attr.3, 刀压深度HH
|
||||||
|
// attr.2, 刀压深度HL
|
||||||
|
// attr.1, 刀压深度LH
|
||||||
|
// attr.0, 刀压深度LL
|
||||||
|
|
||||||
|
#define ATTR_HIGH_MARK 0x0F // 铣刀刀压深度调整掩码
|
||||||
|
|
||||||
|
#pragma pack(1)//设定为1字节对齐
|
||||||
|
//ds16头文件-发给下位机的
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// 0x00
|
||||||
|
char fileName[32]; // 文件名称
|
||||||
|
|
||||||
|
// 0x20
|
||||||
|
u32 dataSize; // 数据字节数
|
||||||
|
u32 itemNums; // 数据项个数
|
||||||
|
u16 bytesPerItem; // 每项占的字节数
|
||||||
|
u16 bytesPerBlk; // 数据内容划分块大小
|
||||||
|
u32 dataChecksum; // 数据累加校验和
|
||||||
|
u16 checkCrc; // 前面6个字段的CRC校验,(6个字段分别为:文件名称,字节数,项个数,每项字节数,每块字节数,数据累加和的CRC校验值)
|
||||||
|
|
||||||
|
// 0x32
|
||||||
|
u16 rev0;
|
||||||
|
u32 fileid; // 文件唯一标识符,识别是否为同一个文件
|
||||||
|
|
||||||
|
// 0x38
|
||||||
|
u8 reserved1[0x40-0x38]; // 保留区1
|
||||||
|
|
||||||
|
// 0x40
|
||||||
|
s32 anchorX; // 定位点坐标X
|
||||||
|
s32 anchorY; // 定位点坐标Y
|
||||||
|
|
||||||
|
// 0x48
|
||||||
|
s32 beginX; // 数据起点坐标X
|
||||||
|
s32 beginY; // 数据起点坐标Y
|
||||||
|
s32 beginR; // 数据起点坐标R
|
||||||
|
|
||||||
|
// 0x54
|
||||||
|
s32 minX;
|
||||||
|
s32 maxX;
|
||||||
|
s32 minY;
|
||||||
|
s32 maxY; // 轮廓范围
|
||||||
|
|
||||||
|
// 0x64
|
||||||
|
u32 sizeX;
|
||||||
|
u32 sizeY; // 裁片大小
|
||||||
|
|
||||||
|
// 0x6C
|
||||||
|
s32 anchorX2; // 定位点坐标X2
|
||||||
|
s32 anchorY2; // 定位点坐标Y2
|
||||||
|
s32 beginX2; // 数据起点坐标X2
|
||||||
|
s32 beginY2; // 数据起点坐标Y2
|
||||||
|
s32 beginR2; // 数据起点坐标Z2
|
||||||
|
|
||||||
|
// 0x80
|
||||||
|
u32 runAct; // 附加动作,
|
||||||
|
// bit0: 0:完成后不拍照 1:完成后拍照
|
||||||
|
|
||||||
|
// 0x84
|
||||||
|
// bit0,偏移点X向允许 0,不允许 1,允许
|
||||||
|
// bit1,偏移点Y向允许 0,不允许 1,允许
|
||||||
|
// bit2,反复优先级 0,X向优先 1,Y向优先
|
||||||
|
// bit3,二次剪线 0,不允许 1,允许
|
||||||
|
u32 EnFlag; //
|
||||||
|
|
||||||
|
s32 offsetX; // 偏移点X
|
||||||
|
s32 offsetY;
|
||||||
|
|
||||||
|
// 0x90
|
||||||
|
u8 xRepeatNums; // X向反复次数,范围0-99,默认0
|
||||||
|
u8 yRepeatNums; // Y向反复次数
|
||||||
|
s32 xRepeatDistance; // X向反复距离,单位mm,精度0.01,范围-100000-100000,默认0
|
||||||
|
s32 yRepeatDistance; // Y向反复距离
|
||||||
|
|
||||||
|
// 0x9A
|
||||||
|
u8 reserved2[0x200-0x9A];
|
||||||
|
|
||||||
|
// 0x200
|
||||||
|
u8 switchNeedleTable[0x400-0x200]; // 色序设定表, 支持512个色序设定
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DataDs16FileHead;//下发给主控的ds16文件头
|
||||||
|
#pragma pack(1)//恢复对齐状态
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// 0
|
||||||
|
char HMIVerStr[16]; // 界面版本
|
||||||
|
|
||||||
|
// 4
|
||||||
|
u32 machineNumber; // 机器编号
|
||||||
|
|
||||||
|
// 5
|
||||||
|
u16 motorNum; //电机个数
|
||||||
|
u16 debugProgress; //调试进度
|
||||||
|
// 6
|
||||||
|
char fileName[32]; // 文件名称
|
||||||
|
|
||||||
|
#if(0)
|
||||||
|
// 52
|
||||||
|
char sensorStartBtn; // 启动按钮1
|
||||||
|
char sensorStopBtn; // 暂停按钮1
|
||||||
|
char sensorJogBtn; // 点动按钮1
|
||||||
|
char sensorMainFrameXZeroPos; // 主框架X零位
|
||||||
|
char sensorMainFrameYZeroPos; // 主框架Y零位
|
||||||
|
char sensorMainFrameXNegLimit; // 主框架X负限位
|
||||||
|
char sensorMainFrameYNegLimit; // 主框架Y负限位
|
||||||
|
char sensorMainFrameXPosLimit; // 主框架X正限位
|
||||||
|
char sensorMainFrameYPosLimit; // 主框架Y正限位
|
||||||
|
char sensorScissorsReturn; // 剪刀回位
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//14
|
||||||
|
char deliveryTime[32]; //交付日期
|
||||||
|
|
||||||
|
//22
|
||||||
|
u32 workProgress; //机器工作进度(花样执行进度)
|
||||||
|
|
||||||
|
//26
|
||||||
|
u32 workState; //工作状态
|
||||||
|
|
||||||
|
//27
|
||||||
|
u32 startPins; //开始针数
|
||||||
|
|
||||||
|
//28
|
||||||
|
u32 endPins; //结束针数
|
||||||
|
|
||||||
|
//29
|
||||||
|
quint64 startTime; //开始时间
|
||||||
|
|
||||||
|
//31
|
||||||
|
quint64 endTime; //结束时间
|
||||||
|
|
||||||
|
//33
|
||||||
|
u32 outCounter; //产量统计
|
||||||
|
|
||||||
|
//34
|
||||||
|
u32 rev2[256-34];
|
||||||
|
|
||||||
|
} __attribute__ ((packed)) HMILotData; // 界面物联网数据
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
// 升级文件头
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// 0x00
|
||||||
|
char fileName[32]; // 文件名称
|
||||||
|
// 0x20
|
||||||
|
u32 dataSize; // 数据字节数
|
||||||
|
u32 dataChecksum; // 数据累加校验和
|
||||||
|
|
||||||
|
// 0x28
|
||||||
|
u8 reserved1[0x30-0x28]; // 保留区1
|
||||||
|
// 0x30
|
||||||
|
u8 reserved2[0x64-0x30]; // 保留区1
|
||||||
|
|
||||||
|
// 0x64
|
||||||
|
u8 reserved3[0x80-0x64]; // 保留区2
|
||||||
|
|
||||||
|
// 0x80
|
||||||
|
u8 reserved4[0x100-0x80];
|
||||||
|
}__attribute__ ((packed)) AppFileHead;
|
||||||
|
|
||||||
|
|
||||||
|
// 文件参数结构
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// 0x00
|
||||||
|
u8 hdIdenti[0x40];
|
||||||
|
|
||||||
|
// 0x40
|
||||||
|
s32 anchorX; // 定位点坐标X
|
||||||
|
s32 anchorY; // 定位点坐标Y
|
||||||
|
// 0x48
|
||||||
|
s32 beginX; // 数据起点坐标X
|
||||||
|
s32 beginY; // 数据起点坐标Y
|
||||||
|
s32 beginR; // 数据起点坐标Z
|
||||||
|
|
||||||
|
// 0x54
|
||||||
|
s32 minX;
|
||||||
|
s32 maxX;
|
||||||
|
s32 minY;
|
||||||
|
s32 maxY; // 轮廓范围
|
||||||
|
|
||||||
|
// 0x64
|
||||||
|
u32 sizeX;
|
||||||
|
u32 sizeY; // 裁片大小
|
||||||
|
|
||||||
|
// 0x6C
|
||||||
|
s32 anchorX2; // 定位点坐标X2
|
||||||
|
s32 anchorY2; // 定位点坐标Y2
|
||||||
|
s32 beginX2; // 数据起点坐标X2
|
||||||
|
s32 beginY2; // 数据起点坐标Y2
|
||||||
|
s32 beginR2; // 数据起点坐标Z2
|
||||||
|
|
||||||
|
// 0x80
|
||||||
|
u8 reserved0[0x200-0x80];
|
||||||
|
// 0x200
|
||||||
|
u8 reserved1[0x400-0x200];
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DataFilePara;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
s32 anchorX; // 定位点坐标X
|
||||||
|
s32 anchorY; // 定位点坐标Y
|
||||||
|
s32 beginX; // 数据起点坐标X
|
||||||
|
s32 beginY; // 数据起点坐标Y
|
||||||
|
|
||||||
|
}__attribute__ ((packed)) DataFilePos;
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// 文件执行参数结构
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32 newIdx;
|
||||||
|
s32 newXPos;
|
||||||
|
s32 newYPos;
|
||||||
|
s32 newRPos;
|
||||||
|
u32 newColorIdx; // 新针位
|
||||||
|
u32 rev[256-5];
|
||||||
|
}__attribute__ ((packed)) FileExecPara;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//参数文件头
|
||||||
|
struct ParaFile
|
||||||
|
{
|
||||||
|
unsigned char s_head[4] ; // 默认 PARA
|
||||||
|
int s_type ; // 默认 0
|
||||||
|
int s_len ; // 数据 默认 4096
|
||||||
|
|
||||||
|
unsigned int s_para_buff[1024] ; //工作 参数体
|
||||||
|
|
||||||
|
unsigned short s_crc ; //参数体的CRC
|
||||||
|
|
||||||
|
unsigned short rev ; //预留 保持 结构体四字节对齐
|
||||||
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
2033
machine/comm/protocol.h
Normal file
2033
machine/comm/protocol.h
Normal file
File diff suppressed because it is too large
Load Diff
107
machine/comm/typedef.h
Normal file
107
machine/comm/typedef.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#ifndef TYPEDEF_H
|
||||||
|
#define TYPEDEF_H
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL ((void *) 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FALSE
|
||||||
|
#define FALSE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#define DATA_VALID 0x55AA
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef int BOOL;
|
||||||
|
typedef unsigned char BYTE;
|
||||||
|
typedef unsigned short int WORD;
|
||||||
|
typedef unsigned long int DWORD;
|
||||||
|
|
||||||
|
typedef unsigned char u8;
|
||||||
|
typedef unsigned short int u16;
|
||||||
|
typedef unsigned int u32;
|
||||||
|
typedef char s8;
|
||||||
|
typedef short int s16;
|
||||||
|
typedef int s32;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
#define U8_MAX ((u8)255)
|
||||||
|
#define S8_MAX ((s8)127)
|
||||||
|
#define S8_MIN ((s8)(-128))
|
||||||
|
#define U16_MAX ((u16)65535u)
|
||||||
|
#define S16_MAX ((s16)32767)
|
||||||
|
#define S16_MIN ((s16)(-32768))
|
||||||
|
#define U32_MAX ((u32)4294967295uL)
|
||||||
|
#define S32_MAX ((s32)2147483647uL)
|
||||||
|
#define S32_MIN ((s32)(-2147483648uL))
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
#ifndef LOBYTE
|
||||||
|
#define LOBYTE(w) ((BYTE)(((WORD)(w)) & 0xff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIBYTE
|
||||||
|
#define HIBYTE(w) ((BYTE)((((WORD)(w)) >> 8) & 0xff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOWORD
|
||||||
|
#define LOWORD(l) ((WORD)(((DWORD)(l)) & 0xffff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIWORD
|
||||||
|
#define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xffff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAKEWORD
|
||||||
|
#define MAKEWORD(a, b) ((WORD)((BYTE)(a)) | (((WORD)((BYTE)(b))) << 8))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAKEDWORD
|
||||||
|
#define MAKEDWORD(a, b) ((DWORD)((WORD)(a)) | (((DWORD)((WORD)(b))) << 16))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LOHFBYTE
|
||||||
|
#define LOHFBYTE(b) ((BYTE)((b) & 0x0f))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIHFBYTE
|
||||||
|
#define HIHFBYTE(b) ((BYTE)(((b) >> 4) & 0x0f))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAKEBYTE
|
||||||
|
#define MAKEBYTE(a, b) ((BYTE)((BYTE)((a) & 0x0f)) | ((BYTE)(((BYTE)((b) & 0x0f)) << 4)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef PI
|
||||||
|
|
||||||
|
#define PI 3.1415926535897932
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TYPEDEF_H
|
||||||
157
machine/comport.cpp
Normal file
157
machine/comport.cpp
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
#include "comport.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ComPort::ComPort(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_pSerialport(NULL),
|
||||||
|
m_running(0),
|
||||||
|
m_pReadTimer(NULL)
|
||||||
|
{
|
||||||
|
m_pReadTimer = new QTimer(this);
|
||||||
|
m_pReadTimer->setInterval(20);
|
||||||
|
connect(m_pReadTimer, SIGNAL(timeout()), this, SLOT(getDataFromPort()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ComPort::~ComPort()
|
||||||
|
{
|
||||||
|
m_pReadTimer->stop();
|
||||||
|
delete m_pReadTimer;
|
||||||
|
|
||||||
|
if (m_pSerialport != NULL)
|
||||||
|
{
|
||||||
|
m_pSerialport->close();
|
||||||
|
delete m_pSerialport;
|
||||||
|
m_pSerialport = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComPort::setComPortName(QString portName)
|
||||||
|
{
|
||||||
|
m_portName.clear();
|
||||||
|
|
||||||
|
if(portName.length() > 0)//串口名称不为空
|
||||||
|
{
|
||||||
|
m_portName = portName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//windows平台下
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
//得到串口设备
|
||||||
|
QString path = "HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM";
|
||||||
|
QSettings *settings = new QSettings(path,QSettings::NativeFormat);
|
||||||
|
QStringList key = settings->allKeys();
|
||||||
|
int num = (int)key.size();
|
||||||
|
|
||||||
|
//打开注册表
|
||||||
|
unsigned long keysize,type,valuesize;
|
||||||
|
wchar_t keyname[256]; //键名数组
|
||||||
|
char keyvalue[256]; //键值数组
|
||||||
|
keysize = sizeof(keyname);
|
||||||
|
valuesize = sizeof(keyvalue);
|
||||||
|
int indexnum;
|
||||||
|
HKEY hKey;
|
||||||
|
QString commresult = "";
|
||||||
|
QString valuemessage = "";//键值
|
||||||
|
QString strkey = "HARDWARE\\DEVICEMAP\\SERIALCOMM";//子键路径
|
||||||
|
LPCWSTR subkey = reinterpret_cast<const wchar_t *>(strkey.utf16());
|
||||||
|
|
||||||
|
if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,subkey,0,KEY_READ,&hKey)!=0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//循环得到串口设备的名称
|
||||||
|
for(int i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
valuemessage.clear();
|
||||||
|
commresult.clear();
|
||||||
|
keysize=sizeof(keyname);
|
||||||
|
valuesize=sizeof(keyvalue);
|
||||||
|
indexnum=i;//要读取键值的索引号
|
||||||
|
|
||||||
|
if(::RegEnumValue(hKey,indexnum,keyname,&keysize,0,&type,(BYTE*)keyvalue,&valuesize) == 0)//列举键名和值
|
||||||
|
{
|
||||||
|
for(unsigned int j = 0; j < valuesize; j++)
|
||||||
|
{
|
||||||
|
if(keyvalue[j]!=0x00)
|
||||||
|
{
|
||||||
|
valuemessage.append(keyvalue[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(m_portName.length() <= 0)
|
||||||
|
{
|
||||||
|
m_portName = valuemessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commresult="nokey";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
::RegCloseKey(hKey);//关闭注册表
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
m_portName = COMNAME;
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComPort::initComm()
|
||||||
|
{
|
||||||
|
if (m_running == 0)
|
||||||
|
{
|
||||||
|
qDebug() << "InitComm ComPort at thread" << QThread::currentThread() << "name" << m_portName;
|
||||||
|
|
||||||
|
struct PortSettings myComSetting = {BAUD115200, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 0, 20};
|
||||||
|
m_pSerialport = new QextSerialPort(m_portName, myComSetting);
|
||||||
|
bool bOpen = m_pSerialport->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
|
||||||
|
if(bOpen == false)
|
||||||
|
{
|
||||||
|
emit siSerialPortOpenState(m_running);
|
||||||
|
qDebug()<<"m_pSerialport->open fail ";
|
||||||
|
return;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
qDebug()<<"m_pSerialport->open success ";
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Start timer";
|
||||||
|
|
||||||
|
m_pReadTimer->start();
|
||||||
|
m_running = 1;
|
||||||
|
emit siSerialPortOpenState(m_running);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComPort::getDataFromPort()
|
||||||
|
{
|
||||||
|
// qDebug("GetDataFromPort");
|
||||||
|
// qDebug() << "ComPort GetDataFromPort" << QThread::currentThread();
|
||||||
|
|
||||||
|
if (m_running != 0 && m_pSerialport != NULL)
|
||||||
|
{
|
||||||
|
QByteArray dat = m_pSerialport->readAll();
|
||||||
|
if (dat.size() != 0)
|
||||||
|
{
|
||||||
|
//qDebug()<<"dat.size()="<<dat.size();
|
||||||
|
qDebug()<< "m_pSerialport->readAll() :"<<dat.data();
|
||||||
|
emit (siReceiveData(dat));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComPort::slotSendData(QByteArray dat)
|
||||||
|
{
|
||||||
|
// qDebug() << "ComPort SlotSendData" << QThread::currentThread();
|
||||||
|
|
||||||
|
if (m_running != 0 && m_pSerialport != NULL && dat.size() != 0)
|
||||||
|
{
|
||||||
|
qDebug()<<"ComPort::slotSendData send data" << QString(dat);
|
||||||
|
m_pSerialport->write(dat.data(), dat.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
43
machine/comport.h
Normal file
43
machine/comport.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef COMPORT_H
|
||||||
|
#define COMPORT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "qextserial/qextserialport.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
#define COMNAME "/dev/ttyS1"
|
||||||
|
#define COMNAME485 "/dev/ttyS2"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class ComPort : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ComPort(QObject *parent = 0);
|
||||||
|
~ComPort();
|
||||||
|
private:
|
||||||
|
QextSerialPort * m_pSerialport;
|
||||||
|
int m_running;
|
||||||
|
QTimer * m_pReadTimer;
|
||||||
|
QString m_portName;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setComPortName(QString portName);//获取所有串口名称
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void getDataFromPort();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void siReceiveData(QByteArray dat);
|
||||||
|
void siSerialPortOpenState(int val);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void initComm();
|
||||||
|
void slotSendData(QByteArray dat);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COMTHREAD_H
|
||||||
518
machine/error.cpp
Normal file
518
machine/error.cpp
Normal file
@ -0,0 +1,518 @@
|
|||||||
|
|
||||||
|
#include "error.h"
|
||||||
|
#include "comm/protocol.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#define CASE_OP(cd, str) \
|
||||||
|
{\
|
||||||
|
case cd:\
|
||||||
|
errinfo = str;\
|
||||||
|
break;\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define ERR_NONE 0x0000 // 没有错误
|
||||||
|
#define ERR_NO_POWER 0x0001 // 没有上电
|
||||||
|
#define ERR_NO_AIR 0x0002 // 气压不足
|
||||||
|
#define ERR_NOT_SAFE 0x0003 // 安全区域介入
|
||||||
|
#define ERR_EXPIRATION 0x0004 // 使用时限已到
|
||||||
|
#define ERR_DRIVER 0x0005 // 驱动器报警
|
||||||
|
#define ERR_FILL_DATA 0x0006 // 填充数据错误
|
||||||
|
#define ERR_NOT_ALLOWED 0x0007 // 不允许工作状态
|
||||||
|
#define ERR_CTRL_ERR 0x0008 // 控制错误
|
||||||
|
#define ERR_FPGA_ERR 0x0009 // FPGA软件版本错误
|
||||||
|
#define ERR_BUTTON_NOUP 0x000A // 等待按钮抬起超时
|
||||||
|
#define ERR_FPGA_RESET 0x000B // FPGA复位错误
|
||||||
|
#define ERR_NO_READY 0x000C // 外设未就绪
|
||||||
|
#define ERR_NO_SEND_ERR 0x000D // 传输数据错误
|
||||||
|
#define ERR_EDTION_ERR 0x000E // 程序版本错误
|
||||||
|
#define ERR_WORK_DONE 0x000F // 完成产量
|
||||||
|
|
||||||
|
#define ERR_LMT_POSITIVE 0x0010 // 正向限位
|
||||||
|
#define ERR_LMT_NEGATIVE 0x0011 // 反向限位
|
||||||
|
#define ERR_RUN_ALM 0x0012 // 运动报警
|
||||||
|
#define ERR_RUN_LIMIT 0x0013 // 运动限位
|
||||||
|
#define ERR_RUN_EMS 0x0014 // 运动急停
|
||||||
|
#define ERR_MV_PARA 0x0015 // 运动参数错误
|
||||||
|
#define ERR_MC_PARA 0x0016 // 机器参数错误
|
||||||
|
#define ERR_IN_PARA 0x0017 // 输入参数错误
|
||||||
|
#define ERR_FPGA_HARD_ERR 0x0018 // FPGA硬件版本错误
|
||||||
|
|
||||||
|
#define ERR_NOT_WORKSTA 0x001A // 不能工作状态
|
||||||
|
#define ERR_NOT_MOVESTA 0x001B // 禁止移框状态
|
||||||
|
#define ERR_NOFAM_ZERO 0x001C // 归零前需要卸下模板
|
||||||
|
#define ERR_NO_ADDAIR 0x001D // 没有加气
|
||||||
|
|
||||||
|
#define ERR_MTZ_RIGHT 0x001F // 归零成功
|
||||||
|
#define ERR_MTZ_ERROR 0x0020 // 归零错误
|
||||||
|
#define ERR_COOR_SYSTM 0x0021 // 坐标系统错误
|
||||||
|
#define ERR_OUT_RANGE 0x0022 // 目标位置越界
|
||||||
|
#define ERR_X_LIT_POSI 0x0023 // X正向限位
|
||||||
|
#define ERR_X_LIT_NEGA 0x0024 // X反向限位
|
||||||
|
#define ERR_Y_LIT_POSI 0x0025 // Y正向限位
|
||||||
|
#define ERR_Y_LIT_NEGA 0x0026 // Y反向限位
|
||||||
|
|
||||||
|
#define ERR_FEED_MANUAL 0x0027 // 进料处于手动状态
|
||||||
|
#define ERR_MC_MANUAL 0x0028 // 机器处于手动状态
|
||||||
|
#define ERR_KEY_SW_OFF 0x0029 // 机器钥匙开关关闭
|
||||||
|
#define ERR_ALM_WATERTANK 0x002A // 水箱报警
|
||||||
|
#define ERR_ALM_COVEROPEN 0x002B // 开盖报警
|
||||||
|
#define ERR_LIGHTCURTAINS1 0x002C // 光幕1介入
|
||||||
|
#define ERR_LIGHTCURTAINS2 0x002D // 光幕2介入
|
||||||
|
#define ERR_AIR_POWER 0x002E // 气压不足
|
||||||
|
#define ERR_PRESS_SENSOR 0x002F // 压料传感器错误
|
||||||
|
#define ERR_CLIP_SENSOR 0x0030 // 夹布传感器错误
|
||||||
|
#define ERR_NO_MATERIEL 0x0031 // 缺料报警
|
||||||
|
#define ERR_CUTFRAME 0x0032 // 边框切割错误
|
||||||
|
#define ERR_MC_AUTO 0x0033 // 机器处于自动状态
|
||||||
|
#define ERR_DOOR_TIMEOUT 0x0034 // 开关门超时
|
||||||
|
#define ERR_NOT_AT_OFFSET 0x0035 // 不在偏移点
|
||||||
|
#define ERR_NO_PHOTO_FILE 0x0036 // 没有拍照文件
|
||||||
|
#define ERR_FEED_AUTO 0x0037 // 进料处于自动状态
|
||||||
|
#define ERR_GANTRY_NOT_POS 0x0038 // 龙门不到位
|
||||||
|
#define ERR_GUARDRAIL_OPEN 0x0039 // 安全门未关闭
|
||||||
|
|
||||||
|
#define ERR_LIGHTCURTAINS3 0x003A // 光幕3介入
|
||||||
|
#define ERR_LIGHTCURTAINS4 0x003B // 光幕4介入
|
||||||
|
#define ERR_PRINT_ERROR 0x003C // 喷墨异常
|
||||||
|
#define ERR_PRINT_NOT_AT_BAK 0x003D // 喷墨不在停止位置
|
||||||
|
|
||||||
|
#define ERR_LOAD_EMPTY 0x003E // 上料储料空料
|
||||||
|
#define ERR_RECV_FULL 0x003F // 收料储料满料
|
||||||
|
|
||||||
|
#define ERR_NO_DATA 0x0040 // 无数据
|
||||||
|
#define ERR_DATA_ERROR 0x0041 // 数据错误
|
||||||
|
#define ERR_GRAPH_OUT_RANGE 0x0042 // 图形超出范围
|
||||||
|
#define ERR_CUTTER2_ERROR 0x0043 // 切割机2故障
|
||||||
|
#define ERR_PHOTO_ERROR 0x0044 // 拍照识别错误
|
||||||
|
#define ERR_CUT_RANGE_OVERFLOW 0x0045 // 切割范围重叠
|
||||||
|
#define ERR_CUTTER1_ERROR 0x0046 // 切割机1故障
|
||||||
|
#define ERR_CUTTER1_CLEERR 0x0047 // 切割机1故障 失效
|
||||||
|
#define ERR_CUTTER2_CLEERR 0x0048 // 切割机2故障 失效
|
||||||
|
#define ERR_CUTTER_WASTE 0x0049 // 切割机废料
|
||||||
|
#define ERR_INPUT_EDGE 0x004A // 进料偏移
|
||||||
|
#define ERR_INPUT_TIMEOUT 0x004B // 进料超时
|
||||||
|
#define ERR_EDGE_TBREAK 0x004E // 边缝机头断线
|
||||||
|
#define ERR_CHANGE_MAR 0x004F // 更换料盘
|
||||||
|
|
||||||
|
#define ERR_MS_NOT_ZERO 0x0050 // 主轴不在零位
|
||||||
|
#define ERR_HK_NOT_ZERO 0x0051 // 旋梭不在零位
|
||||||
|
#define ERR_MS_NOT_SYNC 0x0052 // 针梭不同步
|
||||||
|
#define ERR_RO_NOT_SYNC 0x0053 // 旋转不同步
|
||||||
|
#define ERR_CUTTER_NOT_POS 0x0054 // 剪刀不在回位(注:该报错码是缝纫剪刀)
|
||||||
|
#define ERR_HEAD_NOT_HIGH 0x0055 // 机头不在高位
|
||||||
|
#define ERR_HEAD_NOT_LOW 0x0056 // 机头不在低位
|
||||||
|
#define ERR_LIGHTCURTAINS 0x0057 // 光幕介入
|
||||||
|
#define ERR_UPER_TBREAK 0x0058 // 面线断线
|
||||||
|
#define ERR_BOBBIN_TBREAK 0x0059 // 底线断线
|
||||||
|
#define ERR_NEEDLE_NOT_HIGH 0x005A // 机针不在高位
|
||||||
|
#define ERR_SEND_N1CMD_TIMOUT 0x005B // 发送主轴命令超时
|
||||||
|
#define ERR_SEND_N1CMD_FAIL 0x005C // 发送主轴命令失败
|
||||||
|
#define ERR_TRANS_TIMEOUT 0x005D // 执行命令超时
|
||||||
|
#define ERR_NOT_AT_POS 0x005E // 模版不到位
|
||||||
|
#define ERR_LIFT_TIMEOUT 0x005F // 机头升降超时
|
||||||
|
|
||||||
|
#define ERR_HEAD_NOT_SAFE 0x0060 // 机头不在安全区域
|
||||||
|
#define ERR_HD1_ND_NOT_ZERO 0x0061 // 机头1针不在零位
|
||||||
|
#define ERR_HD2_ND_NOT_ZERO 0x0062 // 机头2针不在零位
|
||||||
|
#define ERR_HD3_ND_NOT_ZERO 0x0063 // 机头3针不在零位
|
||||||
|
#define ERR_HD4_ND_NOT_ZERO 0x0064 // 机头4针不在零位
|
||||||
|
#define ERR_HD5_ND_NOT_ZERO 0x0065 // 机头5针不在零位
|
||||||
|
#define ERR_HD6_ND_NOT_ZERO 0x0066 // 机头6针不在零位
|
||||||
|
#define ERR_HD7_ND_NOT_ZERO 0x0067 // 机头7针不在零位
|
||||||
|
#define ERR_HD8_ND_NOT_ZERO 0x0068 // 机头8针不在零位
|
||||||
|
#define ERR_HD9_ND_NOT_ZERO 0x0069 // 机头9针不在零位
|
||||||
|
|
||||||
|
#define ERR_HD1_CUTTER_NOT_POS 0x0071 // 机头1剪刀不在回位
|
||||||
|
#define ERR_HD2_CUTTER_NOT_POS 0x0072 // 机头2剪刀不在回位
|
||||||
|
#define ERR_HD3_CUTTER_NOT_POS 0x0073 // 机头3剪刀不在回位
|
||||||
|
#define ERR_HD4_CUTTER_NOT_POS 0x0074 // 机头4剪刀不在回位
|
||||||
|
#define ERR_HD5_CUTTER_NOT_POS 0x0075 // 机头5剪刀不在回位
|
||||||
|
#define ERR_HD6_CUTTER_NOT_POS 0x0076 // 机头6剪刀不在回位
|
||||||
|
#define ERR_HD7_CUTTER_NOT_POS 0x0077 // 机头7剪刀不在回位
|
||||||
|
#define ERR_HD8_CUTTER_NOT_POS 0x0078 // 机头8剪刀不在回位
|
||||||
|
#define ERR_HD9_CUTTER_NOT_POS 0x0079 // 机头9剪刀不在回位
|
||||||
|
|
||||||
|
#define ERR_PUNCH_NOT_ZERO 0x0080 // 冲孔主轴不在零位
|
||||||
|
|
||||||
|
#define ERR_R_LIT_POSI 0x0081 // 旋转正向限位
|
||||||
|
#define ERR_R_LIT_NEGA 0x0082 // 旋转反向限位
|
||||||
|
|
||||||
|
#define ERR_PUNCH2_NOT_ZERO 0x0083 // 冲孔2主轴不在零位
|
||||||
|
#define ERR_CUTTER_NOT_ZERO 0x0084 // 裁刀主轴不在零位
|
||||||
|
#define ERR_XY_NOT_WP 0x0085 // XY不在工作位置
|
||||||
|
#define ERR_HEAD_NOT_POS 0x0086 // 机头不到位
|
||||||
|
|
||||||
|
#define ERR_X2_LIT_POSI 0x0087 // X2正向限位
|
||||||
|
#define ERR_X2_LIT_NEGA 0x0088 // X2反向限位
|
||||||
|
#define ERR_Y2_LIT_POSI 0x0089 // Y2正向限位
|
||||||
|
#define ERR_Y2_LIT_NEGA 0x008A // Y2反向限位
|
||||||
|
#define ERR_PRESS_NOT_POS 0x008B // 压料龙门不到位
|
||||||
|
#define ERR_PRESS_LIFT_TIMOUT 0x008C // 压料升降超时
|
||||||
|
#define ERR_PRESS_LIFT_NOT_POS 0x008D // 压料升降不到位
|
||||||
|
#define ERR_TO_ZERO_TIMOUT 0x008E // 等待运动结束超时
|
||||||
|
#define ERR_MOVE_POS_ERR 0x008F // 移动位置错误
|
||||||
|
|
||||||
|
#define ERR_CLUTH_TIMOUT 0x0090 // 等待离合超时
|
||||||
|
#define ERR_CLUTH1_NOT_POS 0x0091 // 机头1离合不到位
|
||||||
|
#define ERR_CLUTH2_NOT_POS 0x0092 // 机头2离合不到位
|
||||||
|
|
||||||
|
#define ERR_FEED_ROLLER 0x0200 // 进料压辊 异常
|
||||||
|
#define ERR_DIS_ROLLER 0x0201 // 出料压辊 异常
|
||||||
|
#define ERR_DIS_MATERIAL 0x0202 // 出料压料 异常
|
||||||
|
#define ERR_TENS_DEVICE 0x0203 // 张紧装置 异常
|
||||||
|
#define ERR_CLOTH_DEVICE 0x0204 // 夹布装置 异常
|
||||||
|
#define ERR_EDGE_MOTOR 0x0205 // 边切电机 阻塞
|
||||||
|
#define ERR_CROSS_MOTOR 0x0206 // 横切电机 异常
|
||||||
|
#define ERR_FCLAMP_LIFT 0x0207 // 前夹升降气缸 异常
|
||||||
|
#define ERR_FCLAMP_OPCL 0x0208 // 前夹开合气缸 异常
|
||||||
|
#define ERR_PULL_CLAMP 0x0209 // 机械手上夹气缸 异常
|
||||||
|
#define ERR_PULL_CLIP 0x020A // 机械手下夹气缸 异常
|
||||||
|
#define ERR_YZR_NOT_SYNC 0x020B // 右框电机不同步
|
||||||
|
#define ERR_CHIP_ERROR 0x020C // 夹线装置位置 异常
|
||||||
|
#define ERR_FIXTURE1_ERROR 0x020D // 工装1传感器错误
|
||||||
|
#define ERR_FIXTURE2_ERROR 0x020E // 工装2传感器错误
|
||||||
|
#define ERR_CLASH_ERROR 0x020F // 工装防撞未就绪
|
||||||
|
|
||||||
|
|
||||||
|
#define ERR_NW_NOT_POS 0x0210 // 近端压轮升降不到位
|
||||||
|
#define ERR_FW_NOT_POS 0x0211 // 远端压轮升降不到位
|
||||||
|
#define ERR_SENDGIVE_NOT_POS 0x0212 // 送边条气缸不到位
|
||||||
|
#define ERR_FPHD_NOT_POS 0x0213 // 机头伸缩不到位
|
||||||
|
#define ERR_INPRESS_ERR 0x0214 // 里压料气缸 异常
|
||||||
|
#define ERR_OUTPRESS_ERR 0x0215 // 外压料气缸 异常
|
||||||
|
|
||||||
|
|
||||||
|
#define ERR_TENS_AND_CLOTH 0x0216 // 当前夹布和张紧位置不允许移动机头
|
||||||
|
#define ERR_RETURN_LIFT 0x0217 // 退料升降装置 异常
|
||||||
|
#define ERR_CLOTH_EMPTY 0x0218 // 送边条装置缺料
|
||||||
|
#define ERR_CHB_SWAY 0x0219 // 换梭摆动装置 异常
|
||||||
|
#define ERR_CHB_PUSH 0x021A // 换梭推动装置 异常
|
||||||
|
#define ERR_CHB_ROTATE 0x021B // 换梭旋转装置 异常
|
||||||
|
#define ERR_CHB_SHUT 0x021C // 梭壳检测 异常
|
||||||
|
#define ERR_XP_LIT_POSI 0x021D // XP正向限位
|
||||||
|
#define ERR_XP_LIT_NEGA 0x021E // XP反向限位
|
||||||
|
#define ERR_YP_LIT_POSI 0x021F // YP正向限位
|
||||||
|
#define ERR_YP_LIT_NEGA 0x0220 // YP反向限位
|
||||||
|
#define ERR_1UP_SEND_C 0x0221 // 送压布条1上气缸 异常
|
||||||
|
#define ERR_1UP_PUSH_S 0x0222 // 压布条1上气缸 异常
|
||||||
|
#define ERR_1UP_SEND_P 0x0223 // 送内压布1上气缸 异常
|
||||||
|
#define ERR_1UP_PUSH_C 0x0224 // 压布1上气缸 异常
|
||||||
|
#define ERR_1UP_IN_PUSH_C 0x0225 // 内压布1上气缸 异常
|
||||||
|
#define ERR_1DW_SEND_C 0x0226 // 送压布条1下气缸 异常
|
||||||
|
#define ERR_1DW_PUSH_S 0x0227 // 压布条1下气缸 异常
|
||||||
|
#define ERR_1DW_SEND_P 0x0228 // 送内压布1下气缸 异常
|
||||||
|
#define ERR_1DW_PUSH_C 0x0229 // 压布1下气缸 异常
|
||||||
|
#define ERR_1DW_IN_PUSH_C 0x022A // 内压布1下气缸 异常
|
||||||
|
#define ERR_TENS1_ERR 0x022B // 张力传感器1通讯 异常
|
||||||
|
#define ERR_TENS2_ERR 0x022C // 张力传感器2通讯 异常
|
||||||
|
#define ERR_FEED_LIMT 0x022D // 上料架对边限位
|
||||||
|
#define ERR_IN_WAIT_AREA 0x022E // 进入等待区域
|
||||||
|
#define ERR_HOT_LINE 0x022F // 烫线气缸未到位
|
||||||
|
|
||||||
|
#define ERR_CHB_SPIN 0x0230 // 换梭旋转装置 异常
|
||||||
|
#define ERR_CHB_DPUSH 0x0231 // 换梭扣线伸缩装置 异常
|
||||||
|
|
||||||
|
#define ERR_PUNCH3_NOT_ZERO 0x0232 // 冲孔3主轴不在零位
|
||||||
|
#define ERR_PUNCH4_NOT_ZERO 0x0233 // 冲孔4主轴不在零位
|
||||||
|
|
||||||
|
#define ERR_CUT_PRESS 0x0250 // 覆膜切料压杠装置 异常
|
||||||
|
#define ERR_LAMIN_FILM1 0x0251 // 覆膜夹膜装置1 异常
|
||||||
|
#define ERR_LAMIN_FILM2 0x0252 // 覆膜夹膜装置2 异常
|
||||||
|
#define ERR_FEED_EMP 0x0253 // 覆膜送料空位 异常
|
||||||
|
|
||||||
|
|
||||||
|
QString getErrStr(u32 code)
|
||||||
|
{
|
||||||
|
QString errinfo;
|
||||||
|
errinfo.clear();
|
||||||
|
QString errorCode;
|
||||||
|
errorCode.clear();
|
||||||
|
|
||||||
|
switch (code)
|
||||||
|
{
|
||||||
|
//通用的错误代码
|
||||||
|
CASE_OP(ERR_NONE, QObject::tr("no error")); // 没有错误
|
||||||
|
CASE_OP(ERR_NO_POWER, QObject::tr("no power")); // 没有上电
|
||||||
|
CASE_OP(ERR_NO_AIR, QObject::tr("insufficient air pressure"));// 气压不足
|
||||||
|
CASE_OP(ERR_NOT_SAFE, QObject::tr("safe area error")); // 安全区域介入
|
||||||
|
CASE_OP(ERR_EXPIRATION, QObject::tr("Expiration of use")); // 使用时限已到
|
||||||
|
CASE_OP(ERR_DRIVER, QObject::tr("Driver alarm")); // 驱动器报警
|
||||||
|
CASE_OP(ERR_FILL_DATA, QObject::tr("Fill data error")); // 填充数据错误
|
||||||
|
CASE_OP(ERR_NOT_ALLOWED, QObject::tr("Not allowed to work")); // 不允许工作状态
|
||||||
|
CASE_OP(ERR_CTRL_ERR, QObject::tr("Control error")); // 控制错误
|
||||||
|
CASE_OP(ERR_FPGA_ERR, QObject::tr("FPGA software version error"));// FPGA软件版本错误
|
||||||
|
CASE_OP(ERR_BUTTON_NOUP, QObject::tr("Button release timeout")); // 等待按钮抬起超时
|
||||||
|
CASE_OP(ERR_FPGA_RESET, QObject::tr("FPGA reset error")); // FPGA复位错误
|
||||||
|
CASE_OP(ERR_NO_READY, QObject::tr("Peripheral not ready")); // 外设未就绪
|
||||||
|
CASE_OP(ERR_NO_SEND_ERR, QObject::tr("Data transmission error")); // 传输数据错误
|
||||||
|
CASE_OP(ERR_EDTION_ERR, QObject::tr("Program version error")); // 程序版本错误
|
||||||
|
CASE_OP(ERR_WORK_DONE, QObject::tr("Work completed")); // 完成产量
|
||||||
|
|
||||||
|
CASE_OP(ERR_LMT_POSITIVE, QObject::tr("positive limit")); // 正向限位
|
||||||
|
CASE_OP(ERR_LMT_NEGATIVE, QObject::tr("negative limit")); // 反向限位
|
||||||
|
CASE_OP(ERR_RUN_ALM, QObject::tr("motion alarm")); // 运动报警
|
||||||
|
CASE_OP(ERR_RUN_LIMIT, QObject::tr("motion limit")); // 运动限位
|
||||||
|
CASE_OP(ERR_RUN_EMS, QObject::tr("motion emergency stop")); // 运动急停
|
||||||
|
CASE_OP(ERR_MV_PARA, QObject::tr("motion parameter error")); // 运动参数错误
|
||||||
|
CASE_OP(ERR_MC_PARA, QObject::tr("machine parameter error")); // 机器参数错误
|
||||||
|
CASE_OP(ERR_IN_PARA, QObject::tr("input parameter error")); // 输入参数错误
|
||||||
|
CASE_OP(ERR_FPGA_HARD_ERR, QObject::tr("FPGA hardware version error"));// FPGA硬件版本错误
|
||||||
|
|
||||||
|
CASE_OP(ERR_NOT_WORKSTA, QObject::tr("not allowed to work")); // 不能工作状态
|
||||||
|
CASE_OP(ERR_NOT_MOVESTA, QObject::tr("move frame prohibited")); // 禁止移框状态
|
||||||
|
CASE_OP(ERR_NOFAM_ZERO, QObject::tr("need to remove template before zeroing")); // 归零前需要卸下模板
|
||||||
|
CASE_OP(ERR_NO_ADDAIR, QObject::tr("No gas added")); // 没有加气
|
||||||
|
|
||||||
|
CASE_OP(ERR_MTZ_RIGHT, QObject::tr("zeroing successful")); // 归零成功
|
||||||
|
CASE_OP(ERR_MTZ_ERROR, QObject::tr("zeroing error")); // 归零错误
|
||||||
|
CASE_OP(ERR_COOR_SYSTM, QObject::tr("coordinate system error")); // 坐标系统错误
|
||||||
|
CASE_OP(ERR_OUT_RANGE, QObject::tr("target position out of range")); // 目标位置越界
|
||||||
|
CASE_OP(ERR_X_LIT_POSI, QObject::tr("X positive limit")); // X正向限位
|
||||||
|
CASE_OP(ERR_X_LIT_NEGA, QObject::tr("X negative limit")); // X反向限位
|
||||||
|
CASE_OP(ERR_Y_LIT_POSI, QObject::tr("Y positive limit")); // Y正向限位
|
||||||
|
CASE_OP(ERR_Y_LIT_NEGA, QObject::tr("Y negative limit")); // Y反向限位
|
||||||
|
|
||||||
|
CASE_OP(ERR_FEED_MANUAL, QObject::tr("feed in manual mode")); // 进料处于手动状态
|
||||||
|
CASE_OP(ERR_MC_MANUAL, QObject::tr("machine in manual mode")); // 机器处于手动状态
|
||||||
|
CASE_OP(ERR_KEY_SW_OFF, QObject::tr("key switch off")); // 机器钥匙开关关闭
|
||||||
|
CASE_OP(ERR_ALM_WATERTANK, QObject::tr("water tank alarm")); // 水箱报警
|
||||||
|
CASE_OP(ERR_ALM_COVEROPEN, QObject::tr("cover open alarm")); // 开盖报警
|
||||||
|
CASE_OP(ERR_LIGHTCURTAINS1, QObject::tr("light curtain 1 triggered")); // 光幕1介入
|
||||||
|
CASE_OP(ERR_LIGHTCURTAINS2, QObject::tr("light curtain 2 triggered")); // 光幕2介入
|
||||||
|
CASE_OP(ERR_AIR_POWER, QObject::tr("air pressure insufficient")); // 气压不足
|
||||||
|
CASE_OP(ERR_PRESS_SENSOR, QObject::tr("pressure sensor error")); // 压料传感器错误
|
||||||
|
CASE_OP(ERR_CLIP_SENSOR, QObject::tr("clip sensor error")); // 夹布传感器错误
|
||||||
|
CASE_OP(ERR_NO_MATERIEL, QObject::tr("material shortage alarm")); // 缺料报警
|
||||||
|
CASE_OP(ERR_CUTFRAME, QObject::tr("cut frame error")); // 边框切割错误
|
||||||
|
CASE_OP(ERR_MC_AUTO, QObject::tr("machine in auto mode")); // 机器处于自动状态
|
||||||
|
CASE_OP(ERR_DOOR_TIMEOUT, QObject::tr("door timeout")); // 开关门超时
|
||||||
|
CASE_OP(ERR_NOT_AT_OFFSET, QObject::tr("not at offset point")); // 不在偏移点
|
||||||
|
CASE_OP(ERR_NO_PHOTO_FILE, QObject::tr("no photo file")); // 没有拍照文件
|
||||||
|
CASE_OP(ERR_FEED_AUTO, QObject::tr("feed in auto mode")); // 进料处于自动状态
|
||||||
|
CASE_OP(ERR_GANTRY_NOT_POS, QObject::tr("gantry not in position")); // 龙门不到位
|
||||||
|
CASE_OP(ERR_GUARDRAIL_OPEN, QObject::tr("safety door not closed")); // 安全门未关闭
|
||||||
|
|
||||||
|
CASE_OP(ERR_LIGHTCURTAINS3, QObject::tr("light curtain 3 triggered")); // 光幕3介入
|
||||||
|
CASE_OP(ERR_LIGHTCURTAINS4, QObject::tr("light curtain 4 triggered")); // 光幕4介入
|
||||||
|
CASE_OP(ERR_PRINT_ERROR, QObject::tr("inkjet error")); // 喷墨异常
|
||||||
|
CASE_OP(ERR_PRINT_NOT_AT_BAK, QObject::tr("inkjet not at stop position")); // 喷墨不在停止位置
|
||||||
|
CASE_OP(ERR_LOAD_EMPTY, QObject::tr("loading storage empty")); // 上料储料空料
|
||||||
|
CASE_OP(ERR_RECV_FULL, QObject::tr("receiving storage full")); // 收料储料满料
|
||||||
|
|
||||||
|
CASE_OP(ERR_NO_DATA, QObject::tr("no data")); // 无数据
|
||||||
|
CASE_OP(ERR_DATA_ERROR, QObject::tr("data error")); // 数据错误
|
||||||
|
|
||||||
|
CASE_OP(ERR_PEN_TIMEOUT, QObject::tr("Brush lifting timeout")); // 画笔升降超时
|
||||||
|
CASE_OP(ERR_PENHAT_TIMEOUT, QObject::tr("Pen cap timeout")); // 画笔笔帽超时
|
||||||
|
|
||||||
|
CASE_OP(ERR_GRAPH_OUT_RANGE, QObject::tr("graphic out of range")); // 图形超出范围
|
||||||
|
CASE_OP(ERR_CUTTER2_ERROR, QObject::tr("cutter 2 error")); // 切割机2故障
|
||||||
|
CASE_OP(ERR_PHOTO_ERROR, QObject::tr("photo recognition error")); // 拍照识别错误
|
||||||
|
CASE_OP(ERR_CUT_RANGE_OVERFLOW, QObject::tr("cut range overlap")); // 切割范围重叠
|
||||||
|
CASE_OP(ERR_CUTTER1_ERROR, QObject::tr("cutter 1 error")); // 切割机1故障
|
||||||
|
CASE_OP(ERR_CUTTER1_CLEERR, QObject::tr("cutter 1 error invalid")); // 切割机1故障 失效
|
||||||
|
CASE_OP(ERR_CUTTER2_CLEERR, QObject::tr("cutter 2 error invalid")); // 切割机2故障 失效
|
||||||
|
CASE_OP(ERR_CUTTER_WASTE, QObject::tr("cutter waste")); // 切割机废料
|
||||||
|
CASE_OP(ERR_INPUT_EDGE, QObject::tr("feeding offset")); // 进料偏移
|
||||||
|
CASE_OP(ERR_INPUT_TIMEOUT, QObject::tr("feeding timeout")); // 进料超时
|
||||||
|
CASE_OP(ERR_EDGE_TBREAK, QObject::tr("edge machine head wire break")); // 边缝机头断线
|
||||||
|
CASE_OP(ERR_CHANGE_MAR, QObject::tr("material tray change")); // 更换料盘
|
||||||
|
|
||||||
|
CASE_OP(ERR_MS_NOT_ZERO, QObject::tr("spindle not at zero")); // 主轴不在零位
|
||||||
|
CASE_OP(ERR_HK_NOT_ZERO, QObject::tr("shuttle not at zero")); // 旋梭不在零位
|
||||||
|
CASE_OP(ERR_MS_NOT_SYNC, QObject::tr("needle and shuttle not synced")); // 针梭不同步
|
||||||
|
CASE_OP(ERR_RO_NOT_SYNC, QObject::tr("rotation not synced")); // 旋转不同步
|
||||||
|
CASE_OP(ERR_CUTTER_NOT_POS, QObject::tr("scissor not in position")); // 剪刀不在回位(缝纫剪刀)
|
||||||
|
CASE_OP(ERR_HEAD_NOT_HIGH, QObject::tr("head not at high position")); // 机头不在高位
|
||||||
|
CASE_OP(ERR_HEAD_NOT_LOW, QObject::tr("head not at low position")); // 机头不在低位
|
||||||
|
CASE_OP(ERR_LIGHTCURTAINS, QObject::tr("light curtain triggered")); // 光幕介入
|
||||||
|
CASE_OP(ERR_UPER_TBREAK, QObject::tr("upper thread break")); // 面线断线
|
||||||
|
CASE_OP(ERR_BOBBIN_TBREAK, QObject::tr("bobbin thread break")); // 底线断线
|
||||||
|
CASE_OP(ERR_NEEDLE_NOT_HIGH, QObject::tr("needle not at high position")); // 机针不在高位
|
||||||
|
CASE_OP(ERR_SEND_N1CMD_TIMOUT, QObject::tr("send spindle command timeout")); // 发送主轴命令超时
|
||||||
|
CASE_OP(ERR_SEND_N1CMD_FAIL, QObject::tr("send spindle command failed")); // 发送主轴命令失败
|
||||||
|
CASE_OP(ERR_TRANS_TIMEOUT, QObject::tr("execute command timeout")); // 执行命令超时
|
||||||
|
CASE_OP(ERR_NOT_AT_POS, QObject::tr("template not in position")); // 模版不到位
|
||||||
|
CASE_OP(ERR_LIFT_TIMEOUT, QObject::tr("head lift timeout")); // 机头升降超时
|
||||||
|
|
||||||
|
CASE_OP(ERR_PUNCH_NOT_ZERO, QObject::tr("punch spindle not at zero")); // 冲孔主轴不在零位
|
||||||
|
CASE_OP(ERR_R_LIT_POSI, QObject::tr("rotation positive limit")); // 旋转正向限位
|
||||||
|
CASE_OP(ERR_R_LIT_NEGA, QObject::tr("rotation negative limit")); // 旋转反向限位
|
||||||
|
CASE_OP(ERR_PUNCH2_NOT_ZERO, QObject::tr("punch 2 spindle not at zero")); // 冲孔2主轴不在零位
|
||||||
|
CASE_OP(ERR_CUTTER_NOT_ZERO, QObject::tr("cutter spindle not at zero")); // 裁刀主轴不在零位
|
||||||
|
CASE_OP(ERR_XY_NOT_WP, QObject::tr("XY not at work position")); // XY不在工作位置
|
||||||
|
CASE_OP(ERR_HEAD_NOT_POS, QObject::tr("head not in position")); // 机头不到位
|
||||||
|
CASE_OP(ERR_X2_LIT_POSI, QObject::tr("X2 positive limit")); // X2正向限位
|
||||||
|
CASE_OP(ERR_X2_LIT_NEGA, QObject::tr("X2 negative limit")); // X2反向限位
|
||||||
|
CASE_OP(ERR_Y2_LIT_POSI, QObject::tr("Y2 positive limit")); // Y2正向限位
|
||||||
|
CASE_OP(ERR_Y2_LIT_NEGA, QObject::tr("Y2 negative limit")); // Y2反向限位
|
||||||
|
CASE_OP(ERR_PRESS_NOT_POS, QObject::tr("press gantry not in position")); // 压料龙门不到位
|
||||||
|
CASE_OP(ERR_PRESS_LIFT_TIMOUT, QObject::tr("press lift timeout")); // 压料升降超时
|
||||||
|
CASE_OP(ERR_PRESS_LIFT_NOT_POS, QObject::tr("press lift not in position")); // 压料升降不到位
|
||||||
|
CASE_OP(ERR_TO_ZERO_TIMOUT, QObject::tr("wait motion end timeout")); // 等待运动结束超时
|
||||||
|
CASE_OP(ERR_MOVE_POS_ERR, QObject::tr("move position error")); // 移动位置错误
|
||||||
|
|
||||||
|
CASE_OP(ERR_CLUTH_TIMOUT, QObject::tr("clutch wait timeout")); // 等待离合超时
|
||||||
|
CASE_OP(ERR_CLUTH1_NOT_POS, QObject::tr("head 1 clutch not in position")); // 机头1离合不到位
|
||||||
|
CASE_OP(ERR_CLUTH2_NOT_POS, QObject::tr("head 2 clutch not in position")); // 机头2离合不到位
|
||||||
|
|
||||||
|
CASE_OP(ERR_FOOT_POS, QObject::tr("presser foot position error")); // 压脚位置错误
|
||||||
|
CASE_OP(ERR_FOOT_OUT_RANGE, QObject::tr("presser motor position out of range"));// 压脚电机位置越界
|
||||||
|
CASE_OP(ERR_LIFT_OUT_RANGE, QObject::tr("head lift position out of range")); // 机头升降位置越界
|
||||||
|
CASE_OP(ERR_ROT_OUT_RANGE, QObject::tr("rotation position out of range")); // 旋转位置越界
|
||||||
|
CASE_OP(ERR_ROT_ECD_ERROR, QObject::tr("rotation encoder error")); // 旋转编码器错误
|
||||||
|
CASE_OP(ERR_LIFT_ULIMIT, QObject::tr("head lift upper limit")); // 机头升降上限位
|
||||||
|
CASE_OP(ERR_LIFT_DLIMIT, QObject::tr("head lift lower limit")); // 机头升降下限位
|
||||||
|
CASE_OP(ERR_LIFT_SYNC_ERR, QObject::tr("head lift sync error")); // 机头升降同步错误
|
||||||
|
CASE_OP(ERR_NOTIN_SAFE_AREA, QObject::tr("head not in safe area")); // 机头不在安全区域
|
||||||
|
|
||||||
|
CASE_OP(ERR_BUS_ERR, QObject::tr("bus error")); // 总线错误
|
||||||
|
CASE_OP(ERR_WIRE_ALARM, QObject::tr("wire tying alarm")); // 扎线报警
|
||||||
|
|
||||||
|
CASE_OP(ERR_ROT_COOR_SYSTM, QObject::tr("rotation motor coordinate system error")); // 旋转电机坐标系统错误
|
||||||
|
CASE_OP(ERR_LIFT_COOR_SYSTM, QObject::tr("lift motor coordinate system error")); // 升降电机坐标系统错误
|
||||||
|
CASE_OP(ERR_MS_COOR_SYSTM, QObject::tr("spindle coordinate system error")); // 主轴坐标系统错误
|
||||||
|
CASE_OP(ERR_WORK_HEAD, QObject::tr("working head error")); // 工作机头错误
|
||||||
|
CASE_OP(ERR_CHANGE_SHUT, QObject::tr("shuttle change error")); // 换梭异常
|
||||||
|
|
||||||
|
CASE_OP(ERR_CHANGE_BOBBIN, QObject::tr("change bobbin")); // 更换梭芯
|
||||||
|
CASE_OP(ERR_CHANGE_BOBBIN_A, QObject::tr("change bobbin A")); // 更换梭芯A
|
||||||
|
CASE_OP(ERR_CHANGE_BOBBIN_B, QObject::tr("change bobbin B")); // 更换梭芯B
|
||||||
|
CASE_OP(ERR_CHANGE_BOBBIN_STA, QObject::tr("machine in bobbin change state")); // 机器处于更换梭芯状态
|
||||||
|
|
||||||
|
CASE_OP(ERR_FEED_ROLLER, QObject::tr("feed roller error")); // 进料压辊 异常
|
||||||
|
CASE_OP(ERR_DIS_ROLLER, QObject::tr("discharge roller error")); // 出料压辊 异常
|
||||||
|
CASE_OP(ERR_DIS_MATERIAL, QObject::tr("discharge material error")); // 出料压料 异常
|
||||||
|
CASE_OP(ERR_TENS_DEVICE, QObject::tr("tension device error")); // 张紧装置 异常
|
||||||
|
CASE_OP(ERR_CLOTH_DEVICE, QObject::tr("cloth clamping device error")); // 夹布装置 异常
|
||||||
|
CASE_OP(ERR_EDGE_MOTOR, QObject::tr("edge motor blockage")); // 边切电机 阻塞
|
||||||
|
CASE_OP(ERR_CROSS_MOTOR, QObject::tr("cross cut motor error")); // 横切电机 异常
|
||||||
|
CASE_OP(ERR_FCLAMP_LIFT, QObject::tr("front clamp lift cylinder error")); // 前夹升降气缸 异常
|
||||||
|
CASE_OP(ERR_FCLAMP_OPCL, QObject::tr("front clamp open/close cylinder error")); // 前夹开合气缸 异常
|
||||||
|
CASE_OP(ERR_PULL_CLAMP, QObject::tr("robot arm upper clamp cylinder error"));// 机械手上夹气缸 异常
|
||||||
|
CASE_OP(ERR_PULL_CLIP, QObject::tr("robot arm lower clamp cylinder error")); // 机械手下夹气缸 异常
|
||||||
|
CASE_OP(ERR_YZR_NOT_SYNC, QObject::tr("right frame motor out of sync")); // 右框电机不同步
|
||||||
|
CASE_OP(ERR_CHIP_ERROR, QObject::tr("wire clamping device position error")); // 夹线装置位置 异常
|
||||||
|
CASE_OP(ERR_FIXTURE1_ERROR, QObject::tr("fixture 1 sensor error")); // 工装1传感器错误
|
||||||
|
CASE_OP(ERR_FIXTURE2_ERROR, QObject::tr("fixture 2 sensor error")); // 工装2传感器错误
|
||||||
|
CASE_OP(ERR_CLASH_ERROR, QObject::tr("fixture anti-collision not ready")); // 工装防撞未就绪
|
||||||
|
|
||||||
|
|
||||||
|
CASE_OP(ERR_NW_NOT_POS, QObject::tr("near-end pressure roller lift not in position")); // 近端压轮升降不到位
|
||||||
|
CASE_OP(ERR_FW_NOT_POS, QObject::tr("far-end pressure roller lift not in position")); // 远端压轮升降不到位
|
||||||
|
CASE_OP(ERR_SENDGIVE_NOT_POS, QObject::tr("edge feeding cylinder not in position")); // 送边条气缸不到位
|
||||||
|
CASE_OP(ERR_FPHD_NOT_POS, QObject::tr("head telescoping not in position")); // 机头伸缩不到位
|
||||||
|
CASE_OP(ERR_INPRESS_ERR, QObject::tr("inner pressure cylinder error")); // 里压料气缸 异常
|
||||||
|
CASE_OP(ERR_OUTPRESS_ERR, QObject::tr("outer pressure cylinder error")); // 外压料气缸 异常
|
||||||
|
|
||||||
|
CASE_OP(ERR_TENS_AND_CLOTH, QObject::tr("current cloth clamp and tension position disallow head movement")); // 当前夹布和张紧位置不允许移动机头
|
||||||
|
CASE_OP(ERR_RETURN_LIFT, QObject::tr("return lift device error")); // 退料升降装置 异常
|
||||||
|
CASE_OP(ERR_CLOTH_EMPTY, QObject::tr("edge feeding device out of material")); // 送边条装置缺料
|
||||||
|
CASE_OP(ERR_CHB_SWAY, QObject::tr("shuttle change swinging device error")); // 换梭摆动装置 异常
|
||||||
|
CASE_OP(ERR_CHB_PUSH, QObject::tr("shuttle change pushing device error")); // 换梭推动装置 异常
|
||||||
|
CASE_OP(ERR_CHB_ROTATE, QObject::tr("shuttle change rotating device error")); // 换梭旋转装置 异常
|
||||||
|
CASE_OP(ERR_CHB_SHUT, QObject::tr("shuttle shell detection error")); // 梭壳检测 异常
|
||||||
|
CASE_OP(ERR_XP_LIT_POSI, QObject::tr("XP positive limit")); // XP正向限位
|
||||||
|
CASE_OP(ERR_XP_LIT_NEGA, QObject::tr("XP negative limit")); // XP反向限位
|
||||||
|
CASE_OP(ERR_YP_LIT_POSI, QObject::tr("YP positive limit")); // YP正向限位
|
||||||
|
CASE_OP(ERR_YP_LIT_NEGA, QObject::tr("YP negative limit")); // YP反向限位
|
||||||
|
CASE_OP(ERR_1UP_SEND_C, QObject::tr("upper 1 cloth feeding cylinder error")); // 送压布条1上气缸 异常
|
||||||
|
CASE_OP(ERR_1UP_PUSH_S, QObject::tr("upper 1 cloth pressing cylinder error")); // 压布条1上气缸 异常
|
||||||
|
CASE_OP(ERR_1UP_SEND_P, QObject::tr("upper 1 inner cloth feeding cylinder error")); // 送内压布1上气缸 异常
|
||||||
|
CASE_OP(ERR_1UP_PUSH_C, QObject::tr("upper 1 cloth pressing cylinder error")); // 压布1上气缸 异常
|
||||||
|
CASE_OP(ERR_1UP_IN_PUSH_C, QObject::tr("upper 1 inner cloth pressing cylinder error")); // 内压布1上气缸 异常
|
||||||
|
CASE_OP(ERR_1DW_SEND_C, QObject::tr("lower 1 cloth feeding cylinder error")); // 送压布条1下气缸 异常
|
||||||
|
CASE_OP(ERR_1DW_PUSH_S, QObject::tr("lower 1 cloth pressing cylinder error")); // 压布条1下气缸 异常
|
||||||
|
CASE_OP(ERR_1DW_SEND_P, QObject::tr("lower 1 inner cloth feeding cylinder error")); // 送内压布1下气缸 异常
|
||||||
|
CASE_OP(ERR_1DW_PUSH_C, QObject::tr("lower 1 cloth pressing cylinder error")); // 压布1下气缸 异常
|
||||||
|
CASE_OP(ERR_1DW_IN_PUSH_C, QObject::tr("lower 1 inner cloth pressing cylinder error")); // 内压布1下气缸 异常
|
||||||
|
CASE_OP(ERR_TENS1_ERR, QObject::tr("tension sensor 1 communication error")); // 张力传感器1通讯 异常
|
||||||
|
CASE_OP(ERR_TENS2_ERR, QObject::tr("tension sensor 2 communication error")); // 张力传感器2通讯 异常
|
||||||
|
CASE_OP(ERR_FEED_LIMT, QObject::tr("feeding rack edge limit")); // 上料架对边限位
|
||||||
|
CASE_OP(ERR_IN_WAIT_AREA, QObject::tr("entered waiting area")); // 进入等待区域
|
||||||
|
CASE_OP(ERR_HOT_LINE, QObject::tr("hot line cylinder not in position")); // 烫线气缸未到位
|
||||||
|
|
||||||
|
CASE_OP(ERR_CHB_SPIN, QObject::tr("shuttle change rotating device error")); // 换梭旋转装置 异常
|
||||||
|
CASE_OP(ERR_CHB_DPUSH, QObject::tr("shuttle change thread pushing telescopic device error")); // 换梭扣线伸缩装置 异常
|
||||||
|
|
||||||
|
CASE_OP(ERR_PUNCH3_NOT_ZERO, QObject::tr("punch 3 spindle not at zero position")); // 冲孔3主轴不在零位
|
||||||
|
CASE_OP(ERR_PUNCH4_NOT_ZERO, QObject::tr("punch 4 spindle not at zero position")); // 冲孔4主轴不在零位
|
||||||
|
|
||||||
|
CASE_OP(ERR_CUT_PRESS, QObject::tr("lamination cutting press bar device error")); // 覆膜切料压杠装置 异常
|
||||||
|
CASE_OP(ERR_LAMIN_FILM1, QObject::tr("lamination clamping device 1 error")); // 覆膜夹膜装置1 异常
|
||||||
|
CASE_OP(ERR_LAMIN_FILM2, QObject::tr("lamination clamping device 2 error")); // 覆膜夹膜装置2 异常
|
||||||
|
CASE_OP(ERR_FEED_EMP, QObject::tr("lamination feeding empty slot error")); // 覆膜送料空位 异常
|
||||||
|
|
||||||
|
CASE_OP(ERRQUI_UPER_TBREAK1, QObject::tr("Head 1 has a broken surface wire")); // 机头1面线断线
|
||||||
|
CASE_OP(ERRQUI_UPER_TBREAK2, QObject::tr("Head 2 has a broken surface wire")); // 机头2面线断线
|
||||||
|
CASE_OP(ERRQUI_LIFT_TIMEOUT, QObject::tr("Head lifting timeout")); // 机头升降超时
|
||||||
|
CASE_OP(ERRQUI_CHANGE_BOBBIN, QObject::tr("Replacing the shuttle core")); // 更换梭芯
|
||||||
|
CASE_OP(ERRQUI_CHANGE_ERR, QObject::tr("Shuttle Change Device Alarm")); // 换梭装置报警
|
||||||
|
CASE_OP(ERRQUI_CHANGE_SHUTDISK, QObject::tr("Replace Shuttle Disk")); // 更换梭盘
|
||||||
|
CASE_OP(ERR_UPER_TBREAK_UP, QObject::tr("The upper cable is broken")); // 上排线断线
|
||||||
|
CASE_OP(ERR_UPER_TBREAK_DW, QObject::tr("Offline broken wire")); // 下排线断线
|
||||||
|
CASE_OP(ERR_PRODUCTION_LINE, QObject::tr("Production line alarm")); // 产线报警
|
||||||
|
|
||||||
|
CASE_OP(ERRQUI_FEED_ROLLER, QObject::tr("Feed pressure roller error")); // 进料压辊异常
|
||||||
|
CASE_OP(ERRQUI_DIS_ROLLER, QObject::tr("Discharge pressure roller error")); // 出料压辊异常
|
||||||
|
CASE_OP(ERRQUI_DIS_MATERIAL, QObject::tr("Discharging and pressing materials error")); // 出料压料异常
|
||||||
|
CASE_OP(ERRQUI_TENS_DEVICE, QObject::tr("Tensioning device error")); // 张紧装置异常
|
||||||
|
CASE_OP(ERRQUI_CLOTH_DEVICE, QObject::tr("Cloth clamping device error")); // 夹布装置异常
|
||||||
|
CASE_OP(ERRQUI_EDGE_MOTOR, QObject::tr("Edge cutting motor blockage")); // 边切电机阻塞
|
||||||
|
CASE_OP(ERRQUI_CROSS_MOTOR, QObject::tr("Transverse motor error")); // 横切电机异常
|
||||||
|
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR1, QObject::tr("Abnormal cutting ultrasonic lifting cylinder")); // 裁切超声波升降气缸异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR2, QObject::tr("Abnormal lifting cylinder of cutting blade")); // 裁切切刀升降气缸异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR3, QObject::tr("Abnormal cutting and ejection cylinder")); // 裁切顶出气缸异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR4, QObject::tr("Abnormal clamping cylinder before cutting")); // 裁切前夹料气缸异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR5, QObject::tr("Abnormal feeding cylinder after cutting")); // 裁切后上夹料气缸异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR6, QObject::tr("Abnormal lower clamping cylinder after cutting")); // 裁切后下夹料气缸异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR7, QObject::tr("Abnormal cutting gripper")); // 裁切夹爪异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR8, QObject::tr("Abnormal position of the material pulling motor")); // 拉料电机位置异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR9, QObject::tr("Abnormal position of cross cutting motor")); // 横切电机位置异常
|
||||||
|
CASE_OP(ERR_BEDSEET_ERRA, QObject::tr("Stop material storage")); // 储料停止
|
||||||
|
CASE_OP(ERR_BEDSEET_ERRB, QObject::tr("Right seam broken line")); // 右边缝断线
|
||||||
|
CASE_OP(ERR_BEDSEET_ERRC, QObject::tr("Left seam broken line")); // 左边缝断线
|
||||||
|
CASE_OP(ERR_BEDSEET_ERRD, QObject::tr("Replace the shuttle core")); // 更换梭芯
|
||||||
|
CASE_OP(ERR_BEDSEET_ERRE, QObject::tr("Not meeting the material pulling conditions")); // 未满足拉料条件
|
||||||
|
CASE_OP(ERR_BEDSEET_ERRF, QObject::tr("Material delivery timeout")); // 物料输送超时
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR10, QObject::tr("Materials not taken away")); // 物料未取走
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR11, QObject::tr("Feeding limit")); // 送料限位
|
||||||
|
CASE_OP(ERR_BEDSEET_ERR12, QObject::tr("The machine head is short of material")); // 机头缺料
|
||||||
|
|
||||||
|
CASE_OP(ERRQUI_INSTALLMENT_OK, QObject::tr("Password set successfully")); // 密码设置成功
|
||||||
|
CASE_OP(ERRQUI_INSTALLMENT_FAIL, QObject::tr("Password setting failed")); // 密码设置失败
|
||||||
|
CASE_OP(ERRQUI_MOTO_N_ALM, QObject::tr("Needle motor alarm")); // 针电机报警
|
||||||
|
CASE_OP(ERRQUI_MOTO_H_ALM, QObject::tr("Shuttle motor alarm")); // 梭电机报警
|
||||||
|
CASE_OP(ERRQUI_MOTO_X_ALM, QObject::tr("X motor alarm")); // X电机报警
|
||||||
|
CASE_OP(ERRQUI_MOTO_Y_ALM, QObject::tr("Y motor alarm")); // Y电机报警
|
||||||
|
CASE_OP(ERRQUI_MOTO_U_ALM, QObject::tr("U motor alarm")); // U电机报警
|
||||||
|
CASE_OP(ERRQUI_MOTO_N_FZ, QObject::tr("Needle motor zeroing failure")); // 针电机归零失败
|
||||||
|
CASE_OP(ERRQUI_MOTO_H_FZ, QObject::tr("Shuttle motor zeroing failure")); // 梭电机归零失败
|
||||||
|
CASE_OP(ERRQUI_MOTO_X_FZ, QObject::tr("Zero reset failure of X motor")); // X电机归零失败
|
||||||
|
CASE_OP(ERRQUI_MOTO_Y_FZ, QObject::tr("Y motor zeroing failed")); // Y电机归零失败
|
||||||
|
CASE_OP(ERRQUI_CS_TIMEOUT, QObject::tr("Communication timeout from the board")); // 从板通讯超时
|
||||||
|
CASE_OP(ERRQUI_MOTO_X_ZERO, QObject::tr("X motor is not at zero position")); // X电机不在零位
|
||||||
|
|
||||||
|
//通用的状态信息
|
||||||
|
CASE_OP(STA_NORMAL_STOP, QObject::tr("Normal stop")); // 正常停止
|
||||||
|
CASE_OP(STA_MTZ_SUCCESS, QObject::tr("Find zero success")); // 归零成功
|
||||||
|
CASE_OP(STA_WORK_PAUSE, QObject::tr("work pause")); // 工作暂停
|
||||||
|
CASE_OP(STA_WORK_OVER, QObject::tr("End of work")); // 工作结束
|
||||||
|
CASE_OP(STA_WORK_FINISH, QObject::tr("Work done")); // 工作完成
|
||||||
|
CASE_OP(STA_WORK_DONE, QObject::tr("Complete production")); // 完成产量
|
||||||
|
CASE_OP(STA_EXEC_SUCCESS, QObject::tr("Execute success")); // 执行成功
|
||||||
|
CASE_OP(STA_EXEC_FAILED, QObject::tr("Execute false")); // 执行失败
|
||||||
|
CASE_OP(STA_WAIT_FILE, QObject::tr("wait file")); // 等待文件
|
||||||
|
CASE_OP(STA_CHANGE_BOBBIN, QObject::tr("change the bobbin")); // 更换梭芯
|
||||||
|
CASE_OP(STA_PROCESS_FINISH, QObject::tr("Execute finish")); // 执行完成
|
||||||
|
CASE_OP(STA_PROCESS_RUNNING, QObject::tr("Execute runnibng")); // 执行过程中
|
||||||
|
|
||||||
|
default:
|
||||||
|
//errorCode.sprintf("CODE 0x%x", code);
|
||||||
|
//errinfo.append(QObject::tr("Undefined error,") + errorCode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return errinfo;
|
||||||
|
}
|
||||||
11
machine/error.h
Normal file
11
machine/error.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef ERROR_H
|
||||||
|
#define ERROR_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include "comm/typedef.h"
|
||||||
|
|
||||||
|
|
||||||
|
QString getErrStr(u32 code);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ERROR_H
|
||||||
334
machine/gatewaytcpclient.cpp
Normal file
334
machine/gatewaytcpclient.cpp
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
#include "gatewaytcpclient.h"
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QAbstractSocket>
|
||||||
|
|
||||||
|
GatewayTcpClient::GatewayTcpClient(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_pClientSocket(NULL),
|
||||||
|
m_pConnectCheckTimer(NULL),
|
||||||
|
m_connected(0),
|
||||||
|
m_pConnectDetectThread(NULL),
|
||||||
|
m_pConnectDetect(NULL),
|
||||||
|
m_detect(0),
|
||||||
|
m_localip(DEF_LOCAL_IP),
|
||||||
|
m_localport(DEF_LOCAL_PORT),
|
||||||
|
m_serverip(DEF_SERVER_IP),
|
||||||
|
m_serverport(DEF_SERVER_PORT)
|
||||||
|
{
|
||||||
|
m_pClientSocket = new QBindTcpSocket(this);
|
||||||
|
m_pClientSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
|
||||||
|
connect(m_pClientSocket, SIGNAL(readyRead()), this, SLOT(receiveServerData()));
|
||||||
|
connect(m_pClientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||||
|
this, SLOT(displaySocketError(QAbstractSocket::SocketError)));
|
||||||
|
// connect(m_pClientSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(netStateChanged(QAbstractSocket::SocketState)));
|
||||||
|
|
||||||
|
m_pConnectCheckTimer = new QTimer(this);
|
||||||
|
connect(m_pConnectCheckTimer, SIGNAL(timeout()), this, SLOT(connectCheck()));
|
||||||
|
|
||||||
|
|
||||||
|
m_pConnectDetectThread = new QThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
GatewayTcpClient::~GatewayTcpClient()
|
||||||
|
{
|
||||||
|
m_pConnectCheckTimer->stop();
|
||||||
|
delete m_pConnectCheckTimer;
|
||||||
|
|
||||||
|
m_pClientSocket->disconnectFromHost();
|
||||||
|
m_pClientSocket->waitForDisconnected();
|
||||||
|
m_pClientSocket->close();
|
||||||
|
delete m_pClientSocket;
|
||||||
|
|
||||||
|
if (m_connected != 0)
|
||||||
|
{
|
||||||
|
m_pConnectDetectThread->quit();
|
||||||
|
m_pConnectDetectThread->wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete m_pConnectDetectThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::setConfigFileName(QString configfilename)
|
||||||
|
{
|
||||||
|
m_configFileName = configfilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::connectToServer()
|
||||||
|
{
|
||||||
|
if (m_pClientSocket == NULL)
|
||||||
|
{
|
||||||
|
qDebug() << "m_pClientSocket not alloc";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_connected == 0)
|
||||||
|
{
|
||||||
|
loadIpAndPort();
|
||||||
|
if (m_pConnectDetect == NULL)
|
||||||
|
{
|
||||||
|
m_pConnectDetect = new TcpConnectDetect;
|
||||||
|
}
|
||||||
|
qDebug() << "GatewayTcpClient::connectToServer()";
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
|
||||||
|
m_pConnectDetect->setIpAndPort(m_localip, m_localport, m_serverip, m_serverport);
|
||||||
|
|
||||||
|
m_pConnectDetect->moveToThread(m_pConnectDetectThread);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(siDetectHost()), m_pConnectDetect, SLOT(connectDetect()), Qt::QueuedConnection);
|
||||||
|
connect(m_pConnectDetect, SIGNAL(siConnectSta(int)), this, SLOT(detectStatus(int)), Qt::QueuedConnection);
|
||||||
|
|
||||||
|
// 20191226由于检测线程会造成网络重连,所以将检测线程注释 lft
|
||||||
|
/*
|
||||||
|
connect(m_pConnectDetectThread, SIGNAL(started()), m_pConnectDetect, SLOT(detectStart()) );
|
||||||
|
connect(m_pConnectDetectThread, SIGNAL(finished()), m_pConnectDetect, SLOT(deleteLater()) ); // 退出删除对象
|
||||||
|
|
||||||
|
m_pConnectDetectThread->start(); // 启动线程
|
||||||
|
*/
|
||||||
|
m_pConnectCheckTimer->start(1000);
|
||||||
|
m_connected = 1;
|
||||||
|
m_detect = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::disConnectFromServer()
|
||||||
|
{
|
||||||
|
if (m_connected != 0)
|
||||||
|
{
|
||||||
|
m_pConnectCheckTimer->stop();
|
||||||
|
|
||||||
|
if (m_pClientSocket != NULL)
|
||||||
|
{
|
||||||
|
m_pClientSocket->disconnectFromHost();
|
||||||
|
m_pClientSocket->waitForDisconnected();
|
||||||
|
m_pClientSocket->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pConnectDetectThread->quit();
|
||||||
|
m_pConnectDetectThread->wait();
|
||||||
|
|
||||||
|
m_connected = 0;
|
||||||
|
m_detect = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::loadIpAndPort()
|
||||||
|
{
|
||||||
|
if (!m_configFileName.isEmpty())
|
||||||
|
{
|
||||||
|
//物联网客户端与mqtt网关服务器建立连接
|
||||||
|
QSettings configIni(m_configFileName, QSettings::IniFormat);
|
||||||
|
QString serverip, localip;
|
||||||
|
quint16 serverport, localport;
|
||||||
|
|
||||||
|
serverip = configIni.value("server/ip", QVariant("192.168.1.128")).toString(); //coco 临时更改物联网服务器IP,之前IP和主板相同,导致界面重启后无法和主板联网
|
||||||
|
serverport = configIni.value("server/port", QVariant(8001)).toInt();
|
||||||
|
localip = configIni.value("local/ip", QVariant("192.168.16.41")).toString();
|
||||||
|
localport = configIni.value("local/port", 5001).toInt();
|
||||||
|
|
||||||
|
// 回写参数
|
||||||
|
configIni.setValue("server/ip", serverip);
|
||||||
|
configIni.setValue("server/port", serverport);
|
||||||
|
configIni.setValue("local/ip", localip);
|
||||||
|
configIni.setValue("local/port", localport);
|
||||||
|
|
||||||
|
m_localip = localip;
|
||||||
|
m_localport = localport;
|
||||||
|
m_serverip = serverip;
|
||||||
|
m_serverport = serverport;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送数据的槽
|
||||||
|
void GatewayTcpClient::slotSendData(QByteArray dat)
|
||||||
|
{
|
||||||
|
if (m_pClientSocket != NULL)
|
||||||
|
{
|
||||||
|
m_pClientSocket->write(dat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动检测连接
|
||||||
|
void GatewayTcpClient::connectCheck()
|
||||||
|
{
|
||||||
|
if (m_pClientSocket == NULL)
|
||||||
|
{
|
||||||
|
qDebug() << "Socket is not alloced";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// qDebug() << "check client connect";
|
||||||
|
if (m_connected == 1)
|
||||||
|
{
|
||||||
|
if (m_localip.isEmpty() == false)
|
||||||
|
{
|
||||||
|
m_pClientSocket->bindAddrAndPort(m_localip, m_localport);
|
||||||
|
}
|
||||||
|
m_pClientSocket->abort();
|
||||||
|
m_pClientSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
||||||
|
m_pClientSocket->connectToHost(m_serverip, m_serverport);
|
||||||
|
int rslt = m_pClientSocket->waitForConnected(2000);
|
||||||
|
if (rslt == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
qDebug("bind connect and waitForConnected 2000, rslt=%d", rslt);
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
*/
|
||||||
|
m_connected = 2;
|
||||||
|
}
|
||||||
|
else if (m_connected != 0)
|
||||||
|
{
|
||||||
|
switch(m_pClientSocket->state())
|
||||||
|
{
|
||||||
|
case QAbstractSocket::ConnectedState:
|
||||||
|
{
|
||||||
|
if (m_connected != 3)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
qDebug() << "net State is Connected";
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
*/
|
||||||
|
m_connected = 3; // 检测连接状态
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::ConnectingState:
|
||||||
|
{
|
||||||
|
if (m_connected != 2)
|
||||||
|
{
|
||||||
|
qDebug() << "net State is Connecting";
|
||||||
|
// qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
}
|
||||||
|
m_connected = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::UnconnectedState:
|
||||||
|
{
|
||||||
|
if (m_connected != 1)
|
||||||
|
{
|
||||||
|
// qDebug() << "net State is unconnected";
|
||||||
|
// qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
}
|
||||||
|
m_connected = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
QAbstractSocket::HostLookupState
|
||||||
|
QAbstractSocket::BoundState
|
||||||
|
QAbstractSocket::ListeningState
|
||||||
|
QAbstractSocket::ClosingState
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
qDebug("net State is %d\r\n", m_pClientSocket->state());
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
}
|
||||||
|
m_connected = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_connected == 3) // 已连接
|
||||||
|
{
|
||||||
|
if (m_detect == 1)
|
||||||
|
{
|
||||||
|
// qDebug() << "Machine " << QThread::currentThread();
|
||||||
|
m_detect = 0;
|
||||||
|
emit(siDetectHost());
|
||||||
|
// qDebug() << "after send SiDetectHost ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit (siConnectSta(m_connected)); // 网络连接信号
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::detectStatus(int sta)
|
||||||
|
{
|
||||||
|
// qDebug("host detect sta=%d", sta);
|
||||||
|
|
||||||
|
m_detect = 1;
|
||||||
|
if (sta == 1) // 网络已断开
|
||||||
|
{
|
||||||
|
qDebug("disconnect ClientSocket by detect");
|
||||||
|
m_pClientSocket->disconnectFromHost();
|
||||||
|
// m_pClientSocket->waitForDisconnected();
|
||||||
|
m_pClientSocket->close();
|
||||||
|
m_connected = 1;
|
||||||
|
}
|
||||||
|
else if (sta == 2) // 网络连接还在
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::receiveServerData()
|
||||||
|
{
|
||||||
|
if (m_pClientSocket != NULL)
|
||||||
|
{
|
||||||
|
QByteArray tmpDat;
|
||||||
|
tmpDat = m_pClientSocket->readAll(); // 读取
|
||||||
|
// qDebug("ReceiveServerData, size = %d", tmpDat.size());
|
||||||
|
// PrintAsHex(&tmpDat);
|
||||||
|
|
||||||
|
emit(siReceiveData(tmpDat)); // 发送收到数据信号
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::displaySocketError(QAbstractSocket::SocketError err)
|
||||||
|
{
|
||||||
|
QString errinfo;
|
||||||
|
|
||||||
|
errinfo.sprintf("Err: code=%d, errorString=", err);
|
||||||
|
errinfo += m_pClientSocket->errorString();
|
||||||
|
|
||||||
|
// qDebug() << errinfo;
|
||||||
|
|
||||||
|
emit(siConnectErr(errinfo)); // 网络错误信息
|
||||||
|
}
|
||||||
|
|
||||||
|
void GatewayTcpClient::netStateChanged(QAbstractSocket::SocketState sta)
|
||||||
|
{
|
||||||
|
switch (sta)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
case UnconnectedState:
|
||||||
|
case HostLookupState:
|
||||||
|
case ConnectingState:
|
||||||
|
case ConnectedState:
|
||||||
|
case BoundState:
|
||||||
|
case ListeningState:
|
||||||
|
case ClosingStat:
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void GatewayTcpClient::hostFound()
|
||||||
|
{
|
||||||
|
qDebug("found host");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
72
machine/gatewaytcpclient.h
Normal file
72
machine/gatewaytcpclient.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#ifndef GATEWAYTCPCLIENT_H
|
||||||
|
#define GATEWAYTCPCLIENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QHostAddress>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QUdpSocket>
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
#include "qbindtcpsocket.h"
|
||||||
|
|
||||||
|
class ConnectDetectThread;
|
||||||
|
|
||||||
|
|
||||||
|
class GatewayTcpClient : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit GatewayTcpClient(QObject *parent = NULL);
|
||||||
|
virtual ~GatewayTcpClient();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setConfigFileName(QString configfilename);
|
||||||
|
signals:
|
||||||
|
void siConnectSta(int sta); // 网络连接信号
|
||||||
|
void siConnectErr(QString errinfo); // 网络错误信息
|
||||||
|
void siReceiveData(QByteArray dat); // 收到数据包信号
|
||||||
|
signals:
|
||||||
|
void siDetectHost(void);
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void slotSendData(QByteArray dat); // 发送数据的槽
|
||||||
|
void connectToServer();//连接到服务器
|
||||||
|
void disConnectFromServer();
|
||||||
|
void detectStatus(int);
|
||||||
|
public:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void connectCheck();
|
||||||
|
void receiveServerData();
|
||||||
|
void displaySocketError(QAbstractSocket::SocketError err);
|
||||||
|
void netStateChanged(QAbstractSocket::SocketState sta);
|
||||||
|
void hostFound();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadIpAndPort();
|
||||||
|
private:
|
||||||
|
QBindTcpSocket * m_pClientSocket;
|
||||||
|
|
||||||
|
QTimer * m_pConnectCheckTimer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_connected; // 连接状态; 0, 初始化; 1, 未连接; 2, 连接中; 3, 已连接
|
||||||
|
|
||||||
|
private:
|
||||||
|
QThread * m_pConnectDetectThread;
|
||||||
|
TcpConnectDetect * m_pConnectDetect;
|
||||||
|
int m_detect; // 连接测试状态
|
||||||
|
private:
|
||||||
|
QString m_configFileName;
|
||||||
|
private:
|
||||||
|
QString m_localip;
|
||||||
|
quint16 m_localport;
|
||||||
|
QString m_serverip;
|
||||||
|
quint16 m_serverport;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GATEWAYTCPCLIENT_H
|
||||||
290
machine/lotmachine.cpp
Normal file
290
machine/lotmachine.cpp
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
#include "lotmachine.h"
|
||||||
|
#include <QTime>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
LotMachine::LotMachine(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_pTcpThread(NULL),
|
||||||
|
m_pTcpClient(NULL),
|
||||||
|
m_pComThread(NULL),
|
||||||
|
m_pComPort(NULL),
|
||||||
|
m_startComm(0)
|
||||||
|
{
|
||||||
|
m_receiveBuff.clear();
|
||||||
|
m_keyBuff.clear();
|
||||||
|
m_reFlag = 0;
|
||||||
|
m_connected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
LotMachine::~LotMachine()
|
||||||
|
{
|
||||||
|
if (m_startComm != 0)
|
||||||
|
{
|
||||||
|
if(m_connectMode == USE_TCP_COMM)
|
||||||
|
{
|
||||||
|
m_pTcpThread->quit();
|
||||||
|
m_pTcpThread->wait();
|
||||||
|
}
|
||||||
|
else if(m_connectMode == USE_SERIAL_COMM)
|
||||||
|
{
|
||||||
|
m_pComThread->quit();
|
||||||
|
m_pComThread->wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_connectMode == USE_TCP_COMM)
|
||||||
|
{
|
||||||
|
if(m_pTcpThread != NULL)
|
||||||
|
{
|
||||||
|
delete m_pTcpThread;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(m_connectMode == USE_SERIAL_COMM)
|
||||||
|
{
|
||||||
|
if(m_pComThread != NULL)
|
||||||
|
{
|
||||||
|
delete m_pComThread;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化通讯连接方式
|
||||||
|
void LotMachine::initConnectMode(s16 val)
|
||||||
|
{
|
||||||
|
m_connectMode = val;
|
||||||
|
if(m_connectMode == USE_TCP_COMM)//网口
|
||||||
|
{
|
||||||
|
m_pTcpThread = new QThread();
|
||||||
|
m_pTcpClient = new GatewayTcpClient();
|
||||||
|
}
|
||||||
|
else if(m_connectMode == USE_SERIAL_COMM)//串口
|
||||||
|
{
|
||||||
|
m_pComThread = new QThread();
|
||||||
|
m_pComPort = new ComPort();
|
||||||
|
connect(m_pComPort, SIGNAL(siSerialPortOpenState(int)), this, SLOT(slotIfOpenSerialPort(int)) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LotMachine::setConfigFileName(QString configfilename)
|
||||||
|
{
|
||||||
|
m_configFileName = configfilename;
|
||||||
|
if(m_connectMode == USE_TCP_COMM)//网口
|
||||||
|
{
|
||||||
|
m_pTcpClient->setConfigFileName(m_configFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置串口名称
|
||||||
|
void LotMachine::setComportName(QString portName)
|
||||||
|
{
|
||||||
|
if(m_pComPort == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_connectMode == USE_SERIAL_COMM)//串口
|
||||||
|
{
|
||||||
|
m_pComPort->setComPortName(portName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LotMachine::getConfigFileName()
|
||||||
|
{
|
||||||
|
return m_configFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LotMachine::startCommunication()
|
||||||
|
{
|
||||||
|
if (m_startComm == 0)
|
||||||
|
{
|
||||||
|
// qDebug() << "Machine " << QThread::currentThread();
|
||||||
|
|
||||||
|
if(m_connectMode == USE_TCP_COMM)//网口
|
||||||
|
{
|
||||||
|
if (m_configFileName.isEmpty())
|
||||||
|
{
|
||||||
|
qDebug() << "mast call SetConfigFileName first ";
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pTcpClient->moveToThread(m_pTcpThread); // 移动对象到线程中
|
||||||
|
|
||||||
|
// connect(qApp, SIGNAL(finished()), m_pTcpThread, SLOT(finished()));
|
||||||
|
|
||||||
|
connect(m_pTcpThread, SIGNAL(started()), m_pTcpClient, SLOT(connectToServer()) );
|
||||||
|
connect(m_pTcpThread, SIGNAL(finished()), m_pTcpClient, SLOT(deleteLater()) ); // 退出删除对象
|
||||||
|
|
||||||
|
connect(m_pTcpClient, SIGNAL(siConnectSta(int)),
|
||||||
|
this, SLOT(slotConnectSta(int)), Qt::AutoConnection); // 连接状态改变
|
||||||
|
connect(m_pTcpClient, SIGNAL(siConnectErr(QString)),
|
||||||
|
this, SLOT(slotConnectErr(QString)), Qt::AutoConnection); // 接收到通讯错误
|
||||||
|
connect(m_pTcpClient, SIGNAL(siReceiveData(QByteArray)),
|
||||||
|
this, SLOT(slotReceiveData(QByteArray)), Qt::AutoConnection); // 接收到数据
|
||||||
|
connect(this, SIGNAL(siSendData(QByteArray)),
|
||||||
|
m_pTcpClient, SLOT(slotSendData(QByteArray)), Qt::AutoConnection); // 发送数据的槽
|
||||||
|
|
||||||
|
m_pTcpThread->start(); // 启动线程
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_connectMode == USE_SERIAL_COMM)//串口
|
||||||
|
{
|
||||||
|
m_pComPort->moveToThread(m_pComThread);
|
||||||
|
|
||||||
|
connect(m_pComThread, SIGNAL(started()), m_pComPort, SLOT(initComm()) );
|
||||||
|
connect(m_pComThread, SIGNAL(finished()), m_pComPort, SLOT(deleteLater()) ); // 退出删除对象
|
||||||
|
|
||||||
|
connect(m_pComPort, SIGNAL(siReceiveData(QByteArray)),
|
||||||
|
this, SLOT(slotReceiveData(QByteArray)), Qt::QueuedConnection); // 接收到数据
|
||||||
|
connect(this, SIGNAL(siSendData(QByteArray)),
|
||||||
|
m_pComPort, SLOT(slotSendData(QByteArray)), Qt::QueuedConnection); // 发送数据的槽
|
||||||
|
|
||||||
|
m_pComThread->start(); // 启动线程
|
||||||
|
}
|
||||||
|
m_startComm = 1;
|
||||||
|
}
|
||||||
|
return m_startComm;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接状态改变的槽函数
|
||||||
|
void LotMachine::slotConnectSta(int sta)
|
||||||
|
{
|
||||||
|
// qDebug() << "SlotConnectSta" << sta;
|
||||||
|
if(m_connected != sta)
|
||||||
|
{
|
||||||
|
m_connected = sta;
|
||||||
|
if(m_connected == 3)//已连接
|
||||||
|
{
|
||||||
|
emit siConnectToMqtt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 接收到通讯错误槽函数
|
||||||
|
void LotMachine::slotConnectErr(QString errinfo)
|
||||||
|
{
|
||||||
|
Q_UNUSED(errinfo);
|
||||||
|
// qDebug() << "LotMachine::SlotConnectErr" << errinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 接收到数据的槽函数
|
||||||
|
void LotMachine::slotReceiveData(QByteArray dat)
|
||||||
|
{
|
||||||
|
m_receiveBuff.append(dat);
|
||||||
|
int size = m_receiveBuff.length();
|
||||||
|
QString str = m_receiveBuff;
|
||||||
|
if(str == "success")
|
||||||
|
{
|
||||||
|
m_receiveBuff.remove(0, size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//QString rackNumStr = getJsonValue("device");//机架号
|
||||||
|
QString bootCmd = getJsonValue("data","boot");//执行命令
|
||||||
|
|
||||||
|
if(bootCmd.length() > 0)
|
||||||
|
{
|
||||||
|
emit siRunLotDataAction(bootCmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_receiveBuff.remove(0, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
//串口是否打开
|
||||||
|
void LotMachine::slotIfOpenSerialPort(int val)
|
||||||
|
{
|
||||||
|
if(val != 0)
|
||||||
|
{
|
||||||
|
if(m_connectMode == USE_SERIAL_COMM)
|
||||||
|
{
|
||||||
|
m_connected = 3;//串口已打开
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取键值对属性值
|
||||||
|
QString LotMachine::getJsonValue(QString name1, QString name2)
|
||||||
|
{
|
||||||
|
QString rstr;
|
||||||
|
rstr.clear();
|
||||||
|
|
||||||
|
if(name1.length() <= 0 && name2.length() <= 0)
|
||||||
|
{
|
||||||
|
return rstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//QString str = "{\"device\":\"xiuhuaji133\",\"data\":{\"boot\":9}}";
|
||||||
|
QString str = m_receiveBuff;
|
||||||
|
|
||||||
|
QStringList vallist;
|
||||||
|
if(str.indexOf(",") == -1)
|
||||||
|
{
|
||||||
|
return rstr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vallist = str.split(",", QString::SkipEmptyParts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(name2.length() <= 0)
|
||||||
|
{
|
||||||
|
if(vallist.size() >= 1)
|
||||||
|
{
|
||||||
|
QStringList vallist1;
|
||||||
|
if(QString(vallist[0]).indexOf(":") == -1)
|
||||||
|
{
|
||||||
|
return rstr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vallist1 = QString(vallist[0]).split(":", QString::SkipEmptyParts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(QString(vallist1[0]).indexOf(name1) == -1)
|
||||||
|
{
|
||||||
|
return rstr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rstr = QString(vallist1[1]).remove("\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(vallist.size() >= 2)
|
||||||
|
{
|
||||||
|
QStringList vallist1;
|
||||||
|
if(QString(vallist[1]).indexOf(":") == -1)
|
||||||
|
{
|
||||||
|
return rstr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vallist1 = QString(vallist[1]).split(":", QString::SkipEmptyParts);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < vallist1.size(); i++)
|
||||||
|
{
|
||||||
|
if(QString(vallist1[i]).indexOf(name2) != -1)
|
||||||
|
{
|
||||||
|
if(i+1 < vallist1.size())
|
||||||
|
{
|
||||||
|
rstr = QString(vallist1[i+1]).remove("\"").remove("}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送物联数据到网关
|
||||||
|
void LotMachine::sendLotDataToGateway(QString str)
|
||||||
|
{
|
||||||
|
QByteArray dat;
|
||||||
|
dat.clear();
|
||||||
|
dat = str.toLatin1();
|
||||||
|
|
||||||
|
emit(siSendData(dat));
|
||||||
|
}
|
||||||
73
machine/lotmachine.h
Normal file
73
machine/lotmachine.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#ifndef LOTMACHINE_H
|
||||||
|
#define LOTMACHINE_H
|
||||||
|
|
||||||
|
#include "gatewaytcpclient.h"
|
||||||
|
#include "comport.h"
|
||||||
|
#include "comm/typedef.h"
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#define USE_TCP_COMM 0
|
||||||
|
#define USE_SERIAL_COMM 1
|
||||||
|
|
||||||
|
class LotMachine: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LotMachine(QObject *parent = NULL);
|
||||||
|
virtual ~LotMachine();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initConnectMode(s16 val = 0);//初始化通讯连接方式
|
||||||
|
void setConfigFileName(QString configfilename);
|
||||||
|
void setComportName(QString portName);//设置串口名称
|
||||||
|
QString getConfigFileName();
|
||||||
|
int startCommunication();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_configFileName;
|
||||||
|
QByteArray m_receiveBuff;//接收到的buf
|
||||||
|
QByteArray m_keyBuff;//键值对buf
|
||||||
|
s16 m_reFlag;
|
||||||
|
|
||||||
|
private:
|
||||||
|
s16 m_connectMode; //通讯连接方式 0:网口,1:串口
|
||||||
|
// 通讯线程和网络连接
|
||||||
|
QThread * m_pTcpThread;
|
||||||
|
GatewayTcpClient * m_pTcpClient;
|
||||||
|
QThread * m_pComThread;
|
||||||
|
ComPort * m_pComPort;
|
||||||
|
|
||||||
|
// 连接
|
||||||
|
public:
|
||||||
|
inline int isConnected() const { return m_connected; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_startComm;
|
||||||
|
int m_connected; // 机器连接状态. 0, 未连接; 1, 连接中; 2,
|
||||||
|
|
||||||
|
signals: // 发送数据到机器的信号
|
||||||
|
void siSendData(QByteArray dat);
|
||||||
|
void siRunLotDataAction(QString cmd);//执行物联网数据动作
|
||||||
|
void siConnectToMqtt();//与网关已连接
|
||||||
|
|
||||||
|
private slots: // 和线程通讯的槽
|
||||||
|
void slotConnectSta(int sta); // 连接状态改变的槽函数
|
||||||
|
void slotConnectErr(QString errinfo); // 接收到通讯错误槽函数
|
||||||
|
void slotReceiveData(QByteArray dat); // 接收到数据的槽函数
|
||||||
|
void slotIfOpenSerialPort(int val);//串口是否打开
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString getJsonValue(QString name1,QString name2 = NULL);//获取键值对属性值
|
||||||
|
|
||||||
|
public:
|
||||||
|
void sendLotDataToGateway(QString str);//发送物联数据到网关
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOTMACHINE_H
|
||||||
|
|
||||||
2087
machine/machine.cpp
Normal file
2087
machine/machine.cpp
Normal file
File diff suppressed because it is too large
Load Diff
314
machine/machine.h
Normal file
314
machine/machine.h
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
#ifndef MACHINE_H
|
||||||
|
#define MACHINE_H
|
||||||
|
|
||||||
|
#include "tcpclient.h"
|
||||||
|
#include "comport.h"
|
||||||
|
#include "datafile/datafiledsr.h"
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "comm/datadef.h"
|
||||||
|
#include "comm/protocol.h"
|
||||||
|
|
||||||
|
#define USE_TCP_COMM 0
|
||||||
|
#define USE_SERIAL_COMM 1
|
||||||
|
|
||||||
|
class Machine: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Machine(QObject *parent = NULL);
|
||||||
|
virtual ~Machine();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initConnectMode(s16 val = 0);//初始化通讯连接方式
|
||||||
|
void setConfigFileName(QString configfilename);
|
||||||
|
void setComportName(QString portName);//设置串口名称
|
||||||
|
QString getConfigFileName();
|
||||||
|
int startCommunication();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_configFileName;
|
||||||
|
|
||||||
|
private:
|
||||||
|
s16 m_connectMode; //通讯连接方式 0:网口,1:串口
|
||||||
|
// 通讯线程和网络连接
|
||||||
|
QThread * m_pTcpThread;
|
||||||
|
TcpClient * m_pTcpClient;
|
||||||
|
QThread * m_pComThread;
|
||||||
|
ComPort * m_pComPort;
|
||||||
|
|
||||||
|
// 连接
|
||||||
|
public:
|
||||||
|
inline int isConnected() const { return m_connected; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_startComm;
|
||||||
|
int m_connected; // 机器连接状态. 0, 未连接; 1, 连接中; 2,
|
||||||
|
|
||||||
|
signals: // 发送数据到机器的信号
|
||||||
|
void siSendData(QByteArray dat);
|
||||||
|
void siSendDataDone();
|
||||||
|
|
||||||
|
private slots: // 和线程通讯的槽
|
||||||
|
void slotConnectSta(int sta); // 连接状态改变的槽函数
|
||||||
|
void slotConnectErr(QString errinfo); // 接收到通讯错误槽函数
|
||||||
|
void slotReceiveData(QByteArray dat); // 接收到数据的槽函数
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// 通讯命令
|
||||||
|
|
||||||
|
// 机器信息
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
|
||||||
|
// 机器状态
|
||||||
|
public:
|
||||||
|
inline int isStatusEn() const { return m_statusEn; }
|
||||||
|
inline const MCStatus & getMcStatus() {m_statusEn = 0; return m_mcStatus; }
|
||||||
|
void setMcStatusAsMc(u8 * buff, int toggle);
|
||||||
|
|
||||||
|
//机器信息
|
||||||
|
inline const MCInfo &getMcInfo(){return m_mcInfo;}
|
||||||
|
//物联数据
|
||||||
|
inline const McLotData &getMcLotData(){return m_lotData;}
|
||||||
|
//调试信息
|
||||||
|
inline const DebugInfo &getDebugInfo(){return m_debugInfo;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_statusEn; // 状态有效标志
|
||||||
|
int m_statusToggle;
|
||||||
|
MCStatus m_mcStatus; // 机器状态
|
||||||
|
MCInfo m_mcInfo; // 机器信息
|
||||||
|
McLotData m_lotData; // 物联数据
|
||||||
|
DebugInfo m_debugInfo;//调试信息
|
||||||
|
|
||||||
|
// 机器参数
|
||||||
|
public:
|
||||||
|
inline const ParaStruct & getMcPara() {/*m_mcParaEn = 0; */ return m_mcPara; }
|
||||||
|
inline const ParaStruct & getWkPara() {/*m_wkParaEn = 0; */ return m_wkPara; }
|
||||||
|
inline const KnifeGapPara & getGainPara() { return m_gainPara; }
|
||||||
|
inline const ParaStruct & getPreMcPara() {/*m_mcParaEn = 0; */ return m_mcPrePara; }
|
||||||
|
inline const ParaStruct & getPreWkPara() {/*m_wkParaEn = 0; */ return m_wkPrePara; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ParaStruct m_mcPara; // 机器参数信息 配置信息
|
||||||
|
ParaStruct m_wkPara; // 工作参数信息
|
||||||
|
ParaStruct m_mcPrePara; // 机器预留参数
|
||||||
|
ParaStruct m_wkPrePara; // 工作预留参数
|
||||||
|
KnifeGapPara m_gainPara;
|
||||||
|
int m_mcParaEn;
|
||||||
|
int m_wkParaEn;
|
||||||
|
int m_gainParaEn;//电机增益参数
|
||||||
|
int m_mcPreParaEn;
|
||||||
|
int m_wkPreParaEn;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline int isSensorBmpEn() const { return m_sensorBmpEn; }
|
||||||
|
inline const SensorsBitmap & getSensorDat() {/* m_sensorStaEn = 0; */ return m_sensorsStaDat; }
|
||||||
|
inline const SensorsBitmap & getSensorBmp() {/* m_sensorBmpEn = 0; */ return m_sensorEnBmp; }
|
||||||
|
inline int getTotalSendNum() { return m_totalSendNum; }
|
||||||
|
inline int getTotalPacketNum() { return m_totalPacketNum; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
SensorsBitmap m_sensorsStaDat; // 传感器信号状态位图
|
||||||
|
SensorsBitmap m_sensorEnBmp; // 传感器信号有效位图
|
||||||
|
int m_sensorStaEn;
|
||||||
|
int m_sensorBmpEn;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setTcpConnectState(int state);
|
||||||
|
void setMacKey(unsigned char * p_dat , int i_size); // 设置机器的密钥
|
||||||
|
// 文件传输结果
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer * m_pSendTimer;
|
||||||
|
FileTransCtrl m_transCtrl;
|
||||||
|
int m_fileTransEn;
|
||||||
|
int m_transBreak;
|
||||||
|
int m_totalSendNum;//传输文件时总共发送的包数
|
||||||
|
int m_totalPacketNum;//传输文件时总的包数
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onSendTimer(void);
|
||||||
|
void slIfOpenSerialPort(int val);//串口是否打开
|
||||||
|
|
||||||
|
signals: // 发送给UI的信号
|
||||||
|
void siMcInfoChange(); // 机器信息改变信号
|
||||||
|
void siDebugInfo(); //调试信息改变信号
|
||||||
|
void siReceiveLotData(); // 接收物联数据信号
|
||||||
|
void siStatusChange(int); // 状态改变信号
|
||||||
|
void siParaChange(int type, int id); // 参数更新信号
|
||||||
|
void siMemDataChange(int beginAddr); // 内存数据更新信号
|
||||||
|
void siSensorChange(SensorsBitmap map); // 传感信号更新信号
|
||||||
|
void siFileInfoChange(); // 文件信息更新信号
|
||||||
|
void siTransResultChange(); // 文件传输结果信号
|
||||||
|
void siTransProgress(u8 fileType, int send, int total); // 文件传输结果信号
|
||||||
|
void siSensorEnBitmap(SensorsBitmap map); // 传感信号有效位图更新信号
|
||||||
|
void siDataFilePos(DataFilePos pos); // 边框检查时起始点超出范围后下位机自动定新的起始点后发给上位机
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void breakFileTrans(); // 打断文件传输
|
||||||
|
|
||||||
|
public: // 机器执行命令,读取下位机数据
|
||||||
|
void getInfoFromMachine();
|
||||||
|
int getStatusFromMachine();
|
||||||
|
void getNetDataFromMachine(); // 读取机器物联数据
|
||||||
|
void getParasFromMachine(int type = -1, int id = 0); // 读取机器参数
|
||||||
|
void restoreFactorySetting(int type = -1); // 恢复出厂设置
|
||||||
|
void getSensorsFromMachine(int backtype = 0);
|
||||||
|
void getTransResultFromMachine(int fileid);
|
||||||
|
void getSensorEnBmpFromMachine(); // 获取传感器有效标志位图
|
||||||
|
void sleep(int sec);
|
||||||
|
|
||||||
|
public: // 设置机器配置
|
||||||
|
// #define UCMD_SET_MC_CONFIG 0x0101 VLDP 无 设置机器的配置,包括信号使用的端口等信息
|
||||||
|
|
||||||
|
public: // 设置机器状态
|
||||||
|
void setMcStatus(int stacode, int para = 0);
|
||||||
|
void cleanError(); // 清除错误
|
||||||
|
void setEnableWorkSta(); // 设置允许工作状态
|
||||||
|
void setDisableWorkSta(); // 设置禁止工作状态
|
||||||
|
void setEnableWorkTime(); // 设置允许工作时间状态
|
||||||
|
void setDisableWorkTime(); // 设置禁止工作时间状态
|
||||||
|
void resetOutput(); // 重置产量
|
||||||
|
void setToManualWork(); // 手动工作状态
|
||||||
|
void setToAutoWork(); // 自动工作状态
|
||||||
|
void switchWorkFile(int idx = 0); // 文件切换
|
||||||
|
void invalidateWorkFile(int idx = 0); // 文件失效
|
||||||
|
void cleanNewParaFlag(); // 清除新参数标志
|
||||||
|
void setSimulateWork(); // 模拟工作状态
|
||||||
|
void setNormalWork(); // 正常工作状态
|
||||||
|
void setWorkHead(int head); // 设置工作机头
|
||||||
|
void exitDetectTest(); //退出断线测试
|
||||||
|
void resetBobbinCounter(); // 底线计数复位
|
||||||
|
void outputReset(); // 产量清零
|
||||||
|
void entrySensorScan(); // 进入扫描传感器状态
|
||||||
|
void exitSensorScan(); // 退出扫描传感器状态
|
||||||
|
void setElapsed(unsigned char i_type , unsigned char i_time); // 设置经过的时间
|
||||||
|
void testThreadBK(int type,int needle); // 测试断线检测,1是面线,2是底线
|
||||||
|
|
||||||
|
public: // 设置机器参数
|
||||||
|
void setParasToMachine(int type, ParaStruct & para);
|
||||||
|
void setAParasToMachine(int type, int idx, u32 value);
|
||||||
|
void setShutDownTime(u8 type, u32 time);
|
||||||
|
void setHeadSpacingToMachine(int type, QByteArray data, u16 paraId);
|
||||||
|
void setMcPara(ParaStruct * pPara);
|
||||||
|
void setWkPara(ParaStruct * pPara);
|
||||||
|
void setMcPrePara(ParaStruct * pPara);//预留参数
|
||||||
|
void setWkPrePara(ParaStruct * pPara);//预留参数
|
||||||
|
void setAMcPara(int id, u32 value);
|
||||||
|
void setAWkPara(int id, u32 value);
|
||||||
|
void setAMcPrePara(int id, u32 value);//预留参数
|
||||||
|
void setAWkPrePara(int id, u32 value);//预留参数
|
||||||
|
|
||||||
|
void setHeadSpacing(DsrHeadEx62 para);
|
||||||
|
|
||||||
|
public: // 设置内存数据
|
||||||
|
// #define UCMD_SET_MEM_DATA 0x0104 // 设置内存数据
|
||||||
|
|
||||||
|
public: // 设置文件参数
|
||||||
|
void setFilePara(int fileidx, int fileid, DataFilePara & filePara);
|
||||||
|
|
||||||
|
public: // 设置执行进度
|
||||||
|
void setFileExecProgress(int fileidx, int fileid, FileExecPara & fileExecPara);
|
||||||
|
void setToDefaultParas(int type, u8 id = 0, u8 nodeType = 0);
|
||||||
|
int headup;
|
||||||
|
|
||||||
|
public slots: // 手动控制命令
|
||||||
|
void actionByhand(int actcode, int para1, int para2 = 0, int para3 = 0);
|
||||||
|
void motoToZero(int obj); // 电机归零(辅助调试的功能,无安全保护和逻辑关系)
|
||||||
|
void motoMove(int obj, int dir, int spd); // 电机移动(辅助调试的功能,无安全保护和逻辑关系)
|
||||||
|
void pullMove(int obj, int dir, int spd); // 拉料移动(辅助调试的功能,无安全保护和逻辑关系) coco
|
||||||
|
void outputCtrl(int obj, int act = 0, int para = 0); // 输出控制(辅助调试的功能,无安全保护和逻辑关系)
|
||||||
|
void motoServoCtrl(int obj, int onoff); // 电机使能控制(辅助调试的功能,无安全保护和逻辑关系)
|
||||||
|
|
||||||
|
void sewingMsServoOn();
|
||||||
|
void sewingMsServoOff(); // 缝纫主轴使能控制
|
||||||
|
|
||||||
|
void manualAction(int obj, int para2 = 0, int para3 = 0); // 手动动作功能(日常使用功能,有安全保护和逻辑时序关系)
|
||||||
|
|
||||||
|
void cutThreadByhand(); // 手动剪线
|
||||||
|
void makeup(int mode); //补缝
|
||||||
|
void msAdjust(int obj, int step); // 针梭校对
|
||||||
|
//void rotaAdjust(int step); // 旋转校对
|
||||||
|
|
||||||
|
void sewHeadLiftUpDown(); // 机头升降
|
||||||
|
void ThicklineSewHeadLiftUpDown();// 粗线布线机机头升降
|
||||||
|
void sewHeadLiftUp(); // 机头上升
|
||||||
|
void sewHeadLiftDown(); // 机头下降
|
||||||
|
void sewHeadLiftUp2(); // 机头上升2
|
||||||
|
void sewHeadLiftDown2(); // 机头下降2
|
||||||
|
void sewingMsRun(); // 缝纫主轴研车
|
||||||
|
void gotoGorner(int nNum);// 回角点
|
||||||
|
void manualOil(int nNum); // 手动加油
|
||||||
|
void shuttleCounter(); //梭盘计数复位
|
||||||
|
void changeOneShuttle();//自动换一个梭
|
||||||
|
void installShuttle(); //安装第一个梭壳
|
||||||
|
void sewBuff(); //缝纫状态
|
||||||
|
void shuttleDiskBuff(); //换梭盘状态
|
||||||
|
void shuttleToHead(); //将旋梭从梭盘到机头
|
||||||
|
void headToShuttle(); //将旋梭从机头拿到梭盘
|
||||||
|
void allMsRun(); // 所有主轴研车
|
||||||
|
|
||||||
|
void headLift(); // 机头升降
|
||||||
|
void msReset(); // 针梭复位
|
||||||
|
void msToFix(); // 针梭去穿线位
|
||||||
|
void sewCutThread(int nNum); // 缝纫剪线
|
||||||
|
|
||||||
|
void moveFrameByHand(char xy, char dir, int spd); // 手动移框
|
||||||
|
void sewJog(); // 缝纫点动
|
||||||
|
|
||||||
|
void spindleHookPos(int def); // 主轴去勾线位
|
||||||
|
void spindleParkPos(int def); // 主轴去停车位
|
||||||
|
public: // 机器工作命令
|
||||||
|
void mcWorkCmd(int workcode, int para1 = 0 , int para2 = 0);
|
||||||
|
|
||||||
|
void startWork(); // 启动工作
|
||||||
|
void pauseWork(); // 暂停工作
|
||||||
|
void allToReset(); // 流程复位
|
||||||
|
void allToZero(); // 全部归零
|
||||||
|
|
||||||
|
void gotoStartPos(); // 回起针点
|
||||||
|
void gotoAnchor(); // 回定位点
|
||||||
|
void setOffsetPos(); // 定偏移点
|
||||||
|
void gotoFinish(); // 回结束点
|
||||||
|
void gotoOffsetPos(); // 回偏移点
|
||||||
|
void setFeedPos(); // 定上料点
|
||||||
|
void gotoFeedPos(); // 回上料点
|
||||||
|
|
||||||
|
void checkFrame(); // 边框检查
|
||||||
|
void simulateFrame(); // 空走边框
|
||||||
|
|
||||||
|
void fastJump(int idx); // 前进回退
|
||||||
|
void gotoWorkPos(); // 回工作点
|
||||||
|
void gotoFixPos(); // 回穿线点
|
||||||
|
void gotoShuttlePos(); // 回换梭位
|
||||||
|
|
||||||
|
void gotoZeroPos(); // 回零点
|
||||||
|
void msRpmChange(int chgram,int flag); // 速度改变
|
||||||
|
void mainShaftJog();// 主轴点动
|
||||||
|
void embSpindleTest(s32 para1, s32 para2); // 主轴研车
|
||||||
|
|
||||||
|
public: // 移动到XY坐标命令
|
||||||
|
void moveFrameTo(int x, int y);
|
||||||
|
|
||||||
|
public: // 文件传输命令
|
||||||
|
int sendFileProc(int type, int idx, int id, DataDs16FileHead * pfileHead, u8 * pDatBuff);
|
||||||
|
int sendFileProc(int type, int idx, int id, DataDs16FileHead & fileHead, u8 * pDatBuff);
|
||||||
|
int sendAPPFileProc(int type, int idx, int id, AppFileHead &fileHead, u8 *pDatBuff);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void startFileTrans(FileTransCtrl & transCtrl);
|
||||||
|
void transFileData(FileTransCtrl & transCtrl, int pktidx);
|
||||||
|
|
||||||
|
public: // 下位机系统升级命令
|
||||||
|
void updateFirmware(); // 下位机升级
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MACHINE_H
|
||||||
|
|
||||||
215
machine/mytcpserver.cpp
Normal file
215
machine/mytcpserver.cpp
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
#include "mytcpserver.h"
|
||||||
|
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QApplication>
|
||||||
|
#include "main.h"
|
||||||
|
//单个包数据大小
|
||||||
|
#define PKG_DATA_SIZE 1024
|
||||||
|
|
||||||
|
MyTcpServer::MyTcpServer(QObject *parent) :
|
||||||
|
QTcpServer(parent)
|
||||||
|
{
|
||||||
|
qDebug()<<__FUNCTION__;
|
||||||
|
//花样文件目录
|
||||||
|
QDir apppath(qApp->applicationDirPath());
|
||||||
|
QString filePath = apppath.path() + QDir::separator() + PATTERNPATH;
|
||||||
|
m_firstFilePath = QDir(filePath).absolutePath();//为了将"\"变为"/"
|
||||||
|
m_socket = new QTcpSocket();
|
||||||
|
reflashFileTrans();
|
||||||
|
}
|
||||||
|
|
||||||
|
MyTcpServer::~MyTcpServer()
|
||||||
|
{
|
||||||
|
delete m_socket ;
|
||||||
|
qDebug()<<__FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 数据打包
|
||||||
|
* @param cmd1
|
||||||
|
* @param cmd2
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QByteArray MyTcpServer::createDataPacket(int cmd1, int cmd2, QByteArray data)
|
||||||
|
{
|
||||||
|
QByteArray cmd;
|
||||||
|
cmd += cmd1;
|
||||||
|
cmd += cmd2;
|
||||||
|
QByteArray bytes(sizeof(FilePkgHead),0);
|
||||||
|
FilePkgHead head;
|
||||||
|
memcpy(&head.cmd,cmd.data(),sizeof(short int));
|
||||||
|
head.dataSize = data.size();
|
||||||
|
// qDebug()<<"data.size:"<<data.size();
|
||||||
|
// qDebug()<<"FilePkgHead.size:"<<sizeof(FilePkgHead);
|
||||||
|
memcpy(bytes.data(),&head,sizeof(FilePkgHead));
|
||||||
|
bytes+=data;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyTcpServer::reflashFileTrans()
|
||||||
|
{
|
||||||
|
totalBytes = 0;
|
||||||
|
m_fileBuffer_Recv.clear();
|
||||||
|
m_fileBuffer_Send.clear();
|
||||||
|
// fileName.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
void MyTcpServer::incomingConnection(qintptr socketDescriptor)
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
void MyTcpServer::incomingConnection(int socketDescriptor)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// 当有客户端连接时,会调用这个方法
|
||||||
|
qDebug()<<"MyTcpServer::incomingConnectio";
|
||||||
|
|
||||||
|
// 设置socket的描述符
|
||||||
|
m_socket->setSocketDescriptor(socketDescriptor);
|
||||||
|
|
||||||
|
// 连接信号和槽来读取来自客户端的数据和处理断开连接
|
||||||
|
connect(m_socket, SIGNAL(readyRead()), this, SLOT(connectionHandle()));
|
||||||
|
connect(m_socket, SIGNAL(disconnected()), this, SLOT(disconnectHandle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyTcpServer::connectionHandle()
|
||||||
|
{
|
||||||
|
QByteArray buffer = m_socket->readAll();
|
||||||
|
|
||||||
|
if(!buffer.isEmpty())
|
||||||
|
{
|
||||||
|
char cmd1 = buffer.at(0);
|
||||||
|
Q_UNUSED(cmd1)
|
||||||
|
char cmd2 = buffer.at(1);
|
||||||
|
FilePkgHead *head = (FilePkgHead *)buffer.data();
|
||||||
|
QByteArray data = buffer.right(head->dataSize);
|
||||||
|
|
||||||
|
qDebug()<<"=============================================================================";
|
||||||
|
qDebug()<< "dataLength:" <<head->dataSize<<" ";
|
||||||
|
|
||||||
|
|
||||||
|
switch (cmd2)
|
||||||
|
{
|
||||||
|
case 0x01://保存文件名和文件大小
|
||||||
|
{
|
||||||
|
if(totalBytes !=0)
|
||||||
|
qWarning()<<"0x01>>(totalBytes !=0)";
|
||||||
|
|
||||||
|
reflashFileTrans();
|
||||||
|
|
||||||
|
//记录文件名称和文件大小
|
||||||
|
memcpy(&totalBytes,data.data(),sizeof(qint64));
|
||||||
|
const qint64 memory_10M = 10*1024*1024;
|
||||||
|
if(totalBytes > memory_10M) //文件大小超过10m
|
||||||
|
{
|
||||||
|
m_socket->write(createDataPacket(0x01,0x05,NULL));
|
||||||
|
reflashFileTrans();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = data.right(data.size() - sizeof(qint64));
|
||||||
|
fileName = QString::fromUtf8(data);
|
||||||
|
fileName = m_firstFilePath + QDir::separator() + fileName;
|
||||||
|
|
||||||
|
qDebug()<<"0x01>>Recv Path Name:" << fileName;
|
||||||
|
qDebug()<<"0x01>>Recv File Name:" << fileName;
|
||||||
|
qDebug()<<"0x01>>Recv File TotalBytes:" << totalBytes;
|
||||||
|
|
||||||
|
if(QFile(fileName).exists())//文件存在,取消传输
|
||||||
|
{
|
||||||
|
m_socket->write(createDataPacket(0x01,0x05,NULL));
|
||||||
|
reflashFileTrans();
|
||||||
|
qDebug()<<fileName<<"QFile(fileName).exists()xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||||
|
}
|
||||||
|
|
||||||
|
//刷新缓冲区
|
||||||
|
m_fileBuffer_Recv.reserve(totalBytes);
|
||||||
|
m_fileBuffer_Recv.resize(0);
|
||||||
|
|
||||||
|
m_socket->write(createDataPacket(0x01,0x04,NULL));
|
||||||
|
m_socket->flush();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 0x02://接收文件数据
|
||||||
|
{
|
||||||
|
if((totalBytes == 0) || (totalBytes <= m_fileBuffer_Recv.size()))
|
||||||
|
{
|
||||||
|
qWarning()<< "0x02>>(totalBytes == 0) || (totalBytes <= m_fileBuffer_Recv.size())";
|
||||||
|
qWarning()<< "0x02>>totalBytes:"<<totalBytes<<"m_fileBuffer_Recv.size():"<<m_fileBuffer_Recv.size();
|
||||||
|
reflashFileTrans();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fileBuffer_Recv += data;//缓冲数据
|
||||||
|
m_socket->write(createDataPacket(0x01,0x04,NULL));
|
||||||
|
m_socket->flush();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 0x03://接收文件完成
|
||||||
|
{
|
||||||
|
if(m_fileBuffer_Recv.size() == totalBytes)
|
||||||
|
{
|
||||||
|
QFile file(fileName);
|
||||||
|
if(!file.open(QFile::WriteOnly))
|
||||||
|
{
|
||||||
|
qWarning() << "0x03 open file error!";
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
file.write(m_fileBuffer_Recv);
|
||||||
|
file.close();
|
||||||
|
qDebug() << "0x03 file.trans success>>>"<<fileName;;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qWarning()<< "0x03>>(m_fileBuffer_Recv.size() != totalBytes)";
|
||||||
|
|
||||||
|
reflashFileTrans();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 0x04://发送文件数据
|
||||||
|
{
|
||||||
|
if(!m_fileBuffer_Send.isEmpty())
|
||||||
|
{
|
||||||
|
QByteArray outBlock = m_fileBuffer_Send.left(qMin(m_fileBuffer_Send.size(),PKG_DATA_SIZE));
|
||||||
|
m_fileBuffer_Send = m_fileBuffer_Send.right(m_fileBuffer_Send.size() - outBlock.size());//保留后一部分
|
||||||
|
QByteArray packet = createDataPacket(0x01,0x02,outBlock);
|
||||||
|
m_socket->write(packet);
|
||||||
|
m_socket->flush();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug()<<"0x04>>m_fileBuffer_Send.isEmpty()"<<m_fileBuffer_Send.size();
|
||||||
|
QByteArray packet = createDataPacket(0x01,0x03,"File Trans Close");
|
||||||
|
m_socket->write(packet);
|
||||||
|
m_socket->flush();
|
||||||
|
reflashFileTrans();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 0x05://取消传输
|
||||||
|
{
|
||||||
|
reflashFileTrans();
|
||||||
|
qDebug()<<"0x05"<<data;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyTcpServer::disconnectHandle()
|
||||||
|
{
|
||||||
|
reflashFileTrans();
|
||||||
|
disconnect(m_socket, SIGNAL(readyRead()), this, SLOT(connectionHandle()));
|
||||||
|
disconnect(m_socket, SIGNAL(disconnected()), this, SLOT(disconnectHandle()));
|
||||||
|
|
||||||
|
qDebug()<<"MyTcpServer disconnection";
|
||||||
|
}
|
||||||
61
machine/mytcpserver.h
Normal file
61
machine/mytcpserver.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#ifndef MYTCPSERVER_H
|
||||||
|
#define MYTCPSERVER_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#pragma pack(1)
|
||||||
|
|
||||||
|
//数据包头
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
short int cmd; //命令
|
||||||
|
char check;//异或校验
|
||||||
|
unsigned int dataSize;//长度
|
||||||
|
} FilePkgHead;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The MyTcpServer class 文件传输服务器 单连接
|
||||||
|
*/
|
||||||
|
class MyTcpServer: public QTcpServer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MyTcpServer(QObject *parent = NULL);
|
||||||
|
~MyTcpServer();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//新的连接
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
void incomingConnection(qintptr socketDescriptor);
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
void incomingConnection(int handle);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void connectionHandle();//协议处理
|
||||||
|
void disconnectHandle(); //断开连接
|
||||||
|
//数据打包
|
||||||
|
QByteArray createDataPacket(int cmd1, int cmd2, QByteArray data);
|
||||||
|
|
||||||
|
public:
|
||||||
|
qint64 totalBytes; //数据总大小
|
||||||
|
QByteArray m_fileBuffer_Send; //缓冲文件,用于发送
|
||||||
|
QByteArray m_fileBuffer_Recv; //缓冲文件,用于接收
|
||||||
|
QTcpSocket *m_socket; //客户端
|
||||||
|
QString fileName;
|
||||||
|
|
||||||
|
QString m_firstFilePath;//根目录前缀
|
||||||
|
|
||||||
|
private:
|
||||||
|
void reflashFileTrans();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void recvFileSuccess(QString filePath);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MYTCPSERVER_H
|
||||||
186
machine/qbindtcpsocket.cpp
Normal file
186
machine/qbindtcpsocket.cpp
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
#include "qbindtcpsocket.h"
|
||||||
|
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
QBindTcpSocket::QBindTcpSocket(QObject *parent):
|
||||||
|
QTcpSocket(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QBindTcpSocket::~QBindTcpSocket()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int QBindTcpSocket::bindAddrAndPort(QString localAddr, quint16 localPort)
|
||||||
|
{
|
||||||
|
QString str = localAddr;
|
||||||
|
QHostAddress addr(str);
|
||||||
|
setLocalAddress(addr);
|
||||||
|
setLocalPort(localPort);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------
|
||||||
|
TcpConnectDetect::TcpConnectDetect(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_pDetectSocket(NULL),
|
||||||
|
m_localip(DEF_LOCAL_IP),
|
||||||
|
m_localport(DEF_LOCAL_PORT),
|
||||||
|
m_serverip(DEF_SERVER_IP),
|
||||||
|
m_serverport(DEF_SERVER_PORT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpConnectDetect::~TcpConnectDetect()
|
||||||
|
{
|
||||||
|
if (m_pDetectSocket == NULL)
|
||||||
|
{
|
||||||
|
m_pDetectSocket->disconnectFromHost();
|
||||||
|
m_pDetectSocket->waitForDisconnected();
|
||||||
|
m_pDetectSocket->close();
|
||||||
|
delete m_pDetectSocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpConnectDetect::detectStart()
|
||||||
|
{
|
||||||
|
qDebug("TcpConnectDetect start");
|
||||||
|
if (m_pDetectSocket == NULL)
|
||||||
|
{
|
||||||
|
m_pDetectSocket = new QBindTcpSocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int TcpConnectDetect::connectDetect()
|
||||||
|
{
|
||||||
|
int connectsta = 0;
|
||||||
|
int rslt;
|
||||||
|
|
||||||
|
// qDebug() << "TcpConnectDetect " << QThread::currentThread();
|
||||||
|
|
||||||
|
if (m_pDetectSocket == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (m_localip.isEmpty() == false)
|
||||||
|
{
|
||||||
|
m_pDetectSocket->bindAddrAndPort(m_localip, m_localport);
|
||||||
|
}
|
||||||
|
m_pDetectSocket->abort();
|
||||||
|
m_pDetectSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
||||||
|
m_pDetectSocket->connectToHost(m_serverip, m_serverport);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
rslt = m_pDetectSocket->waitForConnected(4000); // 等待连接
|
||||||
|
|
||||||
|
qDebug("bind Detect connect rslt=%d", rslt);
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
|
||||||
|
switch(m_pDetectSocket->state())
|
||||||
|
{
|
||||||
|
case QAbstractSocket::ConnectedState:
|
||||||
|
{
|
||||||
|
// 如果连接上,说明 m_pClientSocket 连接已经无效, 需要断开重新连接
|
||||||
|
// 先断开测试连接
|
||||||
|
m_pDetectSocket->disconnectFromHost();
|
||||||
|
m_pDetectSocket->waitForDisconnected();
|
||||||
|
connectsta = 1;
|
||||||
|
// 发送断开主连接的信号
|
||||||
|
qDebug() << "detect is Connected, disconnect all";
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::UnconnectedState:
|
||||||
|
{
|
||||||
|
// qDebug() << "detect is Unconnected err=" << m_pDetectSocket->error() << ", info:" << m_pDetectSocket->errorString();
|
||||||
|
|
||||||
|
switch (m_pDetectSocket->error())
|
||||||
|
{
|
||||||
|
case QAbstractSocket::SocketTimeoutError: // 连接超时,说明已经断开
|
||||||
|
case QAbstractSocket::NetworkError: // 网络错误, 主机不可连接, 可能已经断开
|
||||||
|
{
|
||||||
|
qDebug() << "detect is timout, disconnect all";
|
||||||
|
connectsta = 1;
|
||||||
|
// 发送断开主连接的信号
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::ConnectionRefusedError: // 拒绝连接, 说明连接还在
|
||||||
|
{
|
||||||
|
connectsta = 2;
|
||||||
|
// qDebug() << "Connection Refused, old connect is alive";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
case QAbstractSocket::RemoteHostClosedError:
|
||||||
|
case QAbstractSocket::HostNotFoundError:
|
||||||
|
case QAbstractSocket::SocketAccessError:
|
||||||
|
case QAbstractSocket::SocketResourceError:
|
||||||
|
case QAbstractSocket::SocketTimeoutError:
|
||||||
|
case QAbstractSocket::DatagramTooLargeError:
|
||||||
|
case QAbstractSocket::AddressInUseError:
|
||||||
|
case QAbstractSocket::SocketAddressNotAvailableError:
|
||||||
|
case QAbstractSocket::UnsupportedSocketOperationError:
|
||||||
|
case QAbstractSocket::UnfinishedSocketOperationError:
|
||||||
|
case QAbstractSocket::ProxyAuthenticationRequiredError:
|
||||||
|
case QAbstractSocket::SslHandshakeFailedError:
|
||||||
|
case QAbstractSocket::ProxyConnectionRefusedError:
|
||||||
|
case QAbstractSocket::ProxyConnectionClosedError:
|
||||||
|
case QAbstractSocket::ProxyConnectionTimeoutError:
|
||||||
|
case QAbstractSocket::ProxyNotFoundError:
|
||||||
|
case QAbstractSocket::ProxyProtocolError:
|
||||||
|
case QAbstractSocket::UnknownSocketError:
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// 继续检测
|
||||||
|
connectsta = 2;
|
||||||
|
qDebug() << " retry";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} // 错误处理结束
|
||||||
|
}
|
||||||
|
case QAbstractSocket::ConnectingState:
|
||||||
|
{
|
||||||
|
// qDebug() << "detect is Connecting";
|
||||||
|
// qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
// 继续等待
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::HostLookupState:
|
||||||
|
case QAbstractSocket::BoundState:
|
||||||
|
case QAbstractSocket::ListeningState:
|
||||||
|
case QAbstractSocket::ClosingState:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// 继续等待
|
||||||
|
qDebug("detect sta is %d\r\n", m_pDetectSocket->state());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connectsta != 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}while(1);
|
||||||
|
|
||||||
|
|
||||||
|
m_pDetectSocket->close();
|
||||||
|
|
||||||
|
// 发送本次测试连接的状态信号
|
||||||
|
emit(siConnectSta(connectsta));
|
||||||
|
return connectsta;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpConnectDetect::setIpAndPort(QString localip, quint16 localport, QString serverip, quint16 serverport)
|
||||||
|
{
|
||||||
|
m_localip = localip;
|
||||||
|
m_localport = localport;
|
||||||
|
m_serverip = serverip;
|
||||||
|
m_serverport = serverport;
|
||||||
|
}
|
||||||
53
machine/qbindtcpsocket.h
Normal file
53
machine/qbindtcpsocket.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef QBINDTCPSOCKET_H
|
||||||
|
#define QBINDTCPSOCKET_H
|
||||||
|
|
||||||
|
#define DEF_SERVER_IP "192.168.16.253"
|
||||||
|
#define DEF_SERVER_PORT 5000
|
||||||
|
#define DEF_LOCAL_IP ""
|
||||||
|
#define DEF_LOCAL_PORT 5001
|
||||||
|
|
||||||
|
|
||||||
|
#include <QTcpSocket>
|
||||||
|
|
||||||
|
class QBindTcpSocket : public QTcpSocket
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
QBindTcpSocket(QObject *parent = 0);
|
||||||
|
virtual ~QBindTcpSocket();
|
||||||
|
|
||||||
|
public:
|
||||||
|
int bindAddrAndPort(QString localAddr, quint16 localPort);
|
||||||
|
};
|
||||||
|
|
||||||
|
#if(1)
|
||||||
|
class TcpConnectDetect : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TcpConnectDetect(QObject *parent = NULL);
|
||||||
|
virtual ~TcpConnectDetect();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void siConnectSta(int sta); // 网络连接信号
|
||||||
|
public:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void detectStart();
|
||||||
|
int connectDetect();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QBindTcpSocket * m_pDetectSocket;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setIpAndPort(QString localip, quint16 localport, QString serverip, quint16 serverport);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_localip;
|
||||||
|
quint16 m_localport;
|
||||||
|
QString m_serverip;
|
||||||
|
quint16 m_serverport;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // QBINDTCPSOCKET_H
|
||||||
1117
machine/qextserial/posix_qextserialport.cpp
Normal file
1117
machine/qextserial/posix_qextserialport.cpp
Normal file
File diff suppressed because it is too large
Load Diff
57
machine/qextserial/posix_qextserialport.h
Normal file
57
machine/qextserial/posix_qextserialport.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
#ifndef _POSIX_QEXTSERIALPORT_H_
|
||||||
|
#define _POSIX_QEXTSERIALPORT_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include "qextserialbase.h"
|
||||||
|
|
||||||
|
class Posix_QextSerialPort:public QextSerialBase {
|
||||||
|
public:
|
||||||
|
Posix_QextSerialPort();
|
||||||
|
Posix_QextSerialPort(const Posix_QextSerialPort& s);
|
||||||
|
Posix_QextSerialPort(const QString & name);
|
||||||
|
Posix_QextSerialPort(const PortSettings& settings);
|
||||||
|
Posix_QextSerialPort(const QString & name, const PortSettings& settings);
|
||||||
|
Posix_QextSerialPort& operator=(const Posix_QextSerialPort& s);
|
||||||
|
virtual ~Posix_QextSerialPort();
|
||||||
|
|
||||||
|
virtual void setBaudRate(BaudRateType);
|
||||||
|
virtual void setDataBits(DataBitsType);
|
||||||
|
virtual void setParity(ParityType);
|
||||||
|
virtual void setStopBits(StopBitsType);
|
||||||
|
virtual void setFlowControl(FlowType);
|
||||||
|
virtual void setTimeout(ulong, ulong);
|
||||||
|
|
||||||
|
virtual bool open(OpenMode mode=0);
|
||||||
|
virtual void close();
|
||||||
|
virtual void flush();
|
||||||
|
|
||||||
|
virtual qint64 size() const;
|
||||||
|
virtual qint64 bytesAvailable();
|
||||||
|
|
||||||
|
virtual void ungetChar(char c);
|
||||||
|
|
||||||
|
virtual void translateError(ulong error);
|
||||||
|
|
||||||
|
virtual void setDtr(bool set=true);
|
||||||
|
virtual void setRts(bool set=true);
|
||||||
|
virtual ulong lineStatus();
|
||||||
|
|
||||||
|
QFile* Posix_File;
|
||||||
|
protected:
|
||||||
|
//QFile* Posix_File;
|
||||||
|
struct termios Posix_CommConfig;
|
||||||
|
struct timeval Posix_Timeout;
|
||||||
|
struct timeval Posix_Copy_Timeout;
|
||||||
|
|
||||||
|
virtual qint64 readData(char * data, qint64 maxSize);
|
||||||
|
virtual qint64 writeData(const char * data, qint64 maxSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
250
machine/qextserial/qextserialbase.cpp
Normal file
250
machine/qextserial/qextserialbase.cpp
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
|
||||||
|
#include "qextserialbase.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\class QextSerialBase
|
||||||
|
\version 1.0.0
|
||||||
|
\author Stefan Sander
|
||||||
|
|
||||||
|
A common base class for Win_QextSerialBase, Posix_QextSerialBase and QextSerialPort.
|
||||||
|
*/
|
||||||
|
#ifdef QT_THREAD_SUPPORT
|
||||||
|
QMutex* QextSerialBase::mutex=NULL;
|
||||||
|
unsigned long QextSerialBase::refCount=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialBase::QextSerialBase()
|
||||||
|
Default constructor.
|
||||||
|
*/
|
||||||
|
QextSerialBase::QextSerialBase()
|
||||||
|
: QIODevice()
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef _TTY_WIN_
|
||||||
|
setPortName("COM1");
|
||||||
|
|
||||||
|
#elif defined(_TTY_IRIX_)
|
||||||
|
setPortName("/dev/ttyf1");
|
||||||
|
|
||||||
|
#elif defined(_TTY_HPUX_)
|
||||||
|
setPortName("/dev/tty1p0");
|
||||||
|
|
||||||
|
#elif defined(_TTY_SUN_)
|
||||||
|
setPortName("/dev/ttya");
|
||||||
|
|
||||||
|
#elif defined(_TTY_DIGITAL_)
|
||||||
|
setPortName("/dev/tty01");
|
||||||
|
|
||||||
|
#elif defined(_TTY_FREEBSD_)
|
||||||
|
setPortName("/dev/ttyd1");
|
||||||
|
|
||||||
|
#else
|
||||||
|
setPortName("/dev/ttyS0");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialBase::QextSerialBase(const QString & name)
|
||||||
|
Construct a port and assign it to the device specified by the name parameter.
|
||||||
|
*/
|
||||||
|
QextSerialBase::QextSerialBase(const QString & name)
|
||||||
|
: QIODevice()
|
||||||
|
{
|
||||||
|
setPortName(name);
|
||||||
|
construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialBase::~QextSerialBase()
|
||||||
|
Standard destructor.
|
||||||
|
*/
|
||||||
|
QextSerialBase::~QextSerialBase()
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef QT_THREAD_SUPPORT
|
||||||
|
refCount--;
|
||||||
|
if (mutex && refCount==0) {
|
||||||
|
delete mutex;
|
||||||
|
mutex=NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void QextSerialBase::construct()
|
||||||
|
Common constructor function for setting up default port settings.
|
||||||
|
(115200 Baud, 8N1, Hardware flow control where supported, otherwise no flow control, and 500 ms timeout).
|
||||||
|
*/
|
||||||
|
void QextSerialBase::construct()
|
||||||
|
{
|
||||||
|
Settings.BaudRate=BAUD115200;
|
||||||
|
Settings.DataBits=DATA_8;
|
||||||
|
Settings.Parity=PAR_NONE;
|
||||||
|
Settings.StopBits=STOP_1;
|
||||||
|
Settings.FlowControl=FLOW_HARDWARE;
|
||||||
|
Settings.Timeout_Sec=0;
|
||||||
|
Settings.Timeout_Millisec=500;
|
||||||
|
|
||||||
|
#ifdef QT_THREAD_SUPPORT
|
||||||
|
if (!mutex) {
|
||||||
|
mutex=new QMutex( QMutex::Recursive );
|
||||||
|
}
|
||||||
|
refCount++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setOpenMode(QIODevice::NotOpen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void QextSerialBase::setPortName(const QString & name)
|
||||||
|
Sets the name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0".
|
||||||
|
*/
|
||||||
|
void QextSerialBase::setPortName(const QString & name)
|
||||||
|
{
|
||||||
|
port = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QString QextSerialBase::portName() const
|
||||||
|
Returns the name set by setPortName().
|
||||||
|
*/
|
||||||
|
QString QextSerialBase::portName() const
|
||||||
|
{
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn BaudRateType QextSerialBase::baudRate(void) const
|
||||||
|
Returns the baud rate of the serial port. For a list of possible return values see
|
||||||
|
the definition of the enum BaudRateType.
|
||||||
|
*/
|
||||||
|
BaudRateType QextSerialBase::baudRate(void) const
|
||||||
|
{
|
||||||
|
return Settings.BaudRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn DataBitsType QextSerialBase::dataBits() const
|
||||||
|
Returns the number of data bits used by the port. For a list of possible values returned by
|
||||||
|
this function, see the definition of the enum DataBitsType.
|
||||||
|
*/
|
||||||
|
DataBitsType QextSerialBase::dataBits() const
|
||||||
|
{
|
||||||
|
return Settings.DataBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn ParityType QextSerialBase::parity() const
|
||||||
|
Returns the type of parity used by the port. For a list of possible values returned by
|
||||||
|
this function, see the definition of the enum ParityType.
|
||||||
|
*/
|
||||||
|
ParityType QextSerialBase::parity() const
|
||||||
|
{
|
||||||
|
return Settings.Parity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn StopBitsType QextSerialBase::stopBits() const
|
||||||
|
Returns the number of stop bits used by the port. For a list of possible return values, see
|
||||||
|
the definition of the enum StopBitsType.
|
||||||
|
*/
|
||||||
|
StopBitsType QextSerialBase::stopBits() const
|
||||||
|
{
|
||||||
|
return Settings.StopBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn FlowType QextSerialBase::flowControl() const
|
||||||
|
Returns the type of flow control used by the port. For a list of possible values returned
|
||||||
|
by this function, see the definition of the enum FlowType.
|
||||||
|
*/
|
||||||
|
FlowType QextSerialBase::flowControl() const
|
||||||
|
{
|
||||||
|
return Settings.FlowControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn bool QextSerialBase::isSequential() const
|
||||||
|
Returns true if device is sequential, otherwise returns false. Serial port is sequential device
|
||||||
|
so this function always returns true. Check QIODevice::isSequential() documentation for more
|
||||||
|
information.
|
||||||
|
*/
|
||||||
|
bool QextSerialBase::isSequential() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn bool QextSerialBase::atEnd() const
|
||||||
|
This function will return true if the input buffer is empty (or on error), and false otherwise.
|
||||||
|
Call QextSerialBase::lastError() for error information.
|
||||||
|
*/
|
||||||
|
bool QextSerialBase::atEnd() const
|
||||||
|
{
|
||||||
|
if (size()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qint64 QextSerialBase::readLine(char * data, qint64 maxSize)
|
||||||
|
This function will read a line of buffered input from the port, stopping when either maxSize bytes
|
||||||
|
have been read, the port has no more data available, or a newline is encountered.
|
||||||
|
The value returned is the length of the string that was read.
|
||||||
|
*/
|
||||||
|
qint64 QextSerialBase::readLine(char * data, qint64 maxSize)
|
||||||
|
{
|
||||||
|
qint64 numBytes = bytesAvailable();
|
||||||
|
char* pData = data;
|
||||||
|
|
||||||
|
if (maxSize < 2) //maxSize must be larger than 1
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/*read a byte at a time for MIN(bytesAvail, maxSize - 1) iterations, or until a newline*/
|
||||||
|
while (pData<(data+numBytes) && --maxSize) {
|
||||||
|
readData(pData, 1);
|
||||||
|
if (*pData++ == '\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*pData='\0';
|
||||||
|
|
||||||
|
/*return size of data read*/
|
||||||
|
return (pData-data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn ulong QextSerialBase::lastError() const
|
||||||
|
Returns the code for the last error encountered by the port, or E_NO_ERROR if the last port
|
||||||
|
operation was successful. Possible error codes are:
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
Error Explanation
|
||||||
|
--------------------------- -------------------------------------------------------------
|
||||||
|
E_NO_ERROR No Error has occured
|
||||||
|
E_INVALID_FD Invalid file descriptor (port was not opened correctly)
|
||||||
|
E_NO_MEMORY Unable to allocate memory tables (POSIX)
|
||||||
|
E_CAUGHT_NON_BLOCKED_SIGNAL Caught a non-blocked signal (POSIX)
|
||||||
|
E_PORT_TIMEOUT Operation timed out (POSIX)
|
||||||
|
E_INVALID_DEVICE The file opened by the port is not a character device (POSIX)
|
||||||
|
E_BREAK_CONDITION The port detected a break condition
|
||||||
|
E_FRAMING_ERROR The port detected a framing error
|
||||||
|
(usually caused by incorrect baud rate settings)
|
||||||
|
E_IO_ERROR There was an I/O error while communicating with the port
|
||||||
|
E_BUFFER_OVERRUN Character buffer overrun
|
||||||
|
E_RECEIVE_OVERFLOW Receive buffer overflow
|
||||||
|
E_RECEIVE_PARITY_ERROR The port detected a parity error in the received data
|
||||||
|
E_TRANSMIT_OVERFLOW Transmit buffer overflow
|
||||||
|
E_READ_FAILED General read operation failure
|
||||||
|
E_WRITE_FAILED General write operation failure
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
ulong QextSerialBase::lastError() const
|
||||||
|
{
|
||||||
|
return lastErr;
|
||||||
|
}
|
||||||
196
machine/qextserial/qextserialbase.h
Normal file
196
machine/qextserial/qextserialbase.h
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
|
||||||
|
#ifndef _QEXTSERIALBASE_H_
|
||||||
|
#define _QEXTSERIALBASE_H_
|
||||||
|
|
||||||
|
#include <QIODevice>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#ifdef QT_THREAD_SUPPORT
|
||||||
|
#include <QThread>
|
||||||
|
#include <QMutex>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*if all warning messages are turned off, flag portability warnings to be turned off as well*/
|
||||||
|
#ifdef _TTY_NOWARN_
|
||||||
|
#define _TTY_NOWARN_PORT_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*macros for thread support*/
|
||||||
|
#ifdef QT_THREAD_SUPPORT
|
||||||
|
#define LOCK_MUTEX() mutex->lock()
|
||||||
|
#define UNLOCK_MUTEX() mutex->unlock()
|
||||||
|
#else
|
||||||
|
#define LOCK_MUTEX()
|
||||||
|
#define UNLOCK_MUTEX()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*macros for warning messages*/
|
||||||
|
#ifdef _TTY_NOWARN_PORT_
|
||||||
|
#define TTY_PORTABILITY_WARNING(s)
|
||||||
|
#else
|
||||||
|
#define TTY_PORTABILITY_WARNING(s) qWarning(s)
|
||||||
|
#endif
|
||||||
|
#ifdef _TTY_NOWARN_
|
||||||
|
#define TTY_WARNING(s)
|
||||||
|
#else
|
||||||
|
#define TTY_WARNING(s) qWarning(s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*line status constants*/
|
||||||
|
#define LS_CTS 0x01
|
||||||
|
#define LS_DSR 0x02
|
||||||
|
#define LS_DCD 0x04
|
||||||
|
#define LS_RI 0x08
|
||||||
|
#define LS_RTS 0x10
|
||||||
|
#define LS_DTR 0x20
|
||||||
|
#define LS_ST 0x40
|
||||||
|
#define LS_SR 0x80
|
||||||
|
|
||||||
|
/*error constants*/
|
||||||
|
#define E_NO_ERROR 0
|
||||||
|
#define E_INVALID_FD 1
|
||||||
|
#define E_NO_MEMORY 2
|
||||||
|
#define E_CAUGHT_NON_BLOCKED_SIGNAL 3
|
||||||
|
#define E_PORT_TIMEOUT 4
|
||||||
|
#define E_INVALID_DEVICE 5
|
||||||
|
#define E_BREAK_CONDITION 6
|
||||||
|
#define E_FRAMING_ERROR 7
|
||||||
|
#define E_IO_ERROR 8
|
||||||
|
#define E_BUFFER_OVERRUN 9
|
||||||
|
#define E_RECEIVE_OVERFLOW 10
|
||||||
|
#define E_RECEIVE_PARITY_ERROR 11
|
||||||
|
#define E_TRANSMIT_OVERFLOW 12
|
||||||
|
#define E_READ_FAILED 13
|
||||||
|
#define E_WRITE_FAILED 14
|
||||||
|
|
||||||
|
/*enums for port settings*/
|
||||||
|
enum NamingConvention {
|
||||||
|
WIN_NAMES,
|
||||||
|
IRIX_NAMES,
|
||||||
|
HPUX_NAMES,
|
||||||
|
SUN_NAMES,
|
||||||
|
DIGITAL_NAMES,
|
||||||
|
FREEBSD_NAMES,
|
||||||
|
LINUX_NAMES
|
||||||
|
};
|
||||||
|
|
||||||
|
enum BaudRateType {
|
||||||
|
BAUD50, //POSIX ONLY
|
||||||
|
BAUD75, //POSIX ONLY
|
||||||
|
BAUD110,
|
||||||
|
BAUD134, //POSIX ONLY
|
||||||
|
BAUD150, //POSIX ONLY
|
||||||
|
BAUD200, //POSIX ONLY
|
||||||
|
BAUD300,
|
||||||
|
BAUD600,
|
||||||
|
BAUD1200,
|
||||||
|
BAUD1800, //POSIX ONLY
|
||||||
|
BAUD2400,
|
||||||
|
BAUD4800,
|
||||||
|
BAUD9600,
|
||||||
|
BAUD14400, //WINDOWS ONLY
|
||||||
|
BAUD19200,
|
||||||
|
BAUD38400,
|
||||||
|
BAUD56000, //WINDOWS ONLY
|
||||||
|
BAUD57600,
|
||||||
|
BAUD76800, //POSIX ONLY
|
||||||
|
BAUD115200,
|
||||||
|
BAUD128000, //WINDOWS ONLY
|
||||||
|
BAUD256000 //WINDOWS ONLY
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DataBitsType {
|
||||||
|
DATA_5,
|
||||||
|
DATA_6,
|
||||||
|
DATA_7,
|
||||||
|
DATA_8
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ParityType {
|
||||||
|
PAR_NONE,
|
||||||
|
PAR_ODD,
|
||||||
|
PAR_EVEN,
|
||||||
|
PAR_MARK, //WINDOWS ONLY
|
||||||
|
PAR_SPACE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum StopBitsType {
|
||||||
|
STOP_1,
|
||||||
|
STOP_1_5, //WINDOWS ONLY
|
||||||
|
STOP_2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum FlowType {
|
||||||
|
FLOW_OFF,
|
||||||
|
FLOW_HARDWARE,
|
||||||
|
FLOW_XONXOFF
|
||||||
|
};
|
||||||
|
|
||||||
|
/*structure to contain port settings*/
|
||||||
|
struct PortSettings {
|
||||||
|
BaudRateType BaudRate;
|
||||||
|
DataBitsType DataBits;
|
||||||
|
ParityType Parity;
|
||||||
|
StopBitsType StopBits;
|
||||||
|
FlowType FlowControl;
|
||||||
|
ulong Timeout_Sec;
|
||||||
|
ulong Timeout_Millisec;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QextSerialBase : public QIODevice {
|
||||||
|
public:
|
||||||
|
QextSerialBase();
|
||||||
|
QextSerialBase(const QString & name);
|
||||||
|
virtual ~QextSerialBase();
|
||||||
|
virtual void construct();
|
||||||
|
virtual void setPortName(const QString & name);
|
||||||
|
virtual QString portName() const;
|
||||||
|
|
||||||
|
virtual void setBaudRate(BaudRateType)=0;
|
||||||
|
virtual BaudRateType baudRate() const;
|
||||||
|
virtual void setDataBits(DataBitsType)=0;
|
||||||
|
virtual DataBitsType dataBits() const;
|
||||||
|
virtual void setParity(ParityType)=0;
|
||||||
|
virtual ParityType parity() const;
|
||||||
|
virtual void setStopBits(StopBitsType)=0;
|
||||||
|
virtual StopBitsType stopBits() const;
|
||||||
|
virtual void setFlowControl(FlowType)=0;
|
||||||
|
virtual FlowType flowControl() const;
|
||||||
|
virtual void setTimeout(ulong, ulong)=0;
|
||||||
|
|
||||||
|
virtual bool open(OpenMode mode=0)=0;
|
||||||
|
virtual bool isSequential() const;
|
||||||
|
virtual void close()=0;
|
||||||
|
virtual void flush()=0;
|
||||||
|
|
||||||
|
virtual qint64 size() const=0;
|
||||||
|
virtual qint64 bytesAvailable()=0;
|
||||||
|
virtual bool atEnd() const;
|
||||||
|
|
||||||
|
virtual void ungetChar(char c)=0;
|
||||||
|
virtual qint64 readLine(char * data, qint64 maxSize);
|
||||||
|
|
||||||
|
virtual ulong lastError() const;
|
||||||
|
virtual void translateError(ulong error)=0;
|
||||||
|
|
||||||
|
virtual void setDtr(bool set=true)=0;
|
||||||
|
virtual void setRts(bool set=true)=0;
|
||||||
|
virtual ulong lineStatus()=0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString port;
|
||||||
|
PortSettings Settings;
|
||||||
|
ulong lastErr;
|
||||||
|
|
||||||
|
#ifdef QT_THREAD_SUPPORT
|
||||||
|
static QMutex* mutex;
|
||||||
|
static ulong refCount;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
virtual qint64 readData(char * data, qint64 maxSize)=0;
|
||||||
|
virtual qint64 writeData(const char * data, qint64 maxSize)=0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
98
machine/qextserial/qextserialport.cpp
Normal file
98
machine/qextserial/qextserialport.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
|
||||||
|
/*!
|
||||||
|
\class QextSerialPort
|
||||||
|
\version 1.0.0
|
||||||
|
\author Stefan Sander
|
||||||
|
|
||||||
|
A cross-platform serial port class.
|
||||||
|
This class encapsulates a serial port on both POSIX and Windows systems. The user will be
|
||||||
|
notified of errors and possible portability conflicts at run-time by default - this behavior can
|
||||||
|
be turned off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn
|
||||||
|
off portability warnings) in the project.
|
||||||
|
|
||||||
|
\note
|
||||||
|
On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may
|
||||||
|
select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can
|
||||||
|
make no guarantees as to the quality of POSIX support under NT/2000 however.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "qextserialport.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort::QextSerialPort()
|
||||||
|
Default constructor. Note that the naming convention used by a QextSerialPort constructed with
|
||||||
|
this constructor will be determined by #defined constants, or lack thereof - the default behavior
|
||||||
|
is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are:
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
|
||||||
|
Constant Used By Naming Convention
|
||||||
|
---------- ------------- ------------------------
|
||||||
|
_TTY_WIN_ Windows COM1, COM2
|
||||||
|
_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2
|
||||||
|
_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0
|
||||||
|
_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb
|
||||||
|
_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02
|
||||||
|
_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1
|
||||||
|
_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1
|
||||||
|
<none> Linux /dev/ttyS0, /dev/ttyS1
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
The object will be associated with the first port in the system, e.g. COM1 on Windows systems.
|
||||||
|
See the other constructors if you need to use a port other than the first.
|
||||||
|
*/
|
||||||
|
QextSerialPort::QextSerialPort()
|
||||||
|
: QextBaseType()
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort::QextSerialPort(const QString & name)
|
||||||
|
Constructs a serial port attached to the port specified by name.
|
||||||
|
name is the name of the device, which is windowsystem-specific,
|
||||||
|
e.g."COM1" or "/dev/ttyS0".
|
||||||
|
*/
|
||||||
|
QextSerialPort::QextSerialPort(const QString & name)
|
||||||
|
: QextBaseType(name)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort::QextSerialPort(PortSettings const& settings)
|
||||||
|
Constructs a port with default name and settings specified by the settings parameter.
|
||||||
|
*/
|
||||||
|
QextSerialPort::QextSerialPort(PortSettings const& settings)
|
||||||
|
: QextBaseType(settings)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort::QextSerialPort(const QString & name, PortSettings const& settings)
|
||||||
|
Constructs a port with the name and settings specified.
|
||||||
|
*/
|
||||||
|
QextSerialPort::QextSerialPort(const QString & name, PortSettings const& settings)
|
||||||
|
: QextBaseType(name, settings)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort::QextSerialPort(const QextSerialPort& s)
|
||||||
|
Copy constructor.
|
||||||
|
*/
|
||||||
|
QextSerialPort::QextSerialPort(const QextSerialPort& s)
|
||||||
|
: QextBaseType(s)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort& QextSerialPort::operator=(const QextSerialPort& s)
|
||||||
|
Overrides the = operator.
|
||||||
|
*/
|
||||||
|
QextSerialPort& QextSerialPort::operator=(const QextSerialPort& s)
|
||||||
|
{
|
||||||
|
return (QextSerialPort&)QextBaseType::operator=(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QextSerialPort::~QextSerialPort()
|
||||||
|
Standard destructor.
|
||||||
|
*/
|
||||||
|
QextSerialPort::~QextSerialPort()
|
||||||
|
{}
|
||||||
27
machine/qextserial/qextserialport.h
Normal file
27
machine/qextserial/qextserialport.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
#ifndef _QEXTSERIALPORT_H_
|
||||||
|
#define _QEXTSERIALPORT_H_
|
||||||
|
|
||||||
|
/*POSIX CODE*/
|
||||||
|
#ifdef _TTY_POSIX_
|
||||||
|
#include "posix_qextserialport.h"
|
||||||
|
#define QextBaseType Posix_QextSerialPort
|
||||||
|
|
||||||
|
/*MS WINDOWS CODE*/
|
||||||
|
#else
|
||||||
|
#include "win_qextserialport.h"
|
||||||
|
#define QextBaseType Win_QextSerialPort
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class QextSerialPort: public QextBaseType {
|
||||||
|
public:
|
||||||
|
QextSerialPort();
|
||||||
|
QextSerialPort(const QString & name);
|
||||||
|
QextSerialPort(PortSettings const& s);
|
||||||
|
QextSerialPort(const QString & name, PortSettings const& s);
|
||||||
|
QextSerialPort(const QextSerialPort& s);
|
||||||
|
QextSerialPort& operator=(const QextSerialPort&);
|
||||||
|
virtual ~QextSerialPort();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
880
machine/qextserial/win_qextserialport.cpp
Normal file
880
machine/qextserial/win_qextserialport.cpp
Normal file
@ -0,0 +1,880 @@
|
|||||||
|
/*!
|
||||||
|
\class Win_QextSerialPort
|
||||||
|
\version 1.0.0
|
||||||
|
\author Stefan Sander
|
||||||
|
|
||||||
|
A cross-platform serial port class.
|
||||||
|
This class encapsulates the Windows portion of QextSerialPort. The user will be notified of
|
||||||
|
errors and possible portability conflicts at run-time by default - this behavior can be turned
|
||||||
|
off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off
|
||||||
|
portability warnings) in the project. Note that defining _TTY_NOWARN_ also defines
|
||||||
|
_TTY_NOWARN_PORT_.
|
||||||
|
|
||||||
|
\note
|
||||||
|
On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may
|
||||||
|
select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can
|
||||||
|
make no guarantees as to the quality of POSIX support under NT/2000 however.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "win_qextserialport.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn Win_QextSerialPort::Win_QextSerialPort()
|
||||||
|
Default constructor. Note that the name of the device used by a Win_QextSerialPort constructed
|
||||||
|
with this constructor will be determined by #defined constants, or lack thereof - the default
|
||||||
|
behavior is the same as _TTY_LINUX_. Possible naming conventions and their associated constants
|
||||||
|
are:
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
|
||||||
|
Constant Used By Naming Convention
|
||||||
|
---------- ------------- ------------------------
|
||||||
|
_TTY_WIN_ Windows COM1, COM2
|
||||||
|
_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2
|
||||||
|
_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0
|
||||||
|
_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb
|
||||||
|
_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02
|
||||||
|
_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1
|
||||||
|
_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1
|
||||||
|
<none> Linux /dev/ttyS0, /dev/ttyS1
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
This constructor associates the object with the first port on the system, e.g. COM1 for Windows
|
||||||
|
platforms. See the other constructor if you need a port other than the first.
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort::Win_QextSerialPort():QextSerialBase() {
|
||||||
|
Win_Handle=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort&)
|
||||||
|
Copy constructor.
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort::Win_QextSerialPort(const Win_QextSerialPort& s):QextSerialBase(s.port) {
|
||||||
|
Win_Handle=INVALID_HANDLE_VALUE;
|
||||||
|
setOpenMode(s.openMode());
|
||||||
|
lastErr=s.lastErr;
|
||||||
|
port = s.port;
|
||||||
|
Settings.FlowControl=s.Settings.FlowControl;
|
||||||
|
Settings.Parity=s.Settings.Parity;
|
||||||
|
Settings.DataBits=s.Settings.DataBits;
|
||||||
|
Settings.StopBits=s.Settings.StopBits;
|
||||||
|
Settings.BaudRate=s.Settings.BaudRate;
|
||||||
|
Win_Handle=s.Win_Handle;
|
||||||
|
memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn Win_QextSerialPort::Win_QextSerialPort(const QString & name)
|
||||||
|
Constructs a serial port attached to the port specified by devName.
|
||||||
|
devName is the name of the device, which is windowsystem-specific,
|
||||||
|
e.g."COM2" or "/dev/ttyS0".
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort::Win_QextSerialPort(const QString & name):QextSerialBase(name) {
|
||||||
|
Win_Handle=INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings)
|
||||||
|
Constructs a port with default name and specified settings.
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort::Win_QextSerialPort(const PortSettings& settings) {
|
||||||
|
Win_Handle=INVALID_HANDLE_VALUE;
|
||||||
|
setBaudRate(settings.BaudRate);
|
||||||
|
setDataBits(settings.DataBits);
|
||||||
|
setStopBits(settings.StopBits);
|
||||||
|
setParity(settings.Parity);
|
||||||
|
setFlowControl(settings.FlowControl);
|
||||||
|
setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn Win_QextSerialPort::Win_QextSerialPort(const QString & name, const PortSettings& settings)
|
||||||
|
Constructs a port with specified name and settings.
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort::Win_QextSerialPort(const QString & name, const PortSettings& settings) {
|
||||||
|
Win_Handle=INVALID_HANDLE_VALUE;
|
||||||
|
setPortName(name);
|
||||||
|
setBaudRate(settings.BaudRate);
|
||||||
|
setDataBits(settings.DataBits);
|
||||||
|
setStopBits(settings.StopBits);
|
||||||
|
setParity(settings.Parity);
|
||||||
|
setFlowControl(settings.FlowControl);
|
||||||
|
setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn Win_QextSerialPort::~Win_QextSerialPort()
|
||||||
|
Standard destructor.
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort::~Win_QextSerialPort() {
|
||||||
|
if (isOpen()) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn Win_QextSerialPort& Win_QextSerialPort::operator=(const Win_QextSerialPort& s)
|
||||||
|
overrides the = operator
|
||||||
|
*/
|
||||||
|
Win_QextSerialPort& Win_QextSerialPort::operator=(const Win_QextSerialPort& s) {
|
||||||
|
setOpenMode(s.openMode());
|
||||||
|
lastErr=s.lastErr;
|
||||||
|
port = s.port;
|
||||||
|
Settings.FlowControl=s.Settings.FlowControl;
|
||||||
|
Settings.Parity=s.Settings.Parity;
|
||||||
|
Settings.DataBits=s.Settings.DataBits;
|
||||||
|
Settings.StopBits=s.Settings.StopBits;
|
||||||
|
Settings.BaudRate=s.Settings.BaudRate;
|
||||||
|
Win_Handle=s.Win_Handle;
|
||||||
|
memcpy(&Win_CommConfig, &s.Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
memcpy(&Win_CommTimeouts, &s.Win_CommTimeouts, sizeof(COMMTIMEOUTS));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn bool Win_QextSerialPort::open(OpenMode mode)
|
||||||
|
Opens a serial port. Note that this function does not specify which device to open. If you need
|
||||||
|
to open a device by name, see Win_QextSerialPort::open(const char*). This function has no effect
|
||||||
|
if the port associated with the class is already open. The port is also configured to the current
|
||||||
|
settings, as stored in the Settings structure.
|
||||||
|
*/
|
||||||
|
bool Win_QextSerialPort::open(OpenMode mode) {
|
||||||
|
unsigned long confSize = sizeof(COMMCONFIG);
|
||||||
|
Win_CommConfig.dwSize = confSize;
|
||||||
|
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (mode == QIODevice::NotOpen)
|
||||||
|
return isOpen();
|
||||||
|
if (!isOpen()) {
|
||||||
|
/*open the port*/
|
||||||
|
Win_Handle=CreateFileA(port.toLatin1(), GENERIC_READ|GENERIC_WRITE,
|
||||||
|
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
|
if (Win_Handle!=INVALID_HANDLE_VALUE) {
|
||||||
|
/*set open mode*/
|
||||||
|
QIODevice::open(mode);
|
||||||
|
|
||||||
|
/*configure port settings*/
|
||||||
|
GetCommConfig(Win_Handle, &Win_CommConfig, &confSize);
|
||||||
|
GetCommState(Win_Handle, &(Win_CommConfig.dcb));
|
||||||
|
|
||||||
|
/*set up parameters*/
|
||||||
|
Win_CommConfig.dcb.fBinary=TRUE;
|
||||||
|
Win_CommConfig.dcb.fInX=FALSE;
|
||||||
|
Win_CommConfig.dcb.fOutX=FALSE;
|
||||||
|
Win_CommConfig.dcb.fAbortOnError=FALSE;
|
||||||
|
Win_CommConfig.dcb.fNull=FALSE;
|
||||||
|
setBaudRate(Settings.BaudRate);
|
||||||
|
setDataBits(Settings.DataBits);
|
||||||
|
setStopBits(Settings.StopBits);
|
||||||
|
setParity(Settings.Parity);
|
||||||
|
setFlowControl(Settings.FlowControl);
|
||||||
|
setTimeout(Settings.Timeout_Sec, Settings.Timeout_Millisec);
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
return isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::close()
|
||||||
|
Closes a serial port. This function has no effect if the serial port associated with the class
|
||||||
|
is not currently open.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::close() {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
CloseHandle(Win_Handle);
|
||||||
|
QIODevice::close();
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::flush()
|
||||||
|
Flushes all pending I/O to the serial port. This function has no effect if the serial port
|
||||||
|
associated with the class is not currently open.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::flush() {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (isOpen()) {
|
||||||
|
FlushFileBuffers(Win_Handle);
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qint64 Win_QextSerialPort::size() const
|
||||||
|
This function will return the number of bytes waiting in the receive queue of the serial port.
|
||||||
|
It is included primarily to provide a complete QIODevice interface, and will not record errors
|
||||||
|
in the lastErr member (because it is const). This function is also not thread-safe - in
|
||||||
|
multithreading situations, use Win_QextSerialPort::bytesAvailable() instead.
|
||||||
|
*/
|
||||||
|
qint64 Win_QextSerialPort::size() const {
|
||||||
|
int availBytes;
|
||||||
|
COMSTAT Win_ComStat;
|
||||||
|
DWORD Win_ErrorMask=0;
|
||||||
|
ClearCommError(Win_Handle, &Win_ErrorMask, &Win_ComStat);
|
||||||
|
availBytes = Win_ComStat.cbInQue;
|
||||||
|
return (qint64)availBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qint64 Win_QextSerialPort::bytesAvailable()
|
||||||
|
Returns the number of bytes waiting in the port's receive queue. This function will return 0 if
|
||||||
|
the port is not currently open, or -1 on error. Error information can be retrieved by calling
|
||||||
|
Win_QextSerialPort::getLastError().
|
||||||
|
*/
|
||||||
|
qint64 Win_QextSerialPort::bytesAvailable() {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (isOpen()) {
|
||||||
|
DWORD Errors;
|
||||||
|
COMSTAT Status;
|
||||||
|
bool success=ClearCommError(Win_Handle, &Errors, &Status);
|
||||||
|
translateError(Errors);
|
||||||
|
if (success) {
|
||||||
|
lastErr=E_NO_ERROR;
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
return Status.cbInQue + QIODevice::bytesAvailable();
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
return (unsigned int)-1;
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::translateError(ulong error)
|
||||||
|
Translates a system-specific error code to a QextSerialPort error code. Used internally.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::translateError(ulong error) {
|
||||||
|
if (error&CE_BREAK) {
|
||||||
|
lastErr=E_BREAK_CONDITION;
|
||||||
|
}
|
||||||
|
else if (error&CE_FRAME) {
|
||||||
|
lastErr=E_FRAMING_ERROR;
|
||||||
|
}
|
||||||
|
else if (error&CE_IOE) {
|
||||||
|
lastErr=E_IO_ERROR;
|
||||||
|
}
|
||||||
|
else if (error&CE_MODE) {
|
||||||
|
lastErr=E_INVALID_FD;
|
||||||
|
}
|
||||||
|
else if (error&CE_OVERRUN) {
|
||||||
|
lastErr=E_BUFFER_OVERRUN;
|
||||||
|
}
|
||||||
|
else if (error&CE_RXPARITY) {
|
||||||
|
lastErr=E_RECEIVE_PARITY_ERROR;
|
||||||
|
}
|
||||||
|
else if (error&CE_RXOVER) {
|
||||||
|
lastErr=E_RECEIVE_OVERFLOW;
|
||||||
|
}
|
||||||
|
else if (error&CE_TXFULL) {
|
||||||
|
lastErr=E_TRANSMIT_OVERFLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qint64 Win_QextSerialPort::readData(char *data, qint64 maxSize)
|
||||||
|
Reads a block of data from the serial port. This function will read at most maxlen bytes from
|
||||||
|
the serial port and place them in the buffer pointed to by data. Return value is the number of
|
||||||
|
bytes actually read, or -1 on error.
|
||||||
|
|
||||||
|
\warning before calling this function ensure that serial port associated with this class
|
||||||
|
is currently open (use isOpen() function to check if port is open).
|
||||||
|
*/
|
||||||
|
qint64 Win_QextSerialPort::readData(char *data, qint64 maxSize)
|
||||||
|
{
|
||||||
|
LOCK_MUTEX();
|
||||||
|
int retVal=0;
|
||||||
|
COMSTAT Win_ComStat;
|
||||||
|
DWORD Win_BytesRead=0;
|
||||||
|
DWORD Win_ErrorMask=0;
|
||||||
|
ClearCommError(Win_Handle, &Win_ErrorMask, &Win_ComStat);
|
||||||
|
if (Win_ComStat.cbInQue &&
|
||||||
|
(!ReadFile(Win_Handle, (void*)data, (DWORD)maxSize, &Win_BytesRead, NULL)
|
||||||
|
|| Win_BytesRead==0)) {
|
||||||
|
lastErr=E_READ_FAILED;
|
||||||
|
retVal=-1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
retVal=((int)Win_BytesRead);
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn qint64 Win_QextSerialPort::writeData(const char *data, qint64 maxSize)
|
||||||
|
Writes a block of data to the serial port. This function will write len bytes
|
||||||
|
from the buffer pointed to by data to the serial port. Return value is the number
|
||||||
|
of bytes actually written, or -1 on error.
|
||||||
|
|
||||||
|
\warning before calling this function ensure that serial port associated with this class
|
||||||
|
is currently open (use isOpen() function to check if port is open).
|
||||||
|
*/
|
||||||
|
qint64 Win_QextSerialPort::writeData(const char *data, qint64 maxSize)
|
||||||
|
{
|
||||||
|
LOCK_MUTEX();
|
||||||
|
int retVal=0;
|
||||||
|
DWORD Win_BytesWritten;
|
||||||
|
if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, &Win_BytesWritten, NULL)) {
|
||||||
|
lastErr=E_WRITE_FAILED;
|
||||||
|
retVal=-1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
retVal=((int)Win_BytesWritten);
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
|
||||||
|
flush();
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::ungetChar(char c)
|
||||||
|
This function is included to implement the full QIODevice interface, and currently has no
|
||||||
|
purpose within this class. This function is meaningless on an unbuffered device and currently
|
||||||
|
only prints a warning message to that effect.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::ungetChar(char c) {
|
||||||
|
if (c == c)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*meaningless on unbuffered sequential device - return error and print a warning*/
|
||||||
|
TTY_WARNING("Win_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setFlowControl(FlowType flow)
|
||||||
|
Sets the flow control used by the port. Possible values of flow are:
|
||||||
|
\verbatim
|
||||||
|
FLOW_OFF No flow control
|
||||||
|
FLOW_HARDWARE Hardware (RTS/CTS) flow control
|
||||||
|
FLOW_XONXOFF Software (XON/XOFF) flow control
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setFlowControl(FlowType flow) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (Settings.FlowControl!=flow) {
|
||||||
|
Settings.FlowControl=flow;
|
||||||
|
}
|
||||||
|
if (isOpen()) {
|
||||||
|
switch(flow) {
|
||||||
|
|
||||||
|
/*no flow control*/
|
||||||
|
case FLOW_OFF:
|
||||||
|
Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
|
||||||
|
Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
|
||||||
|
Win_CommConfig.dcb.fInX=FALSE;
|
||||||
|
Win_CommConfig.dcb.fOutX=FALSE;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*software (XON/XOFF) flow control*/
|
||||||
|
case FLOW_XONXOFF:
|
||||||
|
Win_CommConfig.dcb.fOutxCtsFlow=FALSE;
|
||||||
|
Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_DISABLE;
|
||||||
|
Win_CommConfig.dcb.fInX=TRUE;
|
||||||
|
Win_CommConfig.dcb.fOutX=TRUE;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FLOW_HARDWARE:
|
||||||
|
Win_CommConfig.dcb.fOutxCtsFlow=TRUE;
|
||||||
|
Win_CommConfig.dcb.fRtsControl=RTS_CONTROL_HANDSHAKE;
|
||||||
|
Win_CommConfig.dcb.fInX=FALSE;
|
||||||
|
Win_CommConfig.dcb.fOutX=FALSE;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setParity(ParityType parity)
|
||||||
|
Sets the parity associated with the serial port. The possible values of parity are:
|
||||||
|
\verbatim
|
||||||
|
PAR_SPACE Space Parity
|
||||||
|
PAR_MARK Mark Parity
|
||||||
|
PAR_NONE No Parity
|
||||||
|
PAR_EVEN Even Parity
|
||||||
|
PAR_ODD Odd Parity
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setParity(ParityType parity) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (Settings.Parity!=parity) {
|
||||||
|
Settings.Parity=parity;
|
||||||
|
}
|
||||||
|
if (isOpen()) {
|
||||||
|
Win_CommConfig.dcb.Parity=(unsigned char)parity;
|
||||||
|
switch (parity) {
|
||||||
|
|
||||||
|
/*space parity*/
|
||||||
|
case PAR_SPACE:
|
||||||
|
if (Settings.DataBits==DATA_8) {
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: Space parity with 8 data bits is not supported by POSIX systems.");
|
||||||
|
}
|
||||||
|
Win_CommConfig.dcb.fParity=TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*mark parity - WINDOWS ONLY*/
|
||||||
|
case PAR_MARK:
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: Mark parity is not supported by POSIX systems");
|
||||||
|
Win_CommConfig.dcb.fParity=TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*no parity*/
|
||||||
|
case PAR_NONE:
|
||||||
|
Win_CommConfig.dcb.fParity=FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*even parity*/
|
||||||
|
case PAR_EVEN:
|
||||||
|
Win_CommConfig.dcb.fParity=TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*odd parity*/
|
||||||
|
case PAR_ODD:
|
||||||
|
Win_CommConfig.dcb.fParity=TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setDataBits(DataBitsType dataBits)
|
||||||
|
Sets the number of data bits used by the serial port. Possible values of dataBits are:
|
||||||
|
\verbatim
|
||||||
|
DATA_5 5 data bits
|
||||||
|
DATA_6 6 data bits
|
||||||
|
DATA_7 7 data bits
|
||||||
|
DATA_8 8 data bits
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
\note
|
||||||
|
This function is subject to the following restrictions:
|
||||||
|
\par
|
||||||
|
5 data bits cannot be used with 2 stop bits.
|
||||||
|
\par
|
||||||
|
1.5 stop bits can only be used with 5 data bits.
|
||||||
|
\par
|
||||||
|
8 data bits cannot be used with space parity on POSIX systems.
|
||||||
|
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setDataBits(DataBitsType dataBits) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (Settings.DataBits!=dataBits) {
|
||||||
|
if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) ||
|
||||||
|
(Settings.StopBits==STOP_1_5 && dataBits!=DATA_5)) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Settings.DataBits=dataBits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isOpen()) {
|
||||||
|
switch(dataBits) {
|
||||||
|
|
||||||
|
/*5 data bits*/
|
||||||
|
case DATA_5:
|
||||||
|
if (Settings.StopBits==STOP_2) {
|
||||||
|
TTY_WARNING("Win_QextSerialPort: 5 Data bits cannot be used with 2 stop bits.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Win_CommConfig.dcb.ByteSize=5;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*6 data bits*/
|
||||||
|
case DATA_6:
|
||||||
|
if (Settings.StopBits==STOP_1_5) {
|
||||||
|
TTY_WARNING("Win_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Win_CommConfig.dcb.ByteSize=6;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*7 data bits*/
|
||||||
|
case DATA_7:
|
||||||
|
if (Settings.StopBits==STOP_1_5) {
|
||||||
|
TTY_WARNING("Win_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Win_CommConfig.dcb.ByteSize=7;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*8 data bits*/
|
||||||
|
case DATA_8:
|
||||||
|
if (Settings.StopBits==STOP_1_5) {
|
||||||
|
TTY_WARNING("Win_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Win_CommConfig.dcb.ByteSize=8;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setStopBits(StopBitsType stopBits)
|
||||||
|
Sets the number of stop bits used by the serial port. Possible values of stopBits are:
|
||||||
|
\verbatim
|
||||||
|
STOP_1 1 stop bit
|
||||||
|
STOP_1_5 1.5 stop bits
|
||||||
|
STOP_2 2 stop bits
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
\note
|
||||||
|
This function is subject to the following restrictions:
|
||||||
|
\par
|
||||||
|
2 stop bits cannot be used with 5 data bits.
|
||||||
|
\par
|
||||||
|
1.5 stop bits cannot be used with 6 or more data bits.
|
||||||
|
\par
|
||||||
|
POSIX does not support 1.5 stop bits.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setStopBits(StopBitsType stopBits) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (Settings.StopBits!=stopBits) {
|
||||||
|
if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) ||
|
||||||
|
(stopBits==STOP_1_5 && Settings.DataBits!=DATA_5)) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Settings.StopBits=stopBits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isOpen()) {
|
||||||
|
switch (stopBits) {
|
||||||
|
|
||||||
|
/*one stop bit*/
|
||||||
|
case STOP_1:
|
||||||
|
Win_CommConfig.dcb.StopBits=ONESTOPBIT;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*1.5 stop bits*/
|
||||||
|
case STOP_1_5:
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: 1.5 stop bit operation is not supported by POSIX.");
|
||||||
|
if (Settings.DataBits!=DATA_5) {
|
||||||
|
TTY_WARNING("Win_QextSerialPort: 1.5 stop bits can only be used with 5 data bits");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Win_CommConfig.dcb.StopBits=ONE5STOPBITS;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*two stop bits*/
|
||||||
|
case STOP_2:
|
||||||
|
if (Settings.DataBits==DATA_5) {
|
||||||
|
TTY_WARNING("Win_QextSerialPort: 2 stop bits cannot be used with 5 data bits");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Win_CommConfig.dcb.StopBits=TWOSTOPBITS;
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setBaudRate(BaudRateType baudRate)
|
||||||
|
Sets the baud rate of the serial port. Note that not all rates are applicable on
|
||||||
|
all platforms. The following table shows translations of the various baud rate
|
||||||
|
constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an *
|
||||||
|
are speeds that are usable on both Windows and POSIX.
|
||||||
|
\verbatim
|
||||||
|
|
||||||
|
RATE Windows Speed POSIX Speed
|
||||||
|
----------- ------------- -----------
|
||||||
|
BAUD50 110 50
|
||||||
|
BAUD75 110 75
|
||||||
|
*BAUD110 110 110
|
||||||
|
BAUD134 110 134.5
|
||||||
|
BAUD150 110 150
|
||||||
|
BAUD200 110 200
|
||||||
|
*BAUD300 300 300
|
||||||
|
*BAUD600 600 600
|
||||||
|
*BAUD1200 1200 1200
|
||||||
|
BAUD1800 1200 1800
|
||||||
|
*BAUD2400 2400 2400
|
||||||
|
*BAUD4800 4800 4800
|
||||||
|
*BAUD9600 9600 9600
|
||||||
|
BAUD14400 14400 9600
|
||||||
|
*BAUD19200 19200 19200
|
||||||
|
*BAUD38400 38400 38400
|
||||||
|
BAUD56000 56000 38400
|
||||||
|
*BAUD57600 57600 57600
|
||||||
|
BAUD76800 57600 76800
|
||||||
|
*BAUD115200 115200 115200
|
||||||
|
BAUD128000 128000 115200
|
||||||
|
BAUD256000 256000 115200
|
||||||
|
\endverbatim
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setBaudRate(BaudRateType baudRate) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (Settings.BaudRate!=baudRate) {
|
||||||
|
switch (baudRate) {
|
||||||
|
case BAUD50:
|
||||||
|
case BAUD75:
|
||||||
|
case BAUD134:
|
||||||
|
case BAUD150:
|
||||||
|
case BAUD200:
|
||||||
|
Settings.BaudRate=BAUD110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BAUD1800:
|
||||||
|
Settings.BaudRate=BAUD1200;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BAUD76800:
|
||||||
|
Settings.BaudRate=BAUD57600;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Settings.BaudRate=baudRate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isOpen()) {
|
||||||
|
switch (baudRate) {
|
||||||
|
|
||||||
|
/*50 baud*/
|
||||||
|
case BAUD50:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 50 baud operation. Switching to 110 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*75 baud*/
|
||||||
|
case BAUD75:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 75 baud operation. Switching to 110 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*110 baud*/
|
||||||
|
case BAUD110:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*134.5 baud*/
|
||||||
|
case BAUD134:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 134.5 baud operation. Switching to 110 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*150 baud*/
|
||||||
|
case BAUD150:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 150 baud operation. Switching to 110 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*200 baud*/
|
||||||
|
case BAUD200:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 200 baud operation. Switching to 110 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_110;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*300 baud*/
|
||||||
|
case BAUD300:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_300;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*600 baud*/
|
||||||
|
case BAUD600:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_600;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*1200 baud*/
|
||||||
|
case BAUD1200:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_1200;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*1800 baud*/
|
||||||
|
case BAUD1800:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 1800 baud operation. Switching to 1200 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_1200;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*2400 baud*/
|
||||||
|
case BAUD2400:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_2400;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*4800 baud*/
|
||||||
|
case BAUD4800:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_4800;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*9600 baud*/
|
||||||
|
case BAUD9600:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_9600;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*14400 baud*/
|
||||||
|
case BAUD14400:
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 14400 baud operation.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_14400;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*19200 baud*/
|
||||||
|
case BAUD19200:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_19200;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*38400 baud*/
|
||||||
|
case BAUD38400:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_38400;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*56000 baud*/
|
||||||
|
case BAUD56000:
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 56000 baud operation.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_56000;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*57600 baud*/
|
||||||
|
case BAUD57600:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_57600;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*76800 baud*/
|
||||||
|
case BAUD76800:
|
||||||
|
TTY_WARNING("Win_QextSerialPort: Windows does not support 76800 baud operation. Switching to 57600 baud.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_57600;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*115200 baud*/
|
||||||
|
case BAUD115200:
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_115200;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*128000 baud*/
|
||||||
|
case BAUD128000:
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 128000 baud operation.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_128000;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/*256000 baud*/
|
||||||
|
case BAUD256000:
|
||||||
|
TTY_PORTABILITY_WARNING("Win_QextSerialPort Portability Warning: POSIX does not support 256000 baud operation.");
|
||||||
|
Win_CommConfig.dcb.BaudRate=CBR_256000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SetCommConfig(Win_Handle, &Win_CommConfig, sizeof(COMMCONFIG));
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setDtr(bool set)
|
||||||
|
Sets DTR line to the requested state (high by default). This function will have no effect if
|
||||||
|
the port associated with the class is not currently open.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setDtr(bool set) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (isOpen()) {
|
||||||
|
if (set) {
|
||||||
|
EscapeCommFunction(Win_Handle, SETDTR);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EscapeCommFunction(Win_Handle, CLRDTR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setRts(bool set)
|
||||||
|
Sets RTS line to the requested state (high by default). This function will have no effect if
|
||||||
|
the port associated with the class is not currently open.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setRts(bool set) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (isOpen()) {
|
||||||
|
if (set) {
|
||||||
|
EscapeCommFunction(Win_Handle, SETRTS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EscapeCommFunction(Win_Handle, CLRRTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn ulong Win_QextSerialPort::lineStatus(void)
|
||||||
|
returns the line status as stored by the port function. This function will retrieve the states
|
||||||
|
of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines
|
||||||
|
can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned
|
||||||
|
long with specific bits indicating which lines are high. The following constants should be used
|
||||||
|
to examine the states of individual lines:
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
Mask Line
|
||||||
|
------ ----
|
||||||
|
LS_CTS CTS
|
||||||
|
LS_DSR DSR
|
||||||
|
LS_DCD DCD
|
||||||
|
LS_RI RI
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
This function will return 0 if the port associated with the class is not currently open.
|
||||||
|
*/
|
||||||
|
ulong Win_QextSerialPort::lineStatus(void) {
|
||||||
|
unsigned long Status=0, Temp=0;
|
||||||
|
LOCK_MUTEX();
|
||||||
|
if (isOpen()) {
|
||||||
|
GetCommModemStatus(Win_Handle, &Temp);
|
||||||
|
if (Temp&MS_CTS_ON) {
|
||||||
|
Status|=LS_CTS;
|
||||||
|
}
|
||||||
|
if (Temp&MS_DSR_ON) {
|
||||||
|
Status|=LS_DSR;
|
||||||
|
}
|
||||||
|
if (Temp&MS_RING_ON) {
|
||||||
|
Status|=LS_RI;
|
||||||
|
}
|
||||||
|
if (Temp&MS_RLSD_ON) {
|
||||||
|
Status|=LS_DCD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn void Win_QextSerialPort::setTimeout(ulong sec, ulong millisec);
|
||||||
|
Sets the read and write timeouts for the port to sec seconds and millisec milliseconds.
|
||||||
|
*/
|
||||||
|
void Win_QextSerialPort::setTimeout(ulong sec, ulong millisec) {
|
||||||
|
LOCK_MUTEX();
|
||||||
|
Settings.Timeout_Sec=sec;
|
||||||
|
Settings.Timeout_Millisec=millisec;
|
||||||
|
if(isOpen()) {
|
||||||
|
Win_CommTimeouts.ReadIntervalTimeout = sec*1000+millisec;
|
||||||
|
Win_CommTimeouts.ReadTotalTimeoutMultiplier = sec*1000+millisec;
|
||||||
|
Win_CommTimeouts.ReadTotalTimeoutConstant = 0;
|
||||||
|
Win_CommTimeouts.WriteTotalTimeoutMultiplier = sec*1000+millisec;
|
||||||
|
Win_CommTimeouts.WriteTotalTimeoutConstant = 0;
|
||||||
|
SetCommTimeouts(Win_Handle, &Win_CommTimeouts);
|
||||||
|
}
|
||||||
|
UNLOCK_MUTEX();
|
||||||
|
}
|
||||||
48
machine/qextserial/win_qextserialport.h
Normal file
48
machine/qextserial/win_qextserialport.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef _WIN_QEXTSERIALPORT_H_
|
||||||
|
#define _WIN_QEXTSERIALPORT_H_
|
||||||
|
|
||||||
|
#include "qextserialbase.h"
|
||||||
|
|
||||||
|
/*if all warning messages are turned off, flag portability warnings to be turned off as well*/
|
||||||
|
#ifdef _TTY_NOWARN_
|
||||||
|
#define _TTY_NOWARN_PORT_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
class Win_QextSerialPort:public QextSerialBase {
|
||||||
|
public:
|
||||||
|
Win_QextSerialPort();
|
||||||
|
Win_QextSerialPort(Win_QextSerialPort const& s);
|
||||||
|
Win_QextSerialPort(const QString & name);
|
||||||
|
Win_QextSerialPort(const PortSettings& settings);
|
||||||
|
Win_QextSerialPort(const QString & name, const PortSettings& settings);
|
||||||
|
Win_QextSerialPort& operator=(const Win_QextSerialPort& s);
|
||||||
|
virtual ~Win_QextSerialPort();
|
||||||
|
virtual bool open(OpenMode mode=0);
|
||||||
|
virtual void close();
|
||||||
|
virtual void flush();
|
||||||
|
virtual qint64 size() const;
|
||||||
|
virtual void ungetChar(char c);
|
||||||
|
virtual void setFlowControl(FlowType);
|
||||||
|
virtual void setParity(ParityType);
|
||||||
|
virtual void setDataBits(DataBitsType);
|
||||||
|
virtual void setStopBits(StopBitsType);
|
||||||
|
virtual void setBaudRate(BaudRateType);
|
||||||
|
virtual void setDtr(bool set=true);
|
||||||
|
virtual void setRts(bool set=true);
|
||||||
|
virtual ulong lineStatus(void);
|
||||||
|
virtual qint64 bytesAvailable();
|
||||||
|
virtual void translateError(ulong);
|
||||||
|
virtual void setTimeout(ulong, ulong);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HANDLE Win_Handle;
|
||||||
|
COMMCONFIG Win_CommConfig;
|
||||||
|
COMMTIMEOUTS Win_CommTimeouts;
|
||||||
|
|
||||||
|
virtual qint64 readData(char *data, qint64 maxSize);
|
||||||
|
virtual qint64 writeData(const char *data, qint64 maxSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
501
machine/tcpclient.cpp
Normal file
501
machine/tcpclient.cpp
Normal file
@ -0,0 +1,501 @@
|
|||||||
|
#include "tcpclient.h"
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QAbstractSocket>
|
||||||
|
|
||||||
|
TcpClient::TcpClient(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_pClientSocket(NULL),
|
||||||
|
m_pConnectCheckTimer(NULL),
|
||||||
|
m_connected(0),
|
||||||
|
m_pConnectDetectThread(NULL),
|
||||||
|
m_pConnectDetect(NULL),
|
||||||
|
m_detect(0),
|
||||||
|
m_localip(DEF_LOCAL_IP),
|
||||||
|
m_localport(DEF_LOCAL_PORT),
|
||||||
|
m_serverip(DEF_SERVER_IP),
|
||||||
|
m_serverport(DEF_SERVER_PORT)
|
||||||
|
{
|
||||||
|
m_pClientSocket = new QBindTcpSocket(this);
|
||||||
|
m_pClientSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
|
||||||
|
connect(m_pClientSocket, SIGNAL(readyRead()), this, SLOT(receiveServerData()));
|
||||||
|
connect(m_pClientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
|
||||||
|
this, SLOT(displaySocketError(QAbstractSocket::SocketError)));
|
||||||
|
// connect(m_pClientSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(netStateChanged(QAbstractSocket::SocketState)));
|
||||||
|
|
||||||
|
m_pConnectCheckTimer = new QTimer(this);
|
||||||
|
connect(m_pConnectCheckTimer, SIGNAL(timeout()), this, SLOT(connectCheck()));
|
||||||
|
|
||||||
|
|
||||||
|
m_pConnectDetectThread = new QThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpClient::~TcpClient()
|
||||||
|
{
|
||||||
|
m_pConnectCheckTimer->stop();
|
||||||
|
delete m_pConnectCheckTimer;
|
||||||
|
|
||||||
|
m_pClientSocket->disconnectFromHost();
|
||||||
|
m_pClientSocket->waitForDisconnected();
|
||||||
|
m_pClientSocket->close();
|
||||||
|
delete m_pClientSocket;
|
||||||
|
|
||||||
|
if (m_connected != 0)
|
||||||
|
{
|
||||||
|
m_pConnectDetectThread->quit();
|
||||||
|
m_pConnectDetectThread->wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete m_pConnectDetectThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::setConfigFileName(QString configfilename)
|
||||||
|
{
|
||||||
|
m_configFileName = configfilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::connectToServer()
|
||||||
|
{
|
||||||
|
if (m_pClientSocket == NULL)
|
||||||
|
{
|
||||||
|
qDebug() << "m_pClientSocket not alloc";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_connected == 0)
|
||||||
|
{
|
||||||
|
loadIpAndPort();
|
||||||
|
if (m_pConnectDetect == NULL)
|
||||||
|
{
|
||||||
|
m_pConnectDetect = new TcpConnectDetect;
|
||||||
|
}
|
||||||
|
qDebug() << "ConnectToServer";
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
|
||||||
|
m_pConnectDetect->setIpAndPort(m_localip, m_localport, m_serverip, m_serverport);
|
||||||
|
|
||||||
|
m_pConnectDetect->moveToThread(m_pConnectDetectThread);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(siDetectHost()), m_pConnectDetect, SLOT(connectDetect()), Qt::QueuedConnection);
|
||||||
|
connect(m_pConnectDetect, SIGNAL(siConnectSta(int)), this, SLOT(detectStatus(int)), Qt::QueuedConnection);
|
||||||
|
|
||||||
|
// 20191226由于检测线程会造成网络重连,所以将检测线程注释 lft
|
||||||
|
/*
|
||||||
|
connect(m_pConnectDetectThread, SIGNAL(started()), m_pConnectDetect, SLOT(detectStart()) );
|
||||||
|
connect(m_pConnectDetectThread, SIGNAL(finished()), m_pConnectDetect, SLOT(deleteLater()) ); // 退出删除对象
|
||||||
|
|
||||||
|
m_pConnectDetectThread->start(); // 启动线程
|
||||||
|
*/
|
||||||
|
m_pConnectCheckTimer->start(1000);
|
||||||
|
m_connected = 1;
|
||||||
|
m_detect = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::disConnectFromServer()
|
||||||
|
{
|
||||||
|
if (m_connected != 0)
|
||||||
|
{
|
||||||
|
m_pConnectCheckTimer->stop();
|
||||||
|
|
||||||
|
if (m_pClientSocket != NULL)
|
||||||
|
{
|
||||||
|
m_pClientSocket->disconnectFromHost();
|
||||||
|
m_pClientSocket->waitForDisconnected();
|
||||||
|
m_pClientSocket->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pConnectDetectThread->quit();
|
||||||
|
m_pConnectDetectThread->wait();
|
||||||
|
|
||||||
|
m_connected = 0;
|
||||||
|
m_detect = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::loadIpAndPort()
|
||||||
|
{
|
||||||
|
if (!m_configFileName.isEmpty())
|
||||||
|
{
|
||||||
|
// 机器的IP和端口 和 连接机器的本地IP和端口
|
||||||
|
QSettings configIni(m_configFileName, QSettings::IniFormat);
|
||||||
|
QString serverip, localip;
|
||||||
|
quint16 serverport, localport;
|
||||||
|
|
||||||
|
serverip = configIni.value("server/ip", QVariant("192.168.16.253")).toString();
|
||||||
|
serverport = configIni.value("server/port", QVariant(5000)).toInt();
|
||||||
|
localip = configIni.value("local/ip", QVariant("192.168.16.41")).toString();
|
||||||
|
localport = configIni.value("local/port", 5001).toInt();
|
||||||
|
|
||||||
|
// 回写参数
|
||||||
|
configIni.setValue("server/ip", serverip);
|
||||||
|
configIni.setValue("server/port", serverport);
|
||||||
|
configIni.setValue("local/ip", localip);
|
||||||
|
configIni.setValue("local/port", localport);
|
||||||
|
|
||||||
|
m_localip = localip;
|
||||||
|
m_localport = localport;
|
||||||
|
m_serverip = serverip;
|
||||||
|
m_serverport = serverport;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送数据的槽
|
||||||
|
void TcpClient::slotSendData(QByteArray dat)
|
||||||
|
{
|
||||||
|
if (m_pClientSocket != NULL)
|
||||||
|
{
|
||||||
|
m_pClientSocket->write(dat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自动检测连接
|
||||||
|
void TcpClient::connectCheck()
|
||||||
|
{
|
||||||
|
if (m_pClientSocket == NULL)
|
||||||
|
{
|
||||||
|
qDebug() << "Socket is not alloced";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// qDebug() << "check client connect";
|
||||||
|
if (m_connected == 1)
|
||||||
|
{
|
||||||
|
if (m_localip.isEmpty() == false)
|
||||||
|
{
|
||||||
|
m_pClientSocket->bindAddrAndPort(m_localip, m_localport);
|
||||||
|
}
|
||||||
|
m_pClientSocket->abort();
|
||||||
|
m_pClientSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
||||||
|
m_pClientSocket->connectToHost(m_serverip, m_serverport);
|
||||||
|
int rslt = m_pClientSocket->waitForConnected(2000);
|
||||||
|
if (rslt == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
qDebug("bind connect and waitForConnected 2000, rslt=%d", rslt);
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
*/
|
||||||
|
m_connected = 2;
|
||||||
|
}
|
||||||
|
else if (m_connected != 0)
|
||||||
|
{
|
||||||
|
switch(m_pClientSocket->state())
|
||||||
|
{
|
||||||
|
case QAbstractSocket::ConnectedState:
|
||||||
|
{
|
||||||
|
if (m_connected != 3)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
qDebug() << "net State is Connected";
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
*/
|
||||||
|
m_connected = 3; // 检测连接状态
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::ConnectingState:
|
||||||
|
{
|
||||||
|
if (m_connected != 2)
|
||||||
|
{
|
||||||
|
qDebug() << "net State is Connecting";
|
||||||
|
// qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
}
|
||||||
|
m_connected = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::UnconnectedState:
|
||||||
|
{
|
||||||
|
if (m_connected != 1)
|
||||||
|
{
|
||||||
|
// qDebug() << "net State is unconnected";
|
||||||
|
// qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
}
|
||||||
|
m_connected = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
QAbstractSocket::HostLookupState
|
||||||
|
QAbstractSocket::BoundState
|
||||||
|
QAbstractSocket::ListeningState
|
||||||
|
QAbstractSocket::ClosingState
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
qDebug("net State is %d\r\n", m_pClientSocket->state());
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
}
|
||||||
|
m_connected = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_connected == 3) // 已连接
|
||||||
|
{
|
||||||
|
if (m_detect == 1)
|
||||||
|
{
|
||||||
|
// qDebug() << "Machine " << QThread::currentThread();
|
||||||
|
m_detect = 0;
|
||||||
|
emit(siDetectHost());
|
||||||
|
// qDebug() << "after send SiDetectHost ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit (siConnectSta(m_connected)); // 网络连接信号
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::detectStatus(int sta)
|
||||||
|
{
|
||||||
|
// qDebug("host detect sta=%d", sta);
|
||||||
|
|
||||||
|
m_detect = 1;
|
||||||
|
if (sta == 1) // 网络已断开
|
||||||
|
{
|
||||||
|
qDebug("disconnect ClientSocket by detect");
|
||||||
|
m_pClientSocket->disconnectFromHost();
|
||||||
|
// m_pClientSocket->waitForDisconnected();
|
||||||
|
m_pClientSocket->close();
|
||||||
|
m_connected = 1;
|
||||||
|
}
|
||||||
|
else if (sta == 2) // 网络连接还在
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::receiveServerData()
|
||||||
|
{
|
||||||
|
if (m_pClientSocket != NULL)
|
||||||
|
{
|
||||||
|
QByteArray tmpDat;
|
||||||
|
tmpDat = m_pClientSocket->readAll(); // 读取
|
||||||
|
// qDebug("ReceiveServerData, size = %d", tmpDat.size());
|
||||||
|
// PrintAsHex(&tmpDat);
|
||||||
|
|
||||||
|
emit(siReceiveData(tmpDat)); // 发送收到数据信号
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::displaySocketError(QAbstractSocket::SocketError err)
|
||||||
|
{
|
||||||
|
QString errinfo;
|
||||||
|
|
||||||
|
errinfo.sprintf("Err: code=%d, errorString=", err);
|
||||||
|
errinfo += m_pClientSocket->errorString();
|
||||||
|
|
||||||
|
// qDebug() << errinfo;
|
||||||
|
|
||||||
|
emit(siConnectErr(errinfo)); // 网络错误信息
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::netStateChanged(QAbstractSocket::SocketState sta)
|
||||||
|
{
|
||||||
|
switch (sta)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
case UnconnectedState:
|
||||||
|
case HostLookupState:
|
||||||
|
case ConnectingState:
|
||||||
|
case ConnectedState:
|
||||||
|
case BoundState:
|
||||||
|
case ListeningState:
|
||||||
|
case ClosingStat:
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void TcpClient::hostFound()
|
||||||
|
{
|
||||||
|
qDebug("found host");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if(0)
|
||||||
|
//-------------------------------------------------------
|
||||||
|
TcpConnectDetect::TcpConnectDetect(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_pDetectSocket(NULL),
|
||||||
|
m_localip(DEF_LOCAL_IP),
|
||||||
|
m_localport(DEF_LOCAL_PORT),
|
||||||
|
m_serverip(DEF_SERVER_IP),
|
||||||
|
m_serverport(DEF_SERVER_PORT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpConnectDetect::~TcpConnectDetect()
|
||||||
|
{
|
||||||
|
if (m_pDetectSocket == NULL)
|
||||||
|
{
|
||||||
|
m_pDetectSocket->disconnectFromHost();
|
||||||
|
m_pDetectSocket->waitForDisconnected();
|
||||||
|
m_pDetectSocket->close();
|
||||||
|
delete m_pDetectSocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpConnectDetect::detectStart()
|
||||||
|
{
|
||||||
|
qDebug("TcpConnectDetect start");
|
||||||
|
if (m_pDetectSocket == NULL)
|
||||||
|
{
|
||||||
|
m_pDetectSocket = new QBindTcpSocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int TcpConnectDetect::connectDetect()
|
||||||
|
{
|
||||||
|
int connectsta = 0;
|
||||||
|
int rslt;
|
||||||
|
|
||||||
|
// qDebug() << "TcpConnectDetect " << QThread::currentThread();
|
||||||
|
|
||||||
|
if (m_pDetectSocket == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (m_localip.isEmpty() == false)
|
||||||
|
{
|
||||||
|
m_pDetectSocket->bindAddrAndPort(m_localip, m_localport);
|
||||||
|
}
|
||||||
|
m_pDetectSocket->abort();
|
||||||
|
m_pDetectSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
||||||
|
m_pDetectSocket->connectToHost(m_serverip, m_serverport);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
rslt = m_pDetectSocket->waitForConnected(4000); // 等待连接
|
||||||
|
|
||||||
|
qDebug("bind Detect connect rslt=%d", rslt);
|
||||||
|
qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
qDebug() << "serverip=" << m_serverip << "serverport=" << m_serverport;
|
||||||
|
|
||||||
|
switch(m_pDetectSocket->state())
|
||||||
|
{
|
||||||
|
case QAbstractSocket::ConnectedState:
|
||||||
|
{
|
||||||
|
// 如果连接上,说明 m_pClientSocket 连接已经无效, 需要断开重新连接
|
||||||
|
// 先断开测试连接
|
||||||
|
m_pDetectSocket->disconnectFromHost();
|
||||||
|
m_pDetectSocket->waitForDisconnected();
|
||||||
|
connectsta = 1;
|
||||||
|
// 发送断开主连接的信号
|
||||||
|
qDebug() << "detect is Connected, disconnect all";
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::UnconnectedState:
|
||||||
|
{
|
||||||
|
// qDebug() << "detect is Unconnected err=" << m_pDetectSocket->error() << ", info:" << m_pDetectSocket->errorString();
|
||||||
|
|
||||||
|
switch (m_pDetectSocket->error())
|
||||||
|
{
|
||||||
|
case QAbstractSocket::SocketTimeoutError: // 连接超时,说明已经断开
|
||||||
|
case QAbstractSocket::NetworkError: // 网络错误, 主机不可连接, 可能已经断开
|
||||||
|
{
|
||||||
|
qDebug() << "detect is timout, disconnect all";
|
||||||
|
connectsta = 1;
|
||||||
|
// 发送断开主连接的信号
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::ConnectionRefusedError: // 拒绝连接, 说明连接还在
|
||||||
|
{
|
||||||
|
connectsta = 2;
|
||||||
|
// qDebug() << "Connection Refused, old connect is alive";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
case QAbstractSocket::RemoteHostClosedError:
|
||||||
|
case QAbstractSocket::HostNotFoundError:
|
||||||
|
case QAbstractSocket::SocketAccessError:
|
||||||
|
case QAbstractSocket::SocketResourceError:
|
||||||
|
case QAbstractSocket::SocketTimeoutError:
|
||||||
|
case QAbstractSocket::DatagramTooLargeError:
|
||||||
|
case QAbstractSocket::AddressInUseError:
|
||||||
|
case QAbstractSocket::SocketAddressNotAvailableError:
|
||||||
|
case QAbstractSocket::UnsupportedSocketOperationError:
|
||||||
|
case QAbstractSocket::UnfinishedSocketOperationError:
|
||||||
|
case QAbstractSocket::ProxyAuthenticationRequiredError:
|
||||||
|
case QAbstractSocket::SslHandshakeFailedError:
|
||||||
|
case QAbstractSocket::ProxyConnectionRefusedError:
|
||||||
|
case QAbstractSocket::ProxyConnectionClosedError:
|
||||||
|
case QAbstractSocket::ProxyConnectionTimeoutError:
|
||||||
|
case QAbstractSocket::ProxyNotFoundError:
|
||||||
|
case QAbstractSocket::ProxyProtocolError:
|
||||||
|
case QAbstractSocket::UnknownSocketError:
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// 继续检测
|
||||||
|
connectsta = 2;
|
||||||
|
qDebug() << " retry";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} // 错误处理结束
|
||||||
|
}
|
||||||
|
case QAbstractSocket::ConnectingState:
|
||||||
|
{
|
||||||
|
// qDebug() << "detect is Connecting";
|
||||||
|
// qDebug() << "localip=" << m_localip << "localport=" << m_localport;
|
||||||
|
// 继续等待
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QAbstractSocket::HostLookupState:
|
||||||
|
case QAbstractSocket::BoundState:
|
||||||
|
case QAbstractSocket::ListeningState:
|
||||||
|
case QAbstractSocket::ClosingState:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// 继续等待
|
||||||
|
qDebug("detect sta is %d\r\n", m_pDetectSocket->state());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connectsta != 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}while(1);
|
||||||
|
|
||||||
|
|
||||||
|
m_pDetectSocket->close();
|
||||||
|
|
||||||
|
// 发送本次测试连接的状态信号
|
||||||
|
emit(siConnectSta(connectsta));
|
||||||
|
return connectsta;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpConnectDetect::setIpAndPort(QString localip, quint16 localport, QString serverip, quint16 serverport)
|
||||||
|
{
|
||||||
|
m_localip = localip;
|
||||||
|
m_localport = localport;
|
||||||
|
m_serverip = serverip;
|
||||||
|
m_serverport = serverport;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
102
machine/tcpclient.h
Normal file
102
machine/tcpclient.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#ifndef TCPCLIENT_H
|
||||||
|
#define TCPCLIENT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QHostAddress>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QUdpSocket>
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
#include "qbindtcpsocket.h"
|
||||||
|
|
||||||
|
class ConnectDetectThread;
|
||||||
|
|
||||||
|
|
||||||
|
class TcpClient : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TcpClient(QObject *parent = NULL);
|
||||||
|
virtual ~TcpClient();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setConfigFileName(QString configfilename);
|
||||||
|
signals:
|
||||||
|
void siConnectSta(int sta); // 网络连接信号
|
||||||
|
void siConnectErr(QString errinfo); // 网络错误信息
|
||||||
|
void siReceiveData(QByteArray dat); // 收到数据包信号
|
||||||
|
signals:
|
||||||
|
void siDetectHost(void);
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void slotSendData(QByteArray dat); // 发送数据的槽
|
||||||
|
void connectToServer();//连接到服务器
|
||||||
|
void disConnectFromServer();
|
||||||
|
void detectStatus(int);
|
||||||
|
public:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void connectCheck();
|
||||||
|
void receiveServerData();
|
||||||
|
void displaySocketError(QAbstractSocket::SocketError err);
|
||||||
|
void netStateChanged(QAbstractSocket::SocketState sta);
|
||||||
|
void hostFound();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadIpAndPort();
|
||||||
|
private:
|
||||||
|
QBindTcpSocket * m_pClientSocket;//客户端
|
||||||
|
|
||||||
|
QTimer * m_pConnectCheckTimer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int m_connected; // 连接状态; 0, 初始化; 1, 未连接; 2, 连接中; 3, 已连接
|
||||||
|
|
||||||
|
private:
|
||||||
|
QThread * m_pConnectDetectThread;
|
||||||
|
TcpConnectDetect * m_pConnectDetect;
|
||||||
|
int m_detect; // 连接测试状态
|
||||||
|
private:
|
||||||
|
QString m_configFileName;
|
||||||
|
private:
|
||||||
|
QString m_localip;
|
||||||
|
quint16 m_localport;
|
||||||
|
QString m_serverip;
|
||||||
|
quint16 m_serverport;
|
||||||
|
};
|
||||||
|
|
||||||
|
#if(0)
|
||||||
|
class TcpConnectDetect : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TcpConnectDetect(QObject *parent = NULL);
|
||||||
|
virtual ~TcpConnectDetect();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void siConnectSta(int sta); // 网络连接信号
|
||||||
|
public:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void detectStart();
|
||||||
|
int connectDetect();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QBindTcpSocket * m_pDetectSocket;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setIpAndPort(QString localip, quint16 localport, QString serverip, quint16 serverport);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_localip;
|
||||||
|
quint16 m_localport;
|
||||||
|
QString m_serverip;
|
||||||
|
quint16 m_serverport;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TCPCLIENT_H
|
||||||
285
main.cpp
Normal file
285
main.cpp
Normal file
@ -0,0 +1,285 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
#include <QTranslator>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QSplashScreen>
|
||||||
|
#include <QResource>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSharedMemory>
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
|
||||||
|
#define _IN_MAIN_CPP
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "mctype/patternsingleboard/mainUI/mainwidget.h"
|
||||||
|
|
||||||
|
QString switchLanguage(int language,QDir appPath)
|
||||||
|
{
|
||||||
|
QString sourcePath,targetPath;
|
||||||
|
targetPath = appPath.path() + appPath.separator() + "language.qm";
|
||||||
|
switch (language)
|
||||||
|
{
|
||||||
|
case chinese://中文
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "chinese.qm";
|
||||||
|
break;
|
||||||
|
case english://英文
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "english.qm";
|
||||||
|
break;
|
||||||
|
case ukrainian://乌克兰文
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "ukrainian.qm";
|
||||||
|
break;
|
||||||
|
case french://法文
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "france.qm";
|
||||||
|
break;
|
||||||
|
case russian://俄语
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "russian.qm";
|
||||||
|
break;
|
||||||
|
case german://德文
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "german.qm";
|
||||||
|
break;
|
||||||
|
default://中文
|
||||||
|
sourcePath = appPath.path() + appPath.separator() + "chinese.qm";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile::remove(targetPath);
|
||||||
|
QFile::copy(sourcePath,targetPath);
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
system("sync");
|
||||||
|
#endif
|
||||||
|
return targetPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMcMainWindow(QApplication &app, QSplashScreen *splash, s16 HMIDecrypt, s16 connectMode)
|
||||||
|
{
|
||||||
|
//创建主窗口
|
||||||
|
MainWidget mainwindow;
|
||||||
|
//初始化主窗口
|
||||||
|
mainwindow.initMcTypeWindows();
|
||||||
|
mainwindow.initAllWindows(HMIDecrypt,connectMode);
|
||||||
|
|
||||||
|
mainwindow.show();//显示窗口
|
||||||
|
//mainwindow.setWindowIcon(QIcon(":/images/1024x600/rp.png"));
|
||||||
|
splash->finish(NULL);
|
||||||
|
app.exec();//开始执行应用程序
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);//此处必须用QApplication,否则QSplashScreen不能使用
|
||||||
|
QSharedMemory shared_memory;
|
||||||
|
shared_memory.setKey(QString("main_window"));//设置固定共享内存段的key值
|
||||||
|
if(shared_memory.attach()) //尝试将进程附加到该共享内存段,避免windows下重开程序
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//支持中文编码
|
||||||
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
|
//文件路径
|
||||||
|
QDir apppath(qApp->applicationDirPath());
|
||||||
|
qDebug()<<"apppath:"<<apppath.path();
|
||||||
|
//配置文件路径
|
||||||
|
QString configfile;
|
||||||
|
configfile = apppath.path() + apppath.separator() + "config.ini";
|
||||||
|
|
||||||
|
//读入配置
|
||||||
|
g_pSettings = new Settings();
|
||||||
|
g_pSettings->loadSetting(configfile);
|
||||||
|
QFile iniFile(configfile);
|
||||||
|
int language = 0;
|
||||||
|
s16 connectMode = 0;
|
||||||
|
s16 gatewayConnectMode = 0;
|
||||||
|
|
||||||
|
if(!iniFile.exists())//配置文件不存在
|
||||||
|
{
|
||||||
|
QMap<QString, QVariant> settings;
|
||||||
|
|
||||||
|
settings["Pattern/name"] = "";
|
||||||
|
settings["HMI/resolution"] = resolution1006;
|
||||||
|
settings["HMI/theme"] = theme1;
|
||||||
|
settings["HMI/language"] = chinese;
|
||||||
|
settings["HMI/FrontSize"] = FONTSIZE;
|
||||||
|
settings["HMI/machineType"] = MACHINE_HIGHSPEEDSINGLEQUI;
|
||||||
|
settings["HMI/productType"] = PRODUCT_NULL;
|
||||||
|
settings["HMI/debugMode"] = nodebugMode;//界面调试模式
|
||||||
|
settings["HMI/waterMark"] = 1;//0:主背景图不带水印 1:主背景图带水印
|
||||||
|
settings["HMI/paraSort"] = 0;//0:参数不分类显示 1:参数分类显示
|
||||||
|
|
||||||
|
settings["HMI/connectMode"] = 0;//连接方式(通讯方式,网口或串口)
|
||||||
|
settings["HMI/passwordOne"] = g_passwordOne;
|
||||||
|
settings["IOT/gatewayConnectMode"] = 0;//网关连接方式(连接方式,网口或串口)
|
||||||
|
settings["IOT/rackNumber"] = 0;//机架号
|
||||||
|
settings["DateTime/second"] = 0;
|
||||||
|
settings["HeadBreakLineNum"] = 0;//写入机头断线次数
|
||||||
|
settings["HMI/splitStep"] = 1;//是否分割针步
|
||||||
|
settings["MaxSpeedOfMainSewWork"] = 0;//主轴缝纫工作最高转速
|
||||||
|
|
||||||
|
g_pSettings->writeToIniFile(settings);
|
||||||
|
|
||||||
|
g_emResolut = resolution1006;
|
||||||
|
g_emTheme = theme1;
|
||||||
|
language = chinese;
|
||||||
|
g_emDebugMode = nodebugMode;
|
||||||
|
g_emMacType = MACHINE_HIGHSPEEDSINGLEQUI;
|
||||||
|
g_emProductType = PRODUCT_NULL;
|
||||||
|
g_passwordOne = PASSWORD_ONE;
|
||||||
|
g_fontsize = FONTSIZE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int frontSize = g_pSettings->readFromIniFile("HMI/FrontSize").toInt();
|
||||||
|
if((8 > frontSize) || (frontSize > 18))
|
||||||
|
{
|
||||||
|
g_pSettings->writeOneToIniFile("HMI/FrontSize",FONTSIZE);
|
||||||
|
g_fontsize = FONTSIZE;
|
||||||
|
}
|
||||||
|
g_fontsize = g_pSettings->readFromIniFile("HMI/FrontSize").toInt();
|
||||||
|
|
||||||
|
g_emResolut = (Resolution)(g_pSettings->readFromIniFile("HMI/resolution").toInt());
|
||||||
|
|
||||||
|
g_emTheme = (Theme)(g_pSettings->readFromIniFile("HMI/theme").toInt());
|
||||||
|
//这个情况是,存在配置文件的时候,很可能是只有DateTime/second,读不到主题,就是0(图片加载不出来),二级密码也会没有
|
||||||
|
|
||||||
|
//为了防止配置文件里没有debugMode时升级黑屏,因为界面调试模式是后来新加的,之前版本的配置文件里没有,兼容之前的版本 -rq
|
||||||
|
QString debugModeStr = "HMI/debugMode";
|
||||||
|
if(g_pSettings->ifKeyExists(debugModeStr) == true)
|
||||||
|
{
|
||||||
|
g_emDebugMode =(DebugMode)(g_pSettings->readFromIniFile("HMI/debugMode").toInt());//如果存在配置文件,并且有这个key就读配置文件里的调试模式的值
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_pSettings->writeOneToIniFile("HMI/debugMode",nodebugMode);//界面调试模式
|
||||||
|
g_emDebugMode = nodebugMode;
|
||||||
|
}
|
||||||
|
language = g_pSettings->readFromIniFile("HMI/language").toInt();
|
||||||
|
g_emDebugMode =(DebugMode)(g_pSettings->readFromIniFile("HMI/debugMode").toInt());//如果存在配置文件,就读配置文件里的调试模式的值
|
||||||
|
g_emMacType = (MachineType)(g_pSettings->readFromIniFile("HMI/machineType").toInt());
|
||||||
|
g_emProductType = (ProductType)(g_pSettings->readFromIniFile("HMI/productType").toInt());
|
||||||
|
connectMode = g_pSettings->readFromIniFile("HMI/connectMode").toInt();
|
||||||
|
g_passwordOne = g_pSettings->readFromIniFile("HMI/passwordOne").toString();
|
||||||
|
if(g_passwordOne.isEmpty())
|
||||||
|
g_passwordOne = PASSWORD_ONE;
|
||||||
|
gatewayConnectMode = g_pSettings->readFromIniFile("IOT/gatewayConnectMode").toInt();
|
||||||
|
|
||||||
|
g_xCorrectionFactor = 1.0;
|
||||||
|
g_yCorrectionFactor = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//自动获取屏幕分辨率
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QDesktopWidget * desktop = QApplication::desktop();
|
||||||
|
QRect screenRect = desktop->screenGeometry();
|
||||||
|
int width = screenRect.width();
|
||||||
|
int height = screenRect.height();
|
||||||
|
if(width == 1920 && height == 1080)
|
||||||
|
{
|
||||||
|
g_emResolut = resolution1910;
|
||||||
|
}
|
||||||
|
else if(width == 1024 && height == 600)
|
||||||
|
{
|
||||||
|
g_emResolut = resolution1006;
|
||||||
|
}
|
||||||
|
else if(width == 800 && height == 480)
|
||||||
|
{
|
||||||
|
g_emResolut = resolution0804;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//多语言翻译
|
||||||
|
QString languageFile = switchLanguage(language,apppath);
|
||||||
|
qDebug()<<"languageFile:"<<languageFile;
|
||||||
|
QTranslator translator;
|
||||||
|
translator.load(languageFile);
|
||||||
|
app.installTranslator(&translator);
|
||||||
|
|
||||||
|
//资源文件
|
||||||
|
QString resourcefile = apppath.path() + apppath.separator() + "nxcui.rcc";
|
||||||
|
QResource::registerResource(resourcefile);
|
||||||
|
|
||||||
|
//启动画面
|
||||||
|
QSplashScreen *splash = new QSplashScreen;
|
||||||
|
if(g_emResolut == resolution1006)
|
||||||
|
{
|
||||||
|
splash->setPixmap(QPixmap(":/images/startlogo1006.png"));
|
||||||
|
}
|
||||||
|
else if(g_emResolut == resolution0804)
|
||||||
|
{
|
||||||
|
splash->setPixmap(QPixmap(":/images/startlogo0804.png"));
|
||||||
|
}
|
||||||
|
else if(g_emResolut == resolution1910)
|
||||||
|
{
|
||||||
|
splash->setPixmap(QPixmap(":/images/startlogo1910.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QFont font;
|
||||||
|
font.setPixelSize(20);
|
||||||
|
splash->setFont(font);
|
||||||
|
//splash->move(0,0);
|
||||||
|
splash->move(0+g_mainWidgetPos.x(),0+g_mainWidgetPos.y());
|
||||||
|
int waterMark = g_pSettings->readFromIniFile("HMI/waterMark").toInt();//是否带水印
|
||||||
|
if(waterMark==1)//带logo
|
||||||
|
{
|
||||||
|
splash->show();//显示启动画面
|
||||||
|
}
|
||||||
|
|
||||||
|
//检测界面解密的配置文件是否存在
|
||||||
|
//界面解密配置文件路径
|
||||||
|
s16 HMIDecrypt = 1;//1代表已授权解密过,0代表未授权解密过
|
||||||
|
QString HMIDecryptConfigfile;
|
||||||
|
HMIDecryptConfigfile = apppath.path() + apppath.separator() + "HMIDecryptConfig.ini";
|
||||||
|
QFile HMIDecryptIniFile(HMIDecryptConfigfile);
|
||||||
|
if(!HMIDecryptIniFile.exists())//不存在界面解密的文件(已发机器),可与主板建立连接
|
||||||
|
{
|
||||||
|
HMIDecrypt = 1;
|
||||||
|
}
|
||||||
|
else//存在界面解密的文件,判断是否解密过来决定是否与主板建立连接
|
||||||
|
{
|
||||||
|
QSettings iniSetting(HMIDecryptConfigfile, QSettings::IniFormat);
|
||||||
|
HMIDecrypt = iniSetting.value("HMIDecrypt/ifdecrypt").toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pMachine = NULL;
|
||||||
|
QString mcConfigfile;
|
||||||
|
mcConfigfile = apppath.path() + apppath.separator() + "mcconfig.ini";
|
||||||
|
|
||||||
|
g_pMachine = new Machine(); //创建下位机通讯
|
||||||
|
g_pMachine->initConnectMode(connectMode);//初始化通讯连接方式
|
||||||
|
g_pMachine->setComportName(""); //名字为空
|
||||||
|
g_pMachine->setConfigFileName(mcConfigfile);//配置文件
|
||||||
|
if(HMIDecrypt != 0)
|
||||||
|
{
|
||||||
|
g_pMachine->startCommunication();//启动线程
|
||||||
|
}
|
||||||
|
|
||||||
|
//物联网客户端与mqtt网关服务器建立连接
|
||||||
|
g_pLotMachine = NULL;
|
||||||
|
QString lotConfigfile;
|
||||||
|
lotConfigfile = apppath.path() + apppath.separator() + "lotconfig.ini";
|
||||||
|
g_pLotMachine = new LotMachine(); //创建网关通讯
|
||||||
|
g_pLotMachine->initConnectMode(gatewayConnectMode);//初始化通讯连接方式
|
||||||
|
g_pLotMachine->setComportName("");
|
||||||
|
g_pLotMachine->setConfigFileName(lotConfigfile);
|
||||||
|
g_pLotMachine->startCommunication();
|
||||||
|
|
||||||
|
g_pCurEmbData = new EmbData();
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
//win下防止多个程序打开
|
||||||
|
if(shared_memory.create(1)) //创建1byte的共享内存段
|
||||||
|
{
|
||||||
|
setMcMainWindow(app,splash,HMIDecrypt,connectMode);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
setMcMainWindow(app,splash,HMIDecrypt,connectMode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
delete splash;
|
||||||
|
delete g_pSettings;
|
||||||
|
delete g_pMachine;
|
||||||
|
delete g_pCurEmbData;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user