1、增加数据分割功能(完成)
2、更换dxf库(进行中)
This commit is contained in:
华海艳 2024-03-15 16:49:50 +08:00
parent 3ce55cebbd
commit 9f74511e69
69 changed files with 13825 additions and 314 deletions

View File

@ -60,16 +60,14 @@ SOURCES += \
machine/comm/crc16.cpp \
machine/comm/crc32.cpp \
printinfodialog.cpp \
datafile/dxf/dxfhelper.cpp \
datafile/dxf/dxfreader.cpp \
datafile/dxf/dxflib/dl_dxf.cpp \
datafile/dxf/dxflib/dl_writer_ascii.cpp \
addmachinedialog.cpp \
machine/bmp/bwbmp.cpp \
machine/bmp/creatprintbmp.cpp \
machine/tcp/qbindtcpsocket.cpp \
machine/tcp/tcpclient.cpp \
datafile/view/drawdata.cpp
datafile/view/drawdata.cpp \
datafile/dxf/dxfhelper.cpp \
datafile/dxf/dxfreader.cpp
FORMS += \
mainwindow.ui \
@ -117,29 +115,73 @@ HEADERS += \
machine/comm/crc16.h \
machine/comm/crc32.h \
printinfodialog.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 \
addmachinedialog.h \
machine/bmp/bwbmp.h \
machine/bmp/creatprintbmp.h \
machine/tcp/qbindtcpsocket.h \
machine/tcp/tcpclient.h \
machine/printinfo/mcfiles.h \
datafile/view/drawdata.h
datafile/view/drawdata.h \
datafile/dxf/dxfhelper.h \
datafile/dxf/dxfreader.h \
datafile/dxf/dxflib/DxfMath.h \
datafile/dxf/dxflib/GroupCode.h \
datafile/dxf/dxflib/PDSMath.h \
datafile/dxf/dxflib/ReadASTM.h \
datafile/dxf/dxflib/ReadAutoCAD.h \
datafile/dxf/dxflib/ReadDxfFile.h \
datafile/dxf/dxflib/ReadTIIP.h \
datafile/dxf/dxflib/WriteASTM.h \
datafile/dxf/dxflib/WriteAutoCAD.h \
datafile/dxf/dxflib/WriteDxfFile.h \
datafile/dxf/dxflib/DxfMath.h \
datafile/dxf/dxflib/GroupCode.h \
datafile/dxf/dxflib/PDSMath.h \
datafile/dxf/dxflib/ReadASTM.h \
datafile/dxf/dxflib/ReadAutoCAD.h \
datafile/dxf/dxflib/ReadDxfFile.h \
datafile/dxf/dxflib/ReadTIIP.h \
datafile/dxf/dxflib/WriteASTM.h \
datafile/dxf/dxflib/WriteAutoCAD.h \
datafile/dxf/dxflib/WriteDxfFile.h \
datafile/dxf/dxflib/PDSMath/3BSpline.h \
datafile/dxf/dxflib/PDSMath/PDSAlgorithm.h \
datafile/dxf/dxflib/PDSMath/PDSBezier.h \
datafile/dxf/dxflib/PDSMath/PDSFormula.h \
datafile/dxf/dxflib/PDSMath/PDSLocate.h \
datafile/dxf/dxflib/PDSMath/PDSMath.h \
datafile/dxf/dxflib/PDSMath/PDSMathExtern.h \
datafile/dxf/dxflib/PDSMath/PDSMathGlobal.h \
datafile/dxf/dxflib/PDSMath/PDSNurbs.h \
datafile/dxf/dxflib/PDSMath/PDSReadWriteFile.h \
datafile/dxf/dxflib/PDSMath/PDSUID.h \
datafile/dxf/dxflib/PDSMath/PDSUnit.h \
datafile/dxf/dxflib/PDSMath/Point3D.h \
datafile/dxf/dxflib/PDSMath/StdAfx.h \
datafile/dxf/dxflib/PDSMath/UnzipFile.h \
datafile/dxf/dxflib/PDSMath/UnzipFile_Memory.h \
datafile/dxf/dxflib/PDSMath/zconf.h \
datafile/dxf/dxflib/PDSMath/ZipCompress.h \
datafile/dxf/dxflib/PDSMath/ZipException.h \
datafile/dxf/dxflib/PDSMath/ZipFile.h \
datafile/dxf/dxflib/PDSMath/ZipFile_Memory.h \
datafile/dxf/dxflib/PDSMath/ZipStruct.h \
datafile/dxf/dxflib/PDSMath/zlib.h \
datafile/dxf/dxflib/PDSMath/ZUBaseFile.h \
datafile/dxf/dxflib/PDSMath/ZUBaseFile_Memory.h
TRANSLATIONS += chinese.ts\
english.ts
RESOURCES += \
res.qrc
!debug: {
LIBS += $$PWD/../../datafile/dxf/dxflib/ReadDXFFileLib_R
LIBS += $$PWD/../../datafile/dxf/dxflib/RPAPI_R
LIBS += $$PWD/../../datafile/dxf/dxflib/WriteDXFFileLib_R
} else {
LIBS += $$PWD/../../datafile/dxf/dxflib/ReadDXFFileLib_D
LIBS += $$PWD/../../datafile/dxf/dxflib/RPAPI_D
LIBS += $$PWD/../../datafile/dxf/dxflib/WriteDXFFileLib_D
}

View File

@ -0,0 +1,215 @@
#if !defined(DxfMath_h)
#define DxfMath_h
#include <math.h>
#include <afxwin.h>
#include <afxtempl.h>
#include "GroupCode.h"
#define CONST_PI 3.14159265359
//样点旋转
//输入参数:
// (dX,dY)被旋转点,(dXO,dYO)旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦
//输出参数:
// (dXNew,dYNew)旋转后的值
void PointRotate_D(double dX,double dY,double dXO,double dYO,double dSinBeta,double dCosBeta,double& dXNew,double& dYNew);
//样点旋转
//输入参数:
// pdPoint被旋转点,pdPointO旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦
//输出参数:
// pdPoint旋转后的值
void PointRotate(CPointData &pdPoint,CPointData pdPointO,double dSinBeta,double dCosBeta);
//求两点距离
//返回值
// dLength 两点间距离的双精度值
double TwoPointLength(CPointData pdPoint1,CPointData pdPoint2);
//求矢量pdPointS1→pdPointE1逆时针方向旋转到矢量pdPointS2→pdPointE2的方向所经过的夹角,在[0,2pi)之间
//输入参数:
// pdPointS1,pdPointE1 矢量pdPointS1→pdPointE1
// pdPointS2,pdPointE2 矢量pdPointS2→pdPointE2
//返回值:
// 夹角
double angle_2(CPointData pdPointS1,CPointData pdPointE1,CPointData pdPointS2,CPointData pdPointE2);
//得到pdPoint1pdPoint2的中间点 pdMiddle
void GetMiddlePoint(CPointData pdPoint1, CPointData pdPoint2, CPointData &pdMiddle);
//获得沿直线 pdPoint0, pdPoint1方向到pdPoint0距离为 dDistance 的点
CPointData GetPointOnLine(CPointData pdPoint0, CPointData pdPoint1, double dLength);
int IntTrans(double x);
//计算一条链表的有向面积
//输入:
// listPoint 点链.
//输出:
// 无.
//返回值:
// 面积.
//说明:
// 此面积为有向面积.
// 在世界坐标系下.
double Area(CPointDataList& listPoint);
//计算point在线段ptS→ptE上的参数值
//输入:
// point 点.
// (ptS,ptE) 线段.
//输出:
// 无.
//返回值:
// [0,1]点在线段上,并且就在两点之间;否则,点在线段的延长线上.
//说明:
// 线段的两个端点不应该相等.
// 这三个点应共线,此函数不作判断.
double PointToParam(CPointData& point, CPointData& ptS, CPointData& ptE);
//求点一点到一条线段的垂足.
//输入:
// 线段(ptS,ptE)
// ptRes 点.
//输出:
// ptDes 垂足点.
//返回值:
// 无.
//说明:
// 输入线段的两个端点不应该相同,否则输出点和输入点赋值相同.
// 垂足未必落在线段上.
void GetVerticalPoint(CPointData& ptS, CPointData& ptE, CPointData& ptRes, CPointData& ptDes);
//判断两条线段是否平行
//输入:
// 线段(ptS0,ptE0),(ptS1,ptE1)
//输出:
// 无.
//返回值:
// =TRUE,两线平行;=FALSE,两线不平行.
//说明:
// 每条线段的两端点都不应相同,如果发生些种情况,则认为两线平行.
BOOL IsParallel(CPointData& ptS0, CPointData& ptE0, CPointData& ptS1, CPointData& ptE1);
//计算一个点到一条链表的距离.
//输入:
// point 点.
// listPoint 链表.
//输出:
// 无.
//返回值:
// 距离.点到各线段距离中的最小值.
//说明:
double DistanceFromPointToList(CPointData& point, CPointDataList& listPoint);
//计算圆弧控制点
//输入参数:
// dAngleS 圆弧开始角度 参考水平
// dAngleE 圆弧结束角度 参考水平
// PDCenter 圆心
// dRadius 半径
//输出参数:
// listCtrlPoint 圆的控制点
void CalculateArcPoint(double dAngleS, double dAngleE, CPointData PDCenter, double dRadius, CPointDataList &listCtrlPoint);
//计算圆控制点
//输入参数:
// PDCenter 圆心
// dRadius 半径
//输出参数:
// listCtrlPoint 圆的控制点
void CalculateCirclePoint(CPointData PDCenter, double dRadius, CPointDataList &listCtrlPoint);
//计算椭圆控制点
//输入参数:
// dAngleS dAngleE 开始结束角度 如果dAngleS到dAngleE为360度表示为整个椭圆 dAngleE > dAngleS 顺序针,反之为逆时针
// PDCenter 椭圆中心点
// PDAxis 椭圆长轴的一个端点(坐标相对中心点)
// dProportion //长轴和短轴比例
//输出参数:
// listCtrlPoint 控制点
//返回值:
// 只有在输出参数个数大于2有效=true 整个椭圆;=false 部分椭圆
BOOL CaculateEllipse(double dAngleS, double dAngleE, CPointData PDCenter, CPointData PDAxis, double dProportion, CPointDataList &listCtrlPoint);
//删除重合曲线
//[输入][输出] listAllCurveInfor 曲线, 要求曲线中没有闭合曲线
void DeleteSameCurve(CCurveNotchInforList &listAllCurveInfor);
//删除与CurveInfor重合(完全重合)的曲线
//[输入][输出] CurveInfor 曲线
//[输入][输出] listAllCurveInfor 所有曲线,输出参数:重合的曲线被删除
void FindSameCurveAndDelete(CCurveNotchInfor &CurveInfor, CCurveNotchInforList &listAllCurveInfor);
//在给定的曲线中寻找所有闭合曲线
//[输入][输出] listAllCurveInfor 所有曲线 输出时没有listAllCloseCurve中的曲线
//[输出] listAllCloseCurve 所有的闭合曲线
//[输入] iFileType 文件类型 =0 AutoCAD文件 =1 AAMA/ASTM/TIIP
void GetAllCloseCurve(CCurveNotchInforList &listAllCurveInfor, CCloseCurveInforList &listAllCloseCurve, int iFileType);
//在给定的曲线中寻找闭合点链
//[输入][输出] listAllCurveInfor 所有曲线 输出时没有CloseCurveInfo中的曲线
//[输出] CloseCurveInfo 闭合点链 返回值为true有效
//[输出] CurveInforFirst 内有找到闭合曲线的开始点链返回值为false有效
//返回值:
// =true 找到;=false没有找到
BOOL GetCloseCurve(CCurveNotchInforList &listAllCurveInfor, CCloseCurveInfor &CloseCurveInfo, CCurveNotchInfor &CurveInforFirst);
//找控制点最多的点链
//[输入][输出] listAllCurveInfor 所有点链 输出中不包含MaxCtrlCurveInfor
//[输出] MaxCtrlCurveInfor 控制点最多的点链
void FindCtrlMaxCount(CCurveNotchInforList &listAllCurveInfor, CCurveNotchInfor &MaxCtrlCurveInfor);
//寻找开始曲线,得到最左边的曲线
void FindStartCurve(CCurveNotchInforList &listAllCurveInfor, CCurveNotchInfor &StartCtrlCurveInfor);
//寻找对接的下一段
//[输入][输出] listAllCurveInfor 所有点链 输出中不包含CurveInforNext
//[输入] listRefCurveInfor 参考点链,已经形成的链
//[输入] JointPointData 对接点
//[输入] dSamePointDistance 两个相同点最大距离
//[输出] CurveInforNext 找到的对接线
//[输出] bHead=true表示CurveInforNext的头点与给定点相同
//返回值:
// =true 找到;=false 没有找到
BOOL FindJointPoint(CCurveNotchInforList &listAllCurveInfor, CCurveNotchInforList &listRefCurveInfor, CPointData JointPointData, double dSamePointDistance, CCurveNotchInfor &CurveInforNext, BOOL &bHead);
//20200226 判断CurveInfor与listRefCurveInfor是否重叠
//输入参数:
// listRefCurveInfor 参考线段
// CurveInfor 判断线段
//返回值:
// =true 重叠; =false 不重叠
BOOL OverlapList(CCurveNotchInforList &listRefCurveInfor, CCurveNotchInfor CurveInfor);
//在给定的点链中寻找头/尾点与给定点相同的曲线
//[输入][输出] listAllCurveInfor 所有点链 输出中不包含listSamCurveInfor
//[输入] RefPointData 参考点
//[输入] dSamePointDistance 两个相同点最大距离
//[输出] listSameCurveInfor相同点点链, 并且链头都是与参考点相同的
void FindSamePoint(CCurveNotchInforList &listAllCurveInfor, CPointData &RefPointData, double dSamePointDistance, CCurveNotchInforList &listSameCurveInfor);
//找给定边线中的辅助线
//[输入][输出] listAllCurveInfor 所有曲线 输出时没有listAssistantCurve中的曲线
//[输入][输出] listCloseCurveInfor 所有曲线 输出时没有listAssistantCurve中的曲线
//[输入] listBorder 边线实际点链
//[输出] listAssistantCurve 辅助线
void FindPatternAssistanceCurve(CCurveNotchInforList &listAllCurveInfor, CCloseCurveInforList &listCloseCurveInfor, CList<CPoint, CPoint> &listBorder, CCurveNotchInforList &listAssistantCurve);
//找给定边线中的字符串
//[输入][输出] listAllTextData 所有字符串 输出时没有listText中的字符串
//[输入] listBorder 边线实际点链
//[输出] listText 辅助线
void FindPatternText(CTextDataList &listAllTextData, CList<CPoint, CPoint> &listBorder, CTextDataList &listText);
//找给定纸样中的点
//[输入][输出] listPointData 所有点 输出时没有在纸样中点
//[输入] listBorder边线
//[输出] listAssistantPoint 辅助点
void FindPatternPoint(CPointDataList &listPointData, CList<CPoint, CPoint> &listBorder, CCurveNotchInforList &listAssistantPoint);
#endif

View File

@ -0,0 +1,847 @@
#if !defined(GROUPCODE_H)
#define GROUPCODE_H
#include <iostream>
#include <QPoint>
#include <QRect>
#include <QObject>
//#include <afxtempl.h>
#define MAX_LINESTRING 2048 //一行中最大的字符数
#define OriginPoint (0, 0)
#define MIN_SAMEPOINTDISTANCE 0.001 //单位跟当前读入文件一致用于判断点是否为同一个点两个点的X/Y差都小于这个值就认为相同 20181009 从0.15改为0.01,用于QPointData类中的==判断
//20221102 XQ 将值由0.01改为0.001 绣花精度比较高,存在很小的圆
//#define MAX_SAMEPOINTDISTANCE 0.15 //20190221 寻找闭合曲线时, 判断两条曲线端点为同一个点的最大距离, 单位跟当前读入文件一致 0.15与V9保持一致
#define MIN_MAXDISTANCE 1 //单位跟当前读入文件一致, 误差最大值, 用于判断两条曲线距离,判断两条线是否为同一条
#define V10_G_MAX_SPLINE_ERROR 0.05 //曲线的逼近最大误差,单位:mm
#define V10_G_MAX_SPLINECTRL_ERROR 0.1 //反求样条曲线控制点的逼近最大误差,单位:mm
//////////////////////////////////////////////////////////////////////////
//点类型
#define POINT_TURN 0 //转折点
#define POINT_CURVE 1 //曲线点
#define POINT_ARC 2 //圆弧点
#define POINT_SPILINE 3 //三次样条
//组码类型
#define CODE_NULL -1
#define CODE_POLYLINE 0
#define CODE_LWPOLYLINE 1
#define CODE_LINE 2
#define CODE_MLINE 3
#define CODE_SPILINE 4
#define CODE_TEXT 5
#define CODE_MTEXT 6
#define CODE_ARC 7
#define CODE_CIRCLE 8
#define CODE_ELLIPSE 9
#define CODE_DIMENSION 10
//单位
#define CONST_MM 0
#define CONST_INCH 1
//////////////////////////////////////////////////////////////////////////
class CTextDataList;
class CPDSNurbsPointList;
class QPointData : public QObject
{
public:
double m_dX;
double m_dY; //点的坐标
QString m_strLayer; //点所属层 AutoCAD文件中层可以为字符串
/*
=POINT_TURN
=POINT_CURVE曲线点
=POINT_ARC圆弧点
=POINT_SPILINE三次样条
*/
int m_iType;
int m_iGradeID; //放码ID
public:
QPointData(void);
QPointData(QPointData& a);
~QPointData(void);
void operator=(QPointData& a);
bool operator==(QPointData& a); //判断点坐标是否相等,按范围 MIN_SAMEPOINTDISTANCE
bool operator!=(QPointData& a); //按范围 MIN_SAMEPOINTDISTANCE
void Initial(void);
//20190221 判断两个点是否相等,按照给定的范围判断
//输入参数:
// a
// dMaxValue 范围
//返回值:
// =true 相等 =false不相等
bool Equal(QPointData&a, double dMaxValue);
//将点信息偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
QPoint GetIntPoint();
//设置放码ID
//输入参数:
// listPointGrade 查找点链
void SetGradeID(CTextDataList &listPointGrade);
};
class CCurveNotchInforList;
class QPointDataList : public QList<QPointData,QPointData&>
{
public:
QPointDataList& operator=(QPointDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
QPointData& operator[](int iIndex);
//将曲线点链所有点信息偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//得到矩形
QRect GetRect();
void GetIntPoint(QList<QPoint, QPoint> &listPoint);
//设置放码ID
//输入参数:
// listPointGrade 查找点链
void SetGradeID(CTextDataList &listPointGrade);
//设置点类型
//输入参数:
// listTurnPoint 转折点链
// listCurvePoint 曲线点链
void SetPointType(QPointDataList &listTurnPoint, QPointDataList &listCurvePoint);
//查找给定坐标点
//输入参数:
// PointData 点
//返回值:
// =true 找到;=false没有找到
bool FindSamePoint(QPointData PointData);
//将每一个点转成一个曲线链
void GetCurveInforList(CCurveNotchInforList &listCurveInfor);
//20201021 XQ 移除相邻的相同点,头尾点不处理
void RemoveSamePoint();
};
class CGroupCode : public QObject
{
public:
//在Auto CAD中颜色和线型都是使用符号表示的
int m_iType; //类型CODE_NULL....
QString m_strLayer; //所属层
QString m_strColor; //所属颜色, 如果为空,为所属层颜色
QString m_strViewCurveType; //通过查找对应表得到线类型..... 如果为空表示默认线型
public:
CGroupCode(void);
CGroupCode(CGroupCode& a);
~CGroupCode(void);
void operator=(CGroupCode& a);
void Initial(void);
void CopyData(CGroupCode &a);
};
//////////////////////////////////////////////////////////////////////////
//曲线信息
class CCurveInfor : public CGroupCode
{
public:
QPointDataList m_listCtrlCurve;
bool m_bClose; //=true 闭合曲线;=false 开口曲线
//下面三个变量目前只有m_iCurveType为CODE_SPILINE时有效
int m_iCtrlPointType; //= 0表示曲线经过控制点=1 不经过,三次样条; =2 表示 CODE_SPILINE已经被处理过 默认1
QList<double, double> m_listdCode40; //存放组码为40的值 结点数
QList<double, double> m_listdCode41; //存放组码为41的值 权值 如果为空权值为1
QPointDataList m_listReadCurve; //存放读入的拟合点, 不做任何处理,读入什么数据存放什么数据
QList<QPoint, QPoint> m_listPoint; //实际点链
public:
CCurveInfor(void);
CCurveInfor(CCurveInfor& a);
~CCurveInfor(void);
void operator=(CCurveInfor& a);
void Initial(void);
//将曲线点链所有点信息偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//得到矩形
QRect GetRect();
//翻转头点变尾点,尾点变头点
void Reverse();
//得到闭合曲线的中心点(将所有点的X/Y坐标加起来取平局值)
void GetMiddlePoint(QPointData &PDMiddle);
//计算CODE_SPILINE的控制点
void CalcuateSPlineCurve();
//将曲线控制点链分段
void Segmentation(QList<QPointDataList, QPointDataList&> &listPointDataList);
//设置曲线链中的点类型和放码ID
//输入参数:
// listPointGrade 放码点
// listTurnPointLayer 转折点
// listCurvePointLayer 曲线点
void SetPointTypeGradeID(CTextDataList &listPointGrade, QPointDataList &listTurnPointLayer, QPointDataList &listCurvePointLayer);
//计算曲线实际点链
//[输入] iDPMM 放大比例
void CalcuateActualPoint(int iDPMM);
//20200219 XQ 获取实际点链
//输出参数:
// listCurve 实际点链
//说明:
// 调用该函数之前必须调用计算实际点链函数
void GetCurve(QList<QPoint, QPoint> &listCurve);
//20201021 XQ 移除相邻的相同点,只对控制点操作
void RemoveSamePoint();
private:
//计算实际点链
//[输入] iDPMM 放大比例
//[输入] listCtrlPoint 控制点 只有一种类型(头尾点除外,中间点只有一种类型转折点,曲线点,圆弧点)
//[输出] listPoint实际点链
void CalcuateCurveInfor(int iDPMM, QPointDataList &listCtrlPoint, QList<QPoint, QPoint> &listPoint);
//计算三次样条
// [输入] listPoint 三次样条的四个控制点,
// [输出] listCtrl 逼近的控制点
//返回值:
// =ture 计算成功;=false 计算失败
//说明:
// 不管是否计算成功;两头点为转折点,中间点为控制点
bool CalculateSPLine(QPointDataList &listPoint, QPointDataList &listCtrl);
//设置点类型
//输入参数:
// listPoint 需要处理的点链
// bTurn =true所有点处理为转折点=false两头点为转折点中间点为曲线点
void SetPointType(QPointDataList &listPoint, bool bTurn);
//计算方程 t*t*t*ptPoint0+2*t*t*(1-t)ptPoint1+3*t*(1-t)*(1-t)ptPoint2+(1-t)*(1-t)*(1-t)ptPoint3
//[输入] ptPoint0ptPoint1ptPoint2ptPoint3方程的四个已知点
//[输入] dPro 比值t的值该值范围在0到1
//返回值:
// 方程的结果点
QPointData CalcuateEquation(QPointData ptPoint0, QPointData ptPoint1, QPointData ptPoint2, QPointData ptPoint3, double dPro);
//QPointData转CPDSNurbsPoint
void PointDataToNurbsPoint(QPointDataList &listPointData, CPDSNurbsPointList &listNurbsPoint);
//CPDSNurbsPoint转QPoint
void NurbsPointToPoint(CPDSNurbsPointList &listNurbsPoint, int iDPMM, QList<QPoint, QPoint> &listPoint);
//QPoint转QPointData
void PointToPointData(QList<QPoint, QPoint> &listPoint, int iDPMM, QPointDataList &listPointData);
//根据listDataPoint中点类型将listDataPointlistRealPoint分段
void NurbsSegmention(CPDSNurbsPointList &listDataPoint, CPDSNurbsPointList &listRealPoint, int iDPMM,
CArray < QList <QPoint, QPoint> , QList <QPoint, QPoint> > &arCtrlPoint, CArray < QList <QPoint, QPoint> , QList <QPoint, QPoint> > &arRealPoint, bool &bClose);
};
//////////////////////////////////////////////////////////////////////////
//剪口信息
class CNotchInfor : public QObject
{
public:
QPointData m_ptNotch;
int m_iNotchLayer; //剪口层 =4 I型; = 80 T型;= 81 Box型 =82 V型; =83 U型;
double m_dNotchWidth;
bool m_bNotchWidth; //=true 按读入数据处理;=false 按系统默认数据处理
double m_dNotchDepth;
bool m_bNotchDepth; //=true 按读入数据处理;=false 按系统默认数据处理
double m_dNotchAngle;
bool m_bAngle; //=true 表示角度可以用,=false 表示角度不可用
public:
CNotchInfor(void);
CNotchInfor(CNotchInfor& a);
~CNotchInfor(void);
void operator=(CNotchInfor& a);
void Initial(void);
//位置偏移,旋转和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//设置点放码ID
void SetGradeID(CTextDataList &listGradePoint);
};
class CNotchInforList : public QList<CNotchInfor,CNotchInfor&>
{
public:
CNotchInforList& operator=(CNotchInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CNotchInfor& operator[](int iIndex);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//设置点放码ID
void SetGradeID(CTextDataList &listGradePoint);
};
//////////////////////////////////////////////////////////////////////////
//线及其线上附带信息(例如:剪口)
class CCurveNotchInfor : public QObject
{
public:
CCurveInfor m_CurveInfor;
CNotchInforList m_listNotch;
public:
CCurveNotchInfor(void);
CCurveNotchInfor(CCurveNotchInfor& a);
~CCurveNotchInfor(void);
void operator=(CCurveNotchInfor& a);
void Initial(void);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//设置曲线链中的点类型和放码ID
//输入参数:
// listPointGrade 放码点
// listTurnPointLayer 转折点
// listCurvePointLayer 曲线点
void SetPointTypeGradeID(CTextDataList &listPointGrade, QPointDataList &listTurnPointLayer, QPointDataList &listCurvePointLayer);
//得到矩形
QRect GetRect();
//翻转头点变尾点,尾点变头点
void Reverse();
//20200219 XQ 获取实际点链
//输出参数:
// listCurve 实际点链
//说明:
// 调用该函数之前必须调用计算实际点链函数
void GetCurve(QList<QPoint, QPoint> &listCurve);
};
class CCurveNotchInforList: public QList<CCurveNotchInfor,CCurveNotchInfor&>
{
public:
CCurveNotchInforList& operator=(CCurveNotchInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CCurveNotchInfor& operator[](int iIndex);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//设置曲线链中的点类型和放码ID
//输入参数:
// listPointGrade 放码点
// listTurnPointLayer 转折点
// listCurvePointLayer 曲线点
void SetPointTypeGradeID(CTextDataList &listPointGrade, QPointDataList &listTurnPointLayer, QPointDataList &listCurvePointLayer);
//得到矩形
QRect GetRect();
//得到所有点
void GetAllPointData(QPointDataList &listPointData);
//20200220 XQ 得到所有剪口点
void GetAllNotchPoint(CNotchInforList &listNotchInfor);
//得到实际点链
//[输入] bClose =true 闭合
//[输出] listCurve 实际点链
//说明:
// 按照链表的顺序连接所有链, 除去相同点
void GetCurve(QList<QPoint, QPoint> &listCurve, bool bClose);
//计算实际点链
//[输入] iDPMM 放大比例
void CalcuateActualPoint(int iDPMM);
//20201021 XQ 移除相邻的相同点,头尾点不处理
void RemoveSamePoint();
};
//////////////////////////////////////////////////////////////////////////
//文字
class CTextData : public CGroupCode
{
public:
QPointData m_PointData;
QString m_strText;
bool m_bReadHeight;
double m_dHeight;
double m_dAngle;
public:
CTextData(void);
CTextData(CTextData& a);
~CTextData(void);
bool operator==(CTextData& a);
void operator=(CTextData& a);
void Initial(void);
//文字位置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//得到矩形
QRect GetRect();
//设置点放码ID
void SetGradeID(CTextDataList &listGradePoint);
};
class CTextDataList : public QList<CTextData,CTextData&>
{
public:
CTextDataList& operator=(CTextDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CTextData& operator[](int iIndex);
//文字位置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//得到矩形
QRect GetRect();
//设置点放码ID
void SetGradeID(CTextDataList &listGradePoint);
//查找给定坐标的字符串
//输入参数:
// PointData坐标
//输出参数:
// TextData 找到文本 返回值为true有效
//返回值:
// =true 找到;=false没有找到
bool FindSamePointText(QPointData PointData, CTextData &TextData);
};
//////////////////////////////////////////////////////////////////////////
//钻孔信息
class CDrillInfor : public QObject
{
public:
QPointData m_ptDrill;
bool m_bRadius; //=true 按读入数据处理钻孔;=false 按系统默认数据处理钻孔
double m_dRadius;
int m_iCommand; // =0 GP_DCM_DRILL = 1 GP_DCM_DRAW
public:
CDrillInfor(void);
CDrillInfor(CDrillInfor& a);
~CDrillInfor(void);
void operator=(CDrillInfor& a);
void Initial(void);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//设置点放码ID
void SetGradeID(CTextDataList &listGradePoint);
};
class CDrillInforList : public QList<CDrillInfor,CDrillInfor&>
{
public:
CDrillInforList& operator=(CDrillInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CDrillInfor& operator[](int iIndex);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//设置点放码ID
void SetGradeID(CTextDataList &listGradePoint);
};
//////////////////////////////////////////////////////////////////////////
//INSERT标识符信息
class CInsertData : public CGroupCode
{
public:
QString m_strBlockName;
QPointData m_InsertPoint;
double m_dScaleX; //20191012 XQ
double m_dScaleY;
double m_dRotateAngle; //旋转角度
public:
CInsertData(void);
CInsertData(CInsertData& a);
~CInsertData(void);
bool operator==(CInsertData& a);
void operator=(CInsertData& a);
void Initial(void);
};
class CInsertDataList : public QList<CInsertData,CInsertData&>
{
public:
CInsertDataList& operator=(CInsertDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CInsertData& operator[](int iIndex);
//根据给定的块名找出对应的块
//[输入] strBlockName 块名
//[输出] InsertData 插入位置
//返回值:
// 找到插入位置, 没有找到返回NULL
POSITION FindBlockName(QString strBlockName, CInsertData &InsertData);
};
//////////////////////////////////////////////////////////////////////////
class CCurveNotchInforList;
//寻找纸样边线所用到的结构
class CCloseCurveInfor : public QObject
{
public:
CCurveNotchInforList m_listCurveInfor;
double m_dAreaRect; //所在矩形面积
public:
CCloseCurveInfor(void);
CCloseCurveInfor(CCloseCurveInfor& a);
~CCloseCurveInfor(void);
void operator=(CCloseCurveInfor& a);
void Initial(void);
void GetAreaRect();
void GetHeadTail(QPointData &PointDataH, QPointData &PointDataT);
//得到点链
//说明:
// 将链表中的m_listCurveInfor放到一个链中
void GetPointList(QPointDataList &listPointData);
//得到闭合曲线的中心点(将所有点的X/Y坐标加起来取平局值)
void GetMiddlePoint(QPointData &PDMiddle);
};
class CCloseCurveInforList: public QList<CCloseCurveInfor,CCloseCurveInfor&>
{
public:
CCloseCurveInforList& operator=(CCloseCurveInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CCloseCurveInfor& operator[](int iIndex);
//找列表中面积最大的
POSITION FindMaxAreaRect();
};
/////////////////////////////////////////////////////////////////////////
//纸样块, 该类主要用于读入数据之后处理纸样数据时用到的
//说明:
//该类没有SetRotateOffsetScale的原因 在类中不需要对数据进行偏移->旋转->放大缩小, 偏移和旋转 放在m_ptOffsetm_dAngle中
class CPatternBlock : public QObject
{
public:
QString m_strPatternName; //纸样名
QString m_strSizeName; //号型名
QString m_strComment; //注释COMMENT/ANNOTATION
CStringArray m_arrMaterial; //布料名
CUIntArray m_arrQuantity; //总片布料份数 Quantity:<R,L>
CUIntArray m_arrLQuantity; //左片布料份数 Quantity:<R,L>
//m_arrQuantity, m_arrLQuantity大小保持一致
bool m_bFlip; //翻转信息 =true 允许翻转
double m_dRotation; //最大倾斜角 Rotation<0...360>
bool m_bFold; //折叠 Fold:<Y/N> =true 允许折叠
double m_dTilt; //最大倾斜角度 Tilt:<+/-0..90>
CCurveNotchInforList m_listBorder; //边线
CCurveNotchInforList m_listSeam; //缝份线
CCurveNotchInforList m_listAssistantCurve; //辅助线
CTextDataList m_listText; //字符串
//读AutoCAD文件
//CNotchInforList m_listNotch; //剪口
CDrillInforList m_listDrill; //钻孔
CCurveNotchInfor m_GrainLine; //布纹线
CCurveNotchInfor m_SymmetryLine; //对称轴
//下面变量只用于读ASTM/AAMA
CCurveNotchInfor m_GradeLine; //放码线
//纸样的偏移和旋转角度旋转点为QPoint(0,0), 水平为零度
QPointData m_ptOffset;
double m_dAngle;
public:
CPatternBlock(void);
CPatternBlock(CPatternBlock& a);
~CPatternBlock(void);
void operator=(CPatternBlock& a);
void Initial(void);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//放缩
//输入参数:
//dScale 放大缩小比例
void SetScale( double dScale);
QRect GetRect();
//计算实际点链
//[输入] iDPMM 放大比例
void CalcuateActualPoint(int iDPMM);
private:
//拷贝
void CopyPatternInfor(CPatternBlock& a);
};
class CPatternBlockList : public QList<CPatternBlock,CPatternBlock&>
{
public:
CPatternBlockList& operator=(CPatternBlockList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CPatternBlock& operator[](int iIndex);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为QPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//放缩
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
QRect GetRect();
//下列函数用于V10系统中创建纸样所用
//得到列表中所有纸样的号型名
//输出参数:
// listAllSizeName 号型名大小与this列表一样 顺序也一致
void GetAllSizeName(QList<QString,QString> &listAllSizeName);
//找给定名称的号型的在列表中的位置
//输入参数:
// strSizeName 号型名
//返回值:
// 号型名的在列表中的位置, 找到的第一个; NULL表示没有
POSITION FindSizeName(QString strSizeName);
//计算实际点链
//[输入] iDPMM 放大比例
void CalcuateActualPoint(int iDPMM);
};
//读一行字符串
//[输入] bReadWindowText =true 回车是用0x0A表示的=false 回车则是0x0D0A
//[输入] iMaxCount 一行中最大的长度
//[输入] fFile 文件
//返回值:
// 读入的文字
QString GetALineOfFile(bool bReadWindowText, int iMaxCount, FILE *fFile);
//读两行字符串
//[输入] bReadWindowText =true 回车是用0x0A表示的=false 回车则是0x0D0A
//[输入] fFile 文件
//[输出] strString1/strString2 连续两行数据
void ReadTwoLineString(bool bReadWindowText, FILE *fFile, QString &strString1, QString &strString2);
//判断给定的字符串是否为一个数据块的开始标识符(strValue1是否为0strValue2是否为 POLYLINE, LINE...)
//[输入] strValue1 需要判断的字符串
//[输入] strValue2 需要判断的字符串
//返回值:
// =true 是false 不是
//说明:
//strValue1为空的话不判断不为空 判断是否为0 为0继续strValue2的判断
bool JudgeCode(QString strValue1, QString strValue2);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,439 @@
/////////////////////////////////////////////////////////////////////////////
//
// 3BSpline.h - the class of B Spline
//
// 三次B样条曲线类
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(_BSPLINE_H)
#define _BSPLINE_H
#include <afxtempl.h>
#include "Point3D.h"
class C3BSpline;
typedef class C3BSpline * LP3BSpline;
class C3BSpline : public CObject
{
// Attribute
private:
CArray <CPoint_3D,CPoint_3D> m_arrayControlPoints; //Array of Control Points控制点数组
CArray <double,double> m_arrayWeight; //Array of Weight 权重数组
UINT m_nControlPointsCount; //Number of Control Points Array (also of Weight Array)控制点数组(权重数组)数目
CArray <double,double> m_arrayKnots; //Sequence of Knots 节点序列
UINT m_nKnotsCount; //Number of Knots 节点个数
UINT m_nDegree; //Degree of Nurbs Curve (=k-1) 非均匀有理B样条曲线的阶
char m_cCurveType; //Type of Nurbs Curve 非均匀有理B样条曲线的类型
//'U'Uniform B-Spline 均匀有理B样条曲线
//'Q'Quasi Uniform B-Spline 准均匀有理B样条曲线
//'P'Piecewise Bezier Spline 分段Bezier曲线
//'N'Non-Uniform B Spline 非均匀有理B样条曲线
//'C'Set Knots Custom 自行设计节点
BOOL m_bInputByValuePoints; //Sign of Input Points Type 输入点类型标记
UINT m_nDispCount; //Display Count between two Knots 两节点之间的显示点数
CArray <CPoint_3D,CPoint_3D> m_arrayDisplayPoints; //Value Points to Display 需显示的取值点
CArray <double,double> m_arrayCurrentParameter; //Parameter Array of Display Points 显示点参数数组
CArray <double,double> m_arrayCurrentDistance; //Distance Array of Display Points 显示点距离数组
BOOL m_bGetDisplayPoints; //Sign of Calculate of Value Points 取值点计算标记
BOOL m_bModified; //Sigh of Modifying of Curve (Need of reCalculate) 曲线更改标记(需重新计算)
CArray <CPoint_3D,CPoint_3D> m_arrayInputPoints; //Input Points (may be Control Points or Value Points)
CArray <double,double> m_arrayInPntPara; //Input Points parameter
CVector m_BaseVector; //Base Vector of the Curve
public:
BOOL m_bKnotsWeightsSeted; //Sign of Knots and Weights Seted
BOOL m_bHighLightBegin; // sign of begin point highlight
BOOL m_bHighLightEnd; // sign of end point highlight
BOOL m_bDispBE; // sign of start and end point highlight
int m_nFlag; // 0: neither TP nor CP points is diplayed;
//1:only TP is displayed;
// 2:only CP is displayed; 3:both TP and CP is displayed
// 4: TP and curve direction
// 5: display length
// 6: diaply length ruler
// Operation
public:
// Is close curve
BOOL IsClose();
// C++ constructor, creating a C3BSpline, set some value as default
C3BSpline();
// C++ constructor, creating a C3BSpline from a C3BSpline object
C3BSpline(C3BSpline const& bsc);
// C++ deconstructor, free unused memory
virtual ~C3BSpline();
// Get curve control points count( sequence number From 0 to n, totally: n+1, return: n+1 )
// Return count in 'UINT' data type
UINT GetControlPointsCount();
// Set curve control points count, this function is ready for the function "SetControlPoint"
void SetControlPointsCount(UINT nCount);
// Get curve control point value by index( begin from 0 to n )
// Modify input parameter( 3 of double) as return
void GetControlPoint(UINT nIndex, double &x, double &y, double &z);
// Get curve control point value by index( begin from 0 to n )
// Return the value in 'CPoint_3D' data type
CPoint_3D GetControlPoint(UINT nIndex);
// Set curve control point by index( begin from 0 to n ) and its X, Y, Z value( double )
void SetControlPoint(UINT nIndex, double x, double y, double z);
// Set curve control point by index( begin from 0 to n ) and the position value
void SetControlPoint(UINT nIndex, const CPoint_3D CP);
// Set curve control point value with two dimension double array( double v[count][3], each v[*] contains X, Y, Z value )
void SetControlPoints(double **nPoint);
// Remember: we don't get the weights count because it's just as same as the control points count
// Get curve weight value by index( begin from 0 to n )
// Return weight in 'double' data type
double GetWeight(UINT nIndex);
// Set curve weight by index( begin from 0 to n ) and the double value
void SetWeight(UINT nIndex, double nWeight);
// Set curve weights by double array
void SetWeights(double *nWeight);
// Get curve knots count( if everything is all right, it must be m_nControlPointsCount+m_nDegree+1 )
// Return count in 'UINT' data type
UINT GetKnotsCount();
// Set curve knots count, this function is ready for the function "SetKnot"
void SetKnotsCount(UINT nCount);
// Get curve knot value by index( begin from 0 to n )
// Return knot in 'double' data type
double GetKnot(UINT nIndex);
// Set curve knot by index( begin from 0 to n ) and the double value
void SetKnot(UINT nIndex, double nKnot);
// Set curve knots by double array
void SetKnots(double *nKnot);
// We presume that you have set the control points, you can set the curve's weights and knots by this function
// or you can set them yourself. We supply 4 modes list( all modes set weght as 1.0f ), Mode set to be 1 as default( no parameter input ):
// Mode==1: Uniform B-Spline. The knots space between are as same as 1.0f, knots begin from (-m_nDegree).
// Mode==2: Quasi Uniform B-Spline. Just as Uniform B-Spline but the knots space between in first (m_nDegree+1) knots and terminal (m_nDegree+1) knots are 0.0f.
// Mode==3: Piecewise Bezier Spline. First (m_nDegree+1) knots are set to be 0.0f, and terminal (m_nDegree+1) knots are set to be 1.0f. The middle left are set to be 0.5f.
// Mode==4: Non-Uniform B Spline. First (m_nDegree+1) knots are set to be 0.0f, and terminal (m_nDegree+1) knots are set to be 1.0f. The middle left knots space between are determined by length of two input points one by one.
void SetCurveKnotsWeights(int Mode=1);
// Set curve degree( the constructor set degree to 3 as default, we advise you don't use others )
void SetDegree(UINT nDegree);
// Get curve degree value
// return degree value in 'UINT' data type
UINT GetDegree();
// Get point coordinate that in the curve by parameter
// Modify input parameter( 3 of double) as return
void GetPointCoordinate(double u, double &x, double &y ,double &z);
// Get point coordinate that in the curve by parameter
// Return coordinate in 'CPoint_3D' data type
CPoint_3D GetPointCoordinate(double u);
// Set curve input type( input by control points as 'C'(default) and input by value points as 'V' )
void SetInputType(char inType='C');
// Set curve input by value points
void SetInputByValuePoints();
// Set curve input by control points
void SetInputByControlPoints();
// Get curve input type( input by control points as 'C'(default) and input by value points as 'V' )
// Return type in 'char' data type
char GetInputType();
// Test if curve is input by value points
// Return logical result in 'BOOL' data type
BOOL IsInputByValuePoints();
// Test if curve is input by control points
// Return logical result in 'BOOL' data type
BOOL IsInputByControlPoints();
// Set curve Display Count即设置显示精度
void SetDisplayCount(UINT Count);
// Get curve Display Count即获得显示精度
UINT GetDisplayCount();
// Get curve display points count( sequence number From 0 to n, totally: n+1, return: n+1 )
// Return count in 'UINT' data type
UINT GetDisplayPointsCount();
// Get curve control point value by index( begin from 0 to n )
// Modify input parameter( 3 of double) as return
void GetDisplayPoint(UINT nIndex, double &x, double &y, double &z);
// Get curve control point value by index( begin from 0 to n )
// Return the value in 'CPoint_3D' data type
CPoint_3D GetDisplayPoint(UINT nIndex);
/*// Set curve display tolerance
void SetDisplayTolerance(double tlrnc);
// Get curve display tolerance
// Return the value in 'double' type
double GetDisplayTolerance();*/
// Calculate curve display points also calculate every point's parameter and cumulating chordal length
// The value store in class member data
void CalculateDisplayPoints();
// get start point of the curve
CPoint_3D Start_pos();
// get end point of the curve
CPoint_3D End_pos();
// Add curve input point
int AddInputPoints(CPoint_3D new_InP);
// Get input value points count
int GetValuePointsCount();
// Set curve input points count, this function is ready for the function "SetInputPoint"
void SetInputPointsCount(UINT nCount);
// Set curve input point by index and the CPoint_3D of point
void SetInputPoint(UINT nIndex, const CPoint_3D mod_InP);
// Set curve input point by index and the X, Y, Z value of point
void SetInputPoint(UINT nIndex, double x, double y, double z);
// Get curve input points count
int GetInputPointsCount();
// Get curve input point value by index( begin from 0 to n )
// Modify input parameter( 3 of double) as return
void GetInputPoint(UINT nIndex, double &x, double &y, double &z);
// Get curve control point value by index( begin from 0 to n )
// Return the value in 'CPoint_3D' data type
CPoint_3D GetInputPoint(UINT nIndex);
// Get curve input point parameter by index( begin from 0 to n )
double GetInputPointPara(UINT nIndex);
// Clear all input points
void ClearInputPoints();
// Init value points
void InitValuePoints();
// Set curve base vector to move the curve in vector value
void SetBaseVector(double x, double y, double z);
// Get curve last movement value
// Modify input parameter as return
void GetBaseVector(double &x, double &y, double &z);
// Get curve control points by input points. If the input points are control points, we set the knots and weights by 'Mode' input.
// If the input points are value points, we calculate the control points by 'Mode' and set knots and weights in Mode=4.
// That is to say: 'Mode' has different meanings in different input type.
void GetControlPointsByInputPoints(int Mode=3);
// Calculate control points by input value points. Here the knots sequence is uniform: from (-m_nDegree) add 1 to (m_nControlPointsCount+m_nDegree)
// P: Control Points; Q: Value Points; Q`: Unit Vector of Value Points
// Mode==1 Condition: P1=Q1, Pn=Qn ==>> P0=2*P1-P2, Pn+1=2Pn-Pn-1
// Mode==2 Closed period B-Spline (m_nDegree==3) ==>> P0=Pn, Pn+1=P1
// Mode==3 P0=Pn, Pn=1=Pn
// Mode==4 Know Q`1 and Q`n (we calculate it with input points)
// Q`1=(P2-P0)/2, Q1=(P0+4*P1+P2)/6 ==>> P0=P2-2*Q`1, 2*P1/3+P2/3=Q1+Q`1/3
// Q`n=(Pn+1-Pn)/2, Qn=(Pn-1+4*Pn+Pn+1)/6 ==>> Pn-1=Pn+1-2*Q`n, Pn-1/3+2*Pn/3=Qn-Q`n/3
void GetControlPointsByValuePoints(int Mode=3);
// Calculate control points by input value points. Here the knots sequence is set by cumulating bowstring length
// P: Control Points; Q: Value Points; Q`: Unit Vector of Value Points
// Mode==1 Condition: P1=Q1, Pn=Qn ==>> P0=2*P1-P2, Pn+1=2Pn-Pn-1
// Mode==2 Closed period B-Spline (m_nDegree==3) ==>> P0=Pn, Pn+1=P1
// Mode==3 P0=Pn, Pn=1=Pn
// Mode==4 Know Q`1 and Q`n (we calculate it with input points)
// Q`1=(P2-P0)/2, Q1=(P0+4*P1+P2)/6 ==>> P0=P2-2*Q`1, 2*P1/3+P2/3=Q1+Q`1/3
// Q`n=(Pn+1-Pn)/2, Qn=(Pn-1+4*Pn+Pn+1)/6 ==>> Pn-1=Pn+1-2*Q`n, Pn-1/3+2*Pn/3=Qn-Q`n/3
void GetCPByVP(int Mode=3);
// Calculate control points by input value points. Here the knots sequence is set by cumulating bowstring length
// P: Control Points; Q: Value Points; Q`: Unit Vector of Value Points
// Here we know Q`1(start_dir) and Q`n(end_dir) as input
// Q`1=(P2-P0)/2, Q1=(P0+4*P1+P2)/6 ==>> P0=P2-2*Q`1, 2*P1/3+P2/3=Q1+Q`1/3
// Q`n=(Pn+1-Pn)/2, Qn=(Pn-1+4*Pn+Pn+1)/6 ==>> Pn-1=Pn+1-2*Q`n, Pn-1/3+2*Pn/3=Qn-Q`n/3
void GetCPByVPMode4(CUnitVector const& start_dir, CUnitVector const& end_dir);
// Insert a knot value in a known curve, given the insert domain position and the repeat times of insert value
void InsertKnots(UINT i, UINT r, double u);
// Insert a knot value in a known curve
void InsertKnots(double u);
// Get the curve's total length
// Return the value in 'double' data type
double GetCurveLength();
// Get part length of the curve from begining, giving parameter value
// Return the part length in 'double' data type
double GetLengthByParameter(double para);
// Get curve parameter while giving the curve length from begining
// Return parameter in 'double' data type
double GetParameterByLength(double leng);
// The following fuctions are from 'CGLEntity' in virtual type
// Get the maximum length to the origin point of the curve
// Return the maximum length in 'float' data type
virtual float GetRange();
// Copy a C3BSpline
// 拷贝一个bs3_curve(传入C3BSpline)
void Copy(C3BSpline const& bsc);
void Copy(LP3BSpline bs);
// Get derivative of a point in the curve, giving parameter and number of derivatives to be evaluated
// Return derivative in 'vector' data type
// 给出某点的参数值并指出阶数求出该点的n阶导数
CVector GetDerivative(double u, UINT order=1);
// Change the curve's total parameter domain, giving the begin and end point
// 改变参数区间值默认改为从0.0到1.0
void ChangeTotalDomain(double Begin=0.0, double End=1.0);
// Get the curve's parameter domain
// Modify given parameter as return
// 获得参数值区间
void GetCurveDomain(double &Begin, double &End);
// Break the curve from position of given parameter
// 根据曲线上点的参数值,在该处打断曲线,修改原曲线为前半部,并返回新曲线(后半部)
LP3BSpline BreakCurveByParameter(double u);
// Break the curve from position of given curve length from begin
// 根据指定的曲线长度,在该位置将曲线打断,修改原曲线为前半部,并返回新曲线(后半部)
// 由于在根据长度求参数时进行了线性插值,故较精确
LP3BSpline BreakCurveByLength(double l);
// Reverse Curve Direction
// 将曲线反向
void ReverseDir();
// Rebuild Curve, Add Input Value Points by display points
// 以取样显示点方式录入曲线型值点,同时根据参数修正曲线端点,重建曲线
// mode = 's' start起点; 'e' end终点; 'b' both两端; 'n' none不重整端点.
// 001214 专为特征线设置的 mode = 'q' 特征线起点;'z'特征线终点。
void RebuildDir(CPoint_3D * ppb, CPoint_3D * ppe, char mode);
// Refresh input points by given new start/end point
// 只是根据参数修正(更新)曲线的端点,不改变其它点
BOOL RefreshInputPoints(CPoint_3D * ppb, CPoint_3D * ppe, char mode);
// 根据传入曲线长度,获得曲线上的点,由于进行线性插值,比较精确
CPoint_3D GetPositionByLength(double leng);
// 判断曲线是否封闭
BOOL IsClosed();
// 重设型值点
void ResetInputValuePoints(int type);
// Unite two curves. The first curve's end point must be same as the second's begin point
// Return the result of unite curve with its pointer. We don't delete the origin curves
// 合并两条曲线,合并后的新曲线由函数返回,而原曲线并未改动(请自行手工删除)
// 两条曲线必须保证端点处相连
LP3BSpline UniteTwoCurve(LP3BSpline FirstCurve, LP3BSpline SecondCurve);
// Get parameter of the curve, giving its start parameter and length from the start point
// Return parameter in 'double' data type
// 给出指定起点处参数值求出从该点处开始长度值为length处的点的参数
double BS3_curve_length_param(
double start, // parameter to datum point
double length); // length
// Gets an arbitrary number of derivatives of a curve
// Return the actual number of derivatives calculated
// 求曲线参数点处的一阶/二阶 切/法矢
int BS3_curve_evaluate(
double param, // given parameter
CPoint_3D& pos, // returned CPoint_3D
CVector& deriv, // returned derivatives
int order); // number of derivatives to be evaluated, order=1,2
// Evaluates the curve at the given parameter value
// Return the value in 'CPoint_3D' data type
// 获得曲线参数值处的点
CPoint_3D BS3_curve_position(
double param); // given parameter value
// Gets the signed arc length of the curve between two parameter values.
// Return the length in 'double' data type
// 求两点(给出参数值)间曲线的长度
double BS3_curve_param_length(
double start, // parameter of start point
double end); // parameter of end point
// Creates a curve that interpolates or fits to the given tolerance the given points, with the given tangent directions at the two end points
// 给出型值点列(CPoint_3D数组)起点终点切矢方向生成bs3_curve曲线
LP3BSpline BS3_curve_interp(
int npts, // number of points to interpolate
CPoint_3D const* pts, // points to interpolate or fit
CUnitVector const& start_dir, // start direction vector
CUnitVector const& end_dir, // end direction vector
double fitol, // fit tolerance
double& actual_tol); // returned actual tolerance used
// Creates a curve given value points
// 给出型值点列(CPoint_3D数组)生成bs3_curve曲线
LP3BSpline BS3_curve_interp(
int npts, // number of points to interpolate
CPoint_3D const* pts); // points to interpolate or fit
private:
// Get B_Spline basic function value
// Return the value in 'double' data type
double N_u(UINT i, UINT k, double u);
// Used for function "N_u3"
double NA(UINT i, UINT k, double u);
double NB(UINT i, UINT k, double u);
// Get B_Spline basic function value( m_nDegree=3 )
// Return the value in 'double' data type
double N_u3(UINT i, double u);
// Get point in the curve by index and parameter value use "de Boor Arithmetic of B_Spline"
// Return the value in 'CPoint_3D' data type
CPoint_3D P_u(UINT i, double u);
// Calculate distance between two input points one by one( this function only used in function "SetCurveKnotsWeights" )
// 计算相邻输入点间的距离
double Dist_2P(UINT nIndex);
// Found parameter domain between two knots
// Return first knot's index in 'int' data type
// 找到参数值所在的节点区间(返回值是前一个节点位置)
int FoundKnotsDomain(double u);
};
#endif

View File

@ -0,0 +1,196 @@
/********************************************************************
: 20111222<13:51:21>
: PDSAlgorithm.h
:
:
使,,使
,,
:
*********************************************************************/
#ifndef PDSALGORITHM_H
#define PDSALGORITHM_H
#include <afxtempl.h>
//线段
// 该类将会在计算最大多边形的过程中使用,每一条点链都会记录所在曲线的索引值和方向
class CPDSSegment : public CObject
{
public:
CList<CPoint,CPoint> m_listPoint; //实际点链
int m_iCurveIndex; //this所属曲线的索引值
// 举例:在计算最大多边形的过程中,该变量记录this取自于哪一条点链(取名为list)
BOOL m_bDirection; //=TRUE 方向相同, =FALSE 方向相反
// 举例:在计算最大多边形的过程中,该变量记录m_listPoint与list是否头尾点顺序相同,
// 若=FALSE则表示m_listPoint从头到尾的方向是list从尾到头的方向
int m_iIndex; //this在整条链表(数组)中的索引值,可以根据实际情况酌情指定该变量的含义
CPDSSegment(void);
CPDSSegment(CList<CPoint,CPoint>& listPoint, int iCurveIndex, BOOL bDirection, int iIndex);
CPDSSegment(CPDSSegment& rhs);
CPDSSegment& operator=(CPDSSegment& rhs);
BOOL operator==(CPDSSegment& rhs);
BOOL operator!=(CPDSSegment& rhs);
void Initial(void);
};
//typedef CList<CPDSSegment,CPDSSegment&> CPDSSegmentList;
class CPDSSegmentList : public CList<CPDSSegment,CPDSSegment&>
{
public:
CPDSSegmentList& operator=(CPDSSegmentList& rhs);
BOOL operator==(CPDSSegmentList& rhs);
BOOL operator!=(CPDSSegmentList& rhs);
CPDSSegment& operator[](int iIndex);
};
//计算面积最大的多边形
//特别说明:
// 本函数计算在给定的多条点链所形成的若干个多边形中,面积最大的那一个
//参数:
// alCurve 点链数组,输入时要保证每条点链至少有2个点,如果是多边形还要求首尾点相同,并且相邻的点坐标不同
// listSegment [输出]线段链表,按照顺序将各线段中的点链连接起来就是一整条多边形,并且是逆时针的(在屏幕上看是顺时针)
// CPDSSegment::m_iCurveIndex表示该元素是alCurve中的第几条,从0开始
// CPDSSegment::m_bDirection=TRUE表示与alCurve[]方向相同
// CPDSSegment::m_iIndex不使用
//返回值:
// =TRUE 计算成功, =FALSE 计算失败,listSegment为空
BOOL CalculatePolygonWithMaxArea(CArray<CList<CPoint,CPoint>,CList<CPoint,CPoint> >& alCurve, CPDSSegmentList& listSegment);
//计算切割区域
//特别说明:
// 在切割模板的时候,众多的开槽线纵横交错,需要把它们形成的最大多边形找到,直接将中间部分镂空即可,既加快速度又延长激光寿命;
// 切角半径的作用是避免从一条模板切割到另一条模板时形成尖锐的夹角;
//参数:
// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米)
// alCurve 点链数组,输入时要保证每条点链至少有2个点,如果是多边形还要求首尾点相同,并且相邻的点坐标不同
// iRadius 切角半径,若=0表示不切角
// dMaxError 计算圆弧时的拟合误差
// alCutting [输出]点链数组,其中的每一条点链都是被切割的轨迹
//返回值:
// alCutting.GetSize()
int CalculateCuttingRegion(int iDPMM, CArray<CList<CPoint,CPoint>,CList<CPoint,CPoint> >& alCurve, int iRadius, double dMaxError, CArray<CList<CPoint,CPoint>,CList<CPoint,CPoint> >& alCutting);
//计算listSegment中任意两条曲线的交点,并把交点插入到点链中
void DividePDSSegmentList(CPDSSegmentList& listSegment);
//获取给定点的度数(如果某条线段的头点或者尾点等于给定点,那么度数加1)
int GetPointDegree(CPoint ptPoint, CPDSSegmentList& listSegment);
//移除孤立的曲线(如果曲线的头点或者尾点的度数为1,那么它就是孤立的,要被移除)
void RemoveIsolateCurve(CPDSSegmentList& listSegment);
//获取面积最大的多边形
//参数:
// listSelectSegment [输入][输出]给定的全部点链,输出后会将listBorderSegment中的点链移除
// listBorderSegment [输出]能够形成边界的点链
void GetMaxBorder(CPDSSegmentList& listSelectSegment, CPDSSegmentList& listBorderSegment);
//获取与给定点连接的点链
//参数:
// listSelectSegment [输入][输出]给定的全部点链,一旦某条点链被添加到listConnectSegment中,则从该链表中移除
// ptPoint 给定点,查找与头点或者尾点等于该点的点链
// listConnectSegment [输出]与给定点相连接的点链
void GetConnectSegment(CPDSSegmentList& listSelectSegment, CPoint ptPoint, CPDSSegmentList& listConnectSegment);
//向已有边线中添加一条点链
//参数:
// listConnectSegment [输入][输出]与当前已有边线的尾点相连接的点链,输出时,哪条点链被添加到边线中,就把哪条点链移除
// listBorderSegment [输入][输出]输入时不能为空,本函数要使用其尾点的切线方向,输出时将会有一条点链被添加到尾部
void AddOneSegment(CPDSSegmentList& listConnectSegment, CPDSSegmentList& listBorderSegment);
//添加一条点链
//参数:
// ptLB 左下角点(left-bottom),世界坐标系下
// listConnectSegment [输入][输出]与当前已有边线的尾点相连接的点链,输出时,哪条点链被添加到边线中,就把哪条点链移除
// listBorderSegment [输出]输出时将会有一条点链被添加到尾部
void AddOneSegment(CPoint ptLB, CPDSSegmentList& listConnectSegment, CPDSSegmentList& listBorderSegment);
//获取极限点
//参数:
// ptCenter 旋转中心
// listPoint 点链
// bAntiClockwise =TRUE 逆时针旋转,世界坐标系下
//返回值:
// 极限的那个点
//说明:
// 如果要求逆时针旋转,那么要选择最左边的那个点;反之,要选择最右边的那个点
CPoint GetLimitPoint(CPoint ptCenter, CList<CPoint,CPoint>& listPoint, BOOL bAntiClockwise);
//获取左下角点
//参数:
// listSegment 链表
//返回值:
// 点,左下角点.单位:世界坐标系
//说明:
// 此处的左下角点是指:y值最小的那个点,如果这样的点有多个,那么选择x值最小的那一个
CPoint GetLeftBottomPoint(CPDSSegmentList& listSegment);
//计算圆弧切角的实际点链
//参数:
// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米)
// listPoint1 第一条线
// listPoint2 第二条线,并且listPoint2.GetHead()==listPoint1.GetTail()
// iRadius 圆角半径,不能为0
// dMaxError 拟合圆弧的最大误差,不能为0
// listArc [输出]圆弧实际点链
//返回值:
// =TRUE 计算成功,listArc数据有效, =FALSE 计算失败,listArc为空
BOOL CalculateArcCorner(int iDPMM, CList<CPoint,CPoint>& listPoint1, CList<CPoint,CPoint>& listPoint2, int iRadius, double dMaxError, CList<CPoint,CPoint>& listArc);
//计算listSegment中任意两条曲线的交点,并把交点插入到点链中
void DividePDSSegmentList_New(CPDSSegmentList& listSegment);
//将listSegment中的相同点关联起来
//特别说明:
// 链表中的某些点可能坐标并不相等,但是非常接近,调用IsSamePoint()=true,那么应该把这样的点设置为相同的坐标
void ConnectPDSSegmentSamePoint(CPDSSegmentList& listSegment);
//查找小于给定阈值的点,并返回该点位于哪条链表中
//特别说明:
// (1)20160507,syf,添加该函数
// (2)该函数被CalculateCuttingRegion调用
//输入参数:
// ptPoint 给定点
// listSegment 链表
// dMaxError 最大误差值
//返回值:
// 索引值,从0开始,若为-1则搜索失败
int FindNearestPoint_WithDistance(CPoint ptPoint, CPDSSegmentList& listSegment, double dMaxError);
//查找相同的线段
//特别说明:
// (1)20160507,syf,添加该函数
// (2)该函数被CalculateCuttingRegion调用
// (3)实际上listSegment[].m_listPoint.GetCount()=2,全都是线段,这是由CalculateCuttingRegion函数中算法的特殊性决定的
// (4)在查找的过程中,忽略掉线段的方向,只要是端点相同即为相同
//输入参数:
// ptPoint1 线段起点
// ptPoint2 线段终点
// listSegment 链表
//返回值:
// 索引值,从0开始,若为-1则搜索失败
int FindSameSegment_2P(CPoint ptPoint1, CPoint ptPoint2, CPDSSegmentList& listSegment);
//计算切线距离点
//特别说明:
// (1)本函数被数据结构引用,也被工具引用,在V10版本发行后,一定要谨慎修改,以免造成已发行版本出错,切记!!!!
// (2)只要listCurve.GetCount() >= 2,本函数都返回true
// (3)计算切线时,根据宏定义F_MAX_TANGENT_ERROR截取长度,一旦宏定义被修改,本函数的计算结果就会改变
//输入参数:
// iDPMM 分辨率
// listCurve 点链,至少有2个点,否则直接返回false;如果头尾点相同,那么按照多边形处理
// ptFrom 点,从该点开始计算切线;如果该点不在线上,则根据它的最近点计算切线方向,最终保证(ptFrom,ptTangency)就是切线方向
// bTangentPrev =true 指向前趋方向的切线,=false 指向后继方向的切线
// dLength 切线长度,不能为0,使用其绝对值
//输出参数:
// ptFixPoint 最近点,距离ptFrom最近的点,一定在线上(未必在点链内部)
// ptTangent 切点
//返回值:
// =true 计算成功,=false 计算失败
BOOL CalculateTangentPD(int iDPMM, CList<CPoint,CPoint>& listCurve, CPoint ptFrom, BOOL bTangentPrev, double dLength, CPoint& ptFixPoint, CPoint& ptTangent);
#endif //PDSALGORITHM_H

View File

@ -0,0 +1,139 @@
/********************************************************************
:2017911
:PDSBezier.h
:
:Bezier曲线
:
*********************************************************************/
#ifndef _PDS_BEZIER_H_
#define _PDS_BEZIER_H_
#include <afxwin.h>
#include <afxtempl.h>
#include "PDSMath.h"
//Bezier点
class CPDSBezierPoint : public CObject
{
public:
CDBLPoint m_ptPoint; // 点,Bezier曲线必须要经过该点
CDBLPoint m_ptPrev; // 前切线点
CDBLPoint m_ptNext; // 后切线点
double m_dParam; // 该点对应的参数值,在计算Bezier曲线的实际点链的过程中起作用,默认值:0
public:
CPDSBezierPoint(void);
CPDSBezierPoint(CDBLPoint ptPoint, CDBLPoint ptPrev, CDBLPoint ptNext, double dParam = 0.0);
CPDSBezierPoint(CPoint ptPoint, CPoint ptPrev, CPoint ptNext, double dParam = 0.0);
CPDSBezierPoint(CPDSBezierPoint& rhs);
virtual ~CPDSBezierPoint(void);
CPDSBezierPoint& operator=(CPDSBezierPoint& rhs);
BOOL operator==(CPDSBezierPoint& rhs); // 仅比较m_ptPoint是否相等
BOOL operator!=(CPDSBezierPoint& rhs); // 仅比较m_ptPoint是否相等
void Initial(void);
//使用ptPoint,ptPrev,ptNext设置this
void SetPoint(CPoint ptPoint, CPoint ptPrev, CPoint ptNext);
//获取ptPoint,ptPrev,ptNext
void GetPoint(CPoint& ptPoint, CPoint& ptPrev, CPoint& ptNext);
};
//Bezier点的链表
class CPDSBezierPointList : public CList<CPDSBezierPoint,CPDSBezierPoint>
{
public: //扩展的变量
public: //扩展的方法
CPDSBezierPointList& operator=(CPDSBezierPointList& rhs); //赋值
CPDSBezierPoint& operator[](int iIndex); //根据索引值检索,不可越界
//根据listPoint设置this
void SetPoint(CList<CPoint,CPoint>& listPoint);
//将this的数据输出至listPoint
void GetPoint(CList<CPoint,CPoint>& listPoint);
POSITION AddWithoutDuplicate(CPDSBezierPoint ptBezierPoint, BOOL bAddTail = TRUE);
void AddWithoutDuplicate(CPDSBezierPointList& listBezierPoint, BOOL bAddTail = TRUE);
//根据给定的参数值,查找索引值
int FindParamIndex(double dParam);
//获取长度
double GetLength(void);
//将this翻转
void Reverse(void);
};
//Bezier曲线类
class CPDSBezierCurve : public CObject
{
public:
//成员变量封装在一起,方便写代码,Bezier曲线的计算函数并不使用成员变量
CPDSBezierPointList m_listCtrlPoint; // 控制点链,前后切线点参与计算
CPDSBezierPointList m_listRealPoint; // 实际点链,忽略前后切线点的值
int m_iBezierDegree; // Bezier曲线的次数,二次或者三次,默认值:3
public:
CPDSBezierCurve(void);
CPDSBezierCurve(CPDSBezierCurve& rhs);
virtual ~CPDSBezierCurve(void);
CPDSBezierCurve& operator=(CPDSBezierCurve& rhs);
void Initial(void);
//计算Bezier曲线
//输入参数:
// listCtrlPoint 控制点链,前一个点的next切线点与后一个点的prev切线点计算这两点之间的实际点链
// bClose =true 闭合线,GetTail()与GetHead()之间的部分需要计算,=false 开口线
// iBezierDegree Bezier曲线的次数,=2或者=3
// dMaxError 最大误差值
//输出参数:
// listRealPoint 实际点链
static void CalculateBezierCurve(CPDSBezierPointList& listCtrlPoint, BOOL bClose, int iBezierDegree, double dMaxError, CPDSBezierPointList& listRealPoint);
protected:
//计算两点之间的Bezier曲线
//输入参数:
// ptPrevBezierPoint 前一个Bezier点,它的next切线点参与计算
// ptNextBezierPoint 后一个Bezier点,它的prev切线点参与计算
// iBezierDegree Bezier曲线的次数,=2或者=3
// dMaxError 最大误差值
//输出参数:
// listRealPoint 实际点链
static void CalculateBezierBetweenTwoPoint(CPDSBezierPoint ptPrevBezierPoint, CPDSBezierPoint ptNextBezierPoint, int iBezierDegree, double dMaxError, CPDSBezierPointList& listRealPoint);
//根据给定的参数值计算Bezier点
//输入参数:
// ptPrevBezierPoint 前一个Bezier点,它的next切线点参与计算
// ptNextBezierPoint 后一个Bezier点,它的prev切线点参与计算
// iBezierDegree Bezier曲线的次数,=2或者=3
// dParam 参数值,0<=dParam<=1
//返回值:
// Bezier点
static CPDSBezierPoint CalculateBezierPoint(CPDSBezierPoint ptPrevBezierPoint, CPDSBezierPoint ptNextBezierPoint, int iBezierDegree, double dParam);
//根据计算切点的参数
//输入参数:
// ptPrevBezierPoint 前一个Bezier点,它的next切线点参与计算
// ptNextBezierPoint 后一个Bezier点,它的prev切线点参与计算,这两个点构成了一段Bezier曲线
// iBezierDegree Bezier曲线的次数,=2或者=3
// ptBezierPoint1 该段Bezier曲线上的点1
// ptBezierPoint2 该段Bezier曲线上的点2
//输出参数:
// dParam1 参数,介于1点的参数和2点的参数之间
// dParam2 参数,介于1点的参数和2点的参数之间,并且大于dParam1
//返回值:
// =2 有两个解,=1 有一个解,=0 没有解
static int CalculateTangentParam(CPDSBezierPoint ptPrevBezierPoint, CPDSBezierPoint ptNextBezierPoint, int iBezierDegree, CPDSBezierPoint ptBezierPoint1, CPDSBezierPoint ptBezierPoint2, double& dParam1, double& dParam2);
};
#endif // _PDS_BEZIER_H_

View File

@ -0,0 +1,333 @@
/********************************************************************
:2014/04/14
:PDSFormula.h
:
:CString类型的公式,,使:
(1)CPDSFormula对象,CPDSFormula::SetFormula中所列的参数设置,,
(2)CPDSFormula::AnalyseString完成对字符串的解析,m_listFormulaItem中,,,
,m_dConstNumber保存的就是内部长度值,,m_dConstNumber保存的就是实际值,
,[-/4][0-/4],
m_listCalculateFormula链表,
(3),m_listCalculateFormula链表,/m_dConstNumber中,CalculateResult,
:
(1)PDS中解析公式的算法,///
(2)CPDSFormula::SemanticAnalysis是本次新增,,
:5,5,m_iFormulaType保持一致,,4,5,m_iFormulaType保持一致,3210
(3)m_listLengthVariableName与m_listAngleVariableName,,,,/
(4)public类型,便,使,/
:
*********************************************************************/
#ifndef PDSFORMULA_H
#define PDSFORMULA_H
#include <afxwin.h>
#include <afxtempl.h>
//将函数操作符作为单目运算符,运算级别在括号之后
#define PDS_F_OT_NULL 0x00000000 //
#define PDS_F_OT_ADD 0x00000001 //+ 加
#define PDS_F_OT_SUB 0x00000002 //- 减
#define PDS_F_OT_MULT 0x00000004 //* 乘
#define PDS_F_OT_DIV 0x00000008 /// 除
#define PDS_F_OT_LBRACKET 0x00000010 //( 左括号
#define PDS_F_OT_RBRACKET 0x00000020 //) 右括号
#define PDS_F_OT_SQR 0x00000040 //√ 开方
//下面的操作符使用字符串表示
#define PDS_F_OT_SIN 0x00000080 //sin
#define PDS_F_OT_COS 0x00000100 //cos
#define PDS_F_OT_TG 0x00000200 //tg
#define PDS_F_OT_CTG 0x00000400 //ctg
#define PDS_F_OT_ARCSIN 0x00000800 //arcsin
#define PDS_F_OT_ARCCOS 0x00001000 //arccos
#define PDS_F_OT_ARCTG 0x00002000 //arctg
#define PDS_F_OT_ARCCTG 0x00004000 //arcctg
#define PDS_FORMOULA_STACK_SIZE 100
#define PDS_FOT_MAX_LENGTH 7 //使用字符串表示的操作符中字符串的最大长度
//公式错误信息
enum PDS_ERROR_INFO
{
NoError =0, //没有错误
StackOverflow =1, //栈溢出
ExpressionError =2, //表达式错误(操作符的操作数个数不正确)
NOLBracket =3, //只有右括号,没有左括号
NORBracket =4, //存在没有与左括号匹配的右括号
DivideZero =5, //除数为0
SqrtError =6, //开方数小于0
ArcsinError =7, //反正弦数据错误(数据必须在[-1,1]之间)
ArccosError =8, //反余弦数据错误(数据必须在[-1,1]之间)
StringError =9 //字符串存在错误
};
//公式项
class CPDSFormulaItem
{
public:
int m_iType; //=1 操作符(默认), =2 引用m_pData1/m_pData2, =3 内部长度, =4 常量
int m_iOperatorType; //操作符在m_iType=1时有效,取值范围PDS_F_OT_NULL~PDS_F_OT_ARCCTG
int m_iUnit; //单位,在角度公式下,该变量为-1,m_bOperator=FALSE时有效,默认-1,详见<<PDSUnit.h>>
int m_iPrecision; //单位精度,用于转换成字符串时使用,默认-1,详见<<PDSUnit.h>>
double m_dConstNumber; //常量数值,既可以作为系数也可以作为常变量,单位为m_iUnit,当单位为英寸分数表示时,将分数转换成小数保存
void* m_pData1; //指针1,可根据实际需要指定
void* m_pData2; //指针2
CString m_strText; //字符串,可根据实际需要指定
int m_iIndex; //记录this在链表中的索引值
int m_iPower; //记录this的幂次,若为长度,该值为1,否则为0
public:
CPDSFormulaItem(void);
CPDSFormulaItem(CPDSFormulaItem& rhs);
~CPDSFormulaItem(void);
CPDSFormulaItem& operator=(CPDSFormulaItem& rhs);
BOOL operator==(CPDSFormulaItem& rhs);
BOOL operator!=(CPDSFormulaItem& rhs);
void Init(void);
};
typedef CList<CPDSFormulaItem,CPDSFormulaItem&> CPDSFormulaItemList;
//分析字符串时使用到的类
class CPDSMeasurePos
{
public:
CString m_strMeasureName; //在公式中人体尺寸/尺寸变量的名称
int m_iMeasureIndex; //名称在公式中开始的位置
public:
CPDSMeasurePos(void);
CPDSMeasurePos(CPDSMeasurePos& rhs);
~CPDSMeasurePos(void);
CPDSMeasurePos& operator=(CPDSMeasurePos& rhs);
BOOL operator==(CPDSMeasurePos& rhs);
};
typedef CList<CPDSMeasurePos,CPDSMeasurePos&> CPDSMeasurePosList;
class CPDSFormula
{
public:
BOOL m_bOldFormoula; //=TRUE 旧公式, =FALSE 新公式
int m_iFormulaType; //公式类型, =1 长度公式(默认), =2 角度公式
int m_iDPMM; //长度数据单位:dpmm(每毫米点),用来将字符串计算成内部单位
int m_iUnit; //创建公式时,公式所属长度单位
int m_iPrecision; //与单位对应的长度精确度
CString m_strFormula; //用户输入的公式字符串
int m_iMantissa; //旧公式中尾数对应的系统单位值,目的是为了防止单位转换时出现数据误差,只在旧公式中有效
CStringList m_listLengthVariableName; //表示长度的变量名称
CStringList m_listAngleVariableName; //表示角度的变量名称
CPDSFormulaItemList m_listFormulaItem; //记录通过字符串得到的公式项链(公式项在链表中的顺序与公式字符串一致)
CPDSFormulaItemList m_listCalculateFormula; //存放公式项计算的顺序,用于计算结果
PDS_ERROR_INFO m_ErrorInfo; //公式错误信息
//分析过程中使用的变量
WORD m_iPositionIndex; //分析字符串过程中,指向字符串的当前位置
CPDSFormulaItem m_CurrFormulaItem; //当前分析到的单词
CPDSMeasurePosList m_listMeasurePos; //分析字符串时,字符串中的人体尺寸和尺寸变量名称及其在字符串中位置
//两个栈变量只用于分析字符串的过程
CPDSFormulaItem m_arrFIStack1[PDS_FORMOULA_STACK_SIZE]; //分析过程中存放操作符
int m_iStackTop1; //0..ParserStackSize;当前栈顶位置
CPDSFormulaItem m_arrFIStack2[2 * PDS_FORMOULA_STACK_SIZE]; //分析过程中存放操作数和操作符
int m_iStackTop2; //0..2 * ParserStackSize;当前栈顶位置
public:
CPDSFormula(void);
CPDSFormula(CString strFormula, int iDPMM, int iUnit, int iPrecision, BOOL bOldFormoula, int iFormulaType, CStringList& listLengthVariableName, CStringList& listAngleVariableName);
~CPDSFormula(void);
void Init(void);
//设置函数
void SetFormula(CString strFormula, int iDPMM, int iUnit, int iPrecision, BOOL bOldFormoula, int iFormulaType, CStringList& listLengthVariableName, CStringList& listAngleVariableName);
//判断公式是否正确
//返回值:
// =TRUE 公式正确,=FALSE 公式错误
//说明:
// 判断公式中包含的长度尺寸/角度尺寸是否可以在给定的链表中找到
BOOL IsFormulaRight(void);
//设置变量名称链表
void SetVariableName(CStringList& listLengthVariableName, CStringList& listAngleVariableName);
//将输入的字符串分析成一个一个单词
void AnalyseString(void);
//设置计算链m_listCalculateFormula
void SetCalculateList(void);
//公式项入栈
void Push1(CPDSFormulaItem Item);
//公式项出栈
void Pop1(CPDSFormulaItem& Item);
//公式项入栈
void Push2(CPDSFormulaItem Item);
//判断给定的两个公式项中操作符的优先级
// [输入]Item1,Item2两个公式项
//返回值:
// =0 Item1优先级高于Item2; =1 Item1优先级等于Item2; =2 Item1优先级低于Item2
//说明:
// 该函数中不对公式项是否为操作符进行判断
int JudgePRI(CPDSFormulaItem Item1, CPDSFormulaItem Item2);
//判断给定的公式项中操作符是单目运算还是双目运算()
// [输入] Item 公式项
//返回值:
// =TRUE Item为双目运算符; =FALSE Item单目运算符,即函数运算符
BOOL IsDualOperator(CPDSFormulaItem Item);
//从字符串中得到每个公式项
//返回值:
// =TRUE 表示字符串正确,=FALSE 表示字符串存在错误
// 公式项存放在m_listFormulaItem中
//说明:
//思路:
//1. 先找出字符串中所有的人体尺寸和尺寸变量,并记录下人体尺寸/尺寸变量名称和在字符串中的位置;
//2. 在分析字符串时,先通过位置索引在m_listMeasurePos寻找,到直接返回,找不到通过字符串一个一个分析
//3. 保证第一个公式项为数,并且操作数和操作符(加减乘除)交替
BOOL GetStringFormulaItem(void);
//找出m_strFormula中包含的尺寸名称,将结果输出到listMeasurePos中
void GetMeasureInfo(CPDSMeasurePosList& listMeasurePos);
//得到字符串中的单个单词,即变量名,操作符,数据
//返回值:
// 0 字符串错误,即不是变量名也不是操作符
// 1 到了字符串结尾
// 2 碰到错误字符如:!
// 3 返回值为常量
// 4 返回值为变量
// 5 返回值为符号操作符
// 6 返回值为字符串操作符
//说明:
// 变量名不能是数字开头
// 只有在单位为英制分数的情况下,才进行分数的分析
int NextFormulaItem(void);
//根据索引在m_listMeasurePos中查找对应的MeasurePos
//参数:
// iIndex 索引
// MeasurePos [输出]找到对应的变量位置,返回值为TRUE时有效
//返回值:
// =TRUE 找到, =FALSE 没有找到
//说明:
// 如果找到将找到的信息从m_listMeasurePos移出
// 修改如果同一个位置存在多个名称,取名称最长的
// 人体尺寸/尺寸变量名称存在数字
BOOL FindMeasureIndex(int iIndex, CPDSMeasurePos& MeasurePos);
//判断是否为函数:sin, cos ,tg, ctg, arcsin, arccos, arctg, arcctg
//参数:
// strOperatorName [输出]操作符名称
// iOperatorType [输出]操作符类型
//返回值:
// =TRUE iOperatorType有意义, =FALSE iOperatorType不能使用
BOOL IsFunc(CString &strOperatorName, int &iOperatorType);
//判断是否为变量
//参数:
// strVarName [输出]变量名
//返回值:
// =TRUE strVarName有意义,=FALSE strVarName不能使用
BOOL IsVar(CString &strVarName);
//判断下一个字符是否为操作符
//参数:
// strOperatorName [输出]操作符名称
// iOperatorType [输出]操作符类型
//返回值:
// =TRUE iOperatorType有意义, =FALSE iOperatorType不能使用
//说明:
// 开方在该函数中判断,开方表述方式使用的是符号√
BOOL IsOperator(CString& strOperatorName, int& iOperatorType);
//查找给定的名称是否为人体尺寸
//返回值:
// =TRUE 找到变量, =FALSE 没有找到变量
BOOL FindVariableForName(CString strVarName);
//语义分析
//说明:
// 对解析后的m_listFormulaItem进行语义分析,确定其中哪些数字表示内部单位,哪些表示常量
void SemanticAnalysis(void);
//设置幂次
//参数:
// listFormulaItem 公式项链表
// iPower 幂次,=0 表示常量, =1 表示长度, = 2表示长度*长度,以此类推
void SetPower(CPDSFormulaItemList& listFormulaItem, int iPower);
//检查给定链表的幂次是否等于给定值
//参数:
// listFormulaItem 链表
// iPower 幂次, =0 表示常量, =1 表示长度, =2 表示长度*长度,以此类推
//返回值:
// =TRUE 正确, =FALSE 错误
BOOL CheckPower(CPDSFormulaItemList& listFormulaItem, int iPower);
//判断给定链表中是否含有括号
//参数:
// listFormulaItem 公式链表
// iIndexL [输出]最左边的括号在链表中的索引值
// iIndexR [输出]与iIndexL对应的右括号在链表中的索引值
//返回值:
// =TRUE 有括号,(iIndexL,iIndexR)数据有效, =FALSE 没有括号,输出变量无效
BOOL HaveBracket(CPDSFormulaItemList& listFormulaItem, int& iIndexL, int& iIndexR);
//排列组合
//参数:
// iMaxCount 总数
// iCount 被提取出的数量
// alIndex [输出]排列组合链表,其中的alIndex[].GetCount()=iCount,索引值从0开始,从大到小排列
void Permutation(int iMaxCount, int iCount, CArray<CList<int,int>,CList<int,int> >& alIndex);
//获取给定链表的幂次,如果计算失败则返回INT_MAX
//特别说明:什么是计算失败?
// 例如:A*B+C由加号连接的每一项幂次不等,sqrt(A+B)用来开方的数据不是常数或者2的整数倍,sin(A)三角函数的参数不是常量,等等
//返回值:
// 幂次,=0 表示常量, =1 表示长度, = 2表示长度*长度,以此类推
int GetPower(CPDSFormulaItemList& listFormulaItem);
//计算结果
//特别说明:
// 调用本函数之前,要将设置m_listFormulaItem链表,将人体尺寸的实际值设置到m_dConstNumber中,切记!!!
//返回值:
// 如果this是长度公式,那么返回值表示长度,四舍五入后可即为内部长度,如果this是角度公式,那么返回值就是角度
double CalculateResult(void);
//计算旧公式
double CalculateOldFormula(void);
//计算新公式
double CalculateNewFormula(void);
//双目操作符运算
//参数:
// iOperator 操作符
// dValue1 第一操作数
// dValue2 第二操作数
//返回值:
// 结果项(数据公式项)
CPDSFormulaItem CalculateValue1(int iOperator, double dValue1, double dValue2);
//单目操作符运算
//参数:
// iOperator 操作符
// dValue1 第一操作数
//返回值:
// 结果项(数据公式项)
CPDSFormulaItem CalculateValue2(int iOperator, double dValue1);
};
#endif // PDSFORMULA_H

View File

@ -0,0 +1,236 @@
// PDSLocate.h
#if !defined(PDSLocate_h)
#define PDSLocate_h
#include <afxwin.h>
#include <afxtempl.h>
#define PDSLOCATE_SAMEPOINTERROR 5.0; // 判断两个点相等的最大误差值,<=该值的点认为是同一个
//查找点的位置
//输入参数:
// listPoint 点链
// ptPoint 给定的点
//返回值:
// 在listPoint中与ptPoint坐标相同的点的位置,
// 如listPoint中没有与ptPoint的坐标相同的点则返回NULL.
POSITION FindPointAtPointList(CList<CPoint,CPoint>& listPoint,CPoint ptPoint);
//查找点的位置
//输入参数:
// listPoint 点链
// ptPoint 给定的点
// dMaxError 最大误差,若<0则根据CONST_SAME_POINT_ERROR进行查找
//返回值:
// 在listPoint中与ptPoint的距离小于dMaxError的最近点的位置,
// 如listPoint中没有与ptPoint的距离小于dMaxError的点则返回NULL.
POSITION FindPointAtPointList(CList<CPoint,CPoint>& listPoint,CPoint ptPoint,double dMaxError);
//判断一点在多边形中的位置
//特别说明:
// [20170830 syf]新增dSamePointError变量
//输入参数:
// listPolygon 多边形的点链
// ptPoint 给定的点
// dSamePointError 判断两个点相等的误差值,<=该值的点认为是同一个
// >0 直接使用该值做判断
// =0 坐标完全相等的点才是同一个,否则不是
// <0 本函数自动使用 CONST_SAME_POINT_ERROR 做判断
//输出参数:
// posPrev 前点的位置,若为NULL,表示pos前面的所有点都不满足dSamePointError条件
// pos ptPoint的位置(该位置的点未必等于ptPoint,满足dSamePointError条件)
// posNext 后点的位置,若为NULL,表示pos后面的所有点都不满足dSamePointError条件
//返回值:
// =true 匹配成功(此时的posPrev与posNext可能为NULL),=false 匹配失败
BOOL PointPosOfPolygon(CList<CPoint,CPoint>& listPolygon,CPoint ptPoint,POSITION& posPrev,POSITION& pos,POSITION& posNext,double dSamePointError = 0.0);
//判断一点在多边形中的位置,并输出前后点
//输入参数:
// listPolygon 多边形的点链
// ptPoint 给定的点
// dSamePointError 判断两个点相等的误差值,<=该值的点认为是同一个
// >0 直接使用该值做判断
// =0 坐标完全相等的点才是同一个,否则不是
// <0 本函数自动使用 CONST_SAME_POINT_ERROR 做判断
//输出参数:
// ptPrev 前点
// ptNext 后点
//返回值:
// =true 计算成功,=false 计算失败
BOOL PointPosOfPolygon(CList<CPoint,CPoint>& listPolygon,CPoint ptPoint,CPoint& ptPrev,CPoint& ptNext,double dSamePointError = 0.0);
//判断一点在折线中的位置
//特别说明:
// [20170830 syf]新增dSamePointError变量
//输入参数:
// listPolyline 折线的点链
// ptPoint 给定的点
// dSamePointError 判断两个点相等的误差值,<=该值的点认为是同一个
// >0 直接使用该值做判断
// =0 坐标完全相等的点才是同一个,否则不是
// <0 本函数自动使用 CONST_SAME_POINT_ERROR 做判断
//输出参数:
// posPrev 前点的位置,若为NULL,表示pos前面的所有点都不满足dSamePointError条件
// pos ptPoint的位置(该位置的点未必等于ptPoint,满足dSamePointError条件)
// posNext 后点的位置,若为NULL,表示pos后面的所有点都不满足dSamePointError条件
//返回值:
// =true 匹配成功(此时的posPrev与posNext可能为NULL),=false 匹配失败
BOOL PointPosOfPolyline(CList<CPoint,CPoint>& listPolyline,CPoint ptPoint,POSITION& posPrev,POSITION& pos,POSITION& posNext,double dSamePointError = 0.0);
//求多边形中距离ptPoint最近的位置
//输入参数:
// listPolygon 多边形的点链
// dMaxError 最大误差
// ptPoint 给定的点
//返回值:
// 如果ptPoint与多边形的最近距离 <= dMaxError,则返回true,其中:
// ptFixPoint 多边形中距离ptPoint最近的位置
// dDistance 实际距离
// pos 是ptPoint的位置,如ptPoint不是点链上的点则pos=NULL.
// posPrev,posNext 是ptPoint的前后点的位置
// 如果ptPoint与多边形的最近距离 > dMaxError,则返回false.
BOOL FixPointAtPolygon(CList<CPoint,CPoint>& listPolygon,double dMaxError,CPoint ptPoint,
CPoint& ptFixPoint,double& dDistance,
POSITION& posPrev,POSITION& pos,POSITION& posNext);
//求折线中距离ptPoint最近的位置
//输入参数:
// listPolyline 折线的点链
// ptPoint 给定的点
//返回值:
// 如果ptPoint与折线的最近距离 <= dMaxError,则返回true,其中:
// ptFixPoint 折线中距离ptPoint最近的位置
// dDistance 实际距离
// pos 是ptPoint的位置,如ptPoint不是点链上的点则pos=NULL.
// posPrev,posNext 是ptPoint的前后点的位置
// 如果ptPoint与折线的最近距离 > dMaxError,则返回false.
BOOL FixPointAtPolyline(CList<CPoint,CPoint>& listPolyline,double dMaxError,CPoint ptPoint,
CPoint& ptFixPoint,double& dDistance,
POSITION& posPrev,POSITION& pos,POSITION& posNext);
//求线段中距离ptPoint最近的位置
//输入参数:
// ptPointS,ptPointE 线段的点
// ptPoint 给定的点
//输出参数:
// ptFixPoint 线段中距离ptPoint最近的位置
// dDistance 实际距离
//返回值:
// 如果ptPoint与线段的最近距离 <= dMaxError,则返回true,其中:
// ptFixPoint 线段中距离ptPoint最近的位置
// dDistance 实际距离
// 如果ptPoint与折线的最近距离 > dMaxError,则返回false.
BOOL FixPointAtLineSegment(CPoint ptPointS,CPoint ptPointE,double dMaxError,CPoint ptPoint,
CPoint& ptFixPoint,double& dDistance);
//求点ptPoint与直线的最近距离点.
//注意:与FixPointAtLineSegment的区别是FixPointAtLineSegment求线段的最近点.
//输入参数:
// ptPointS,ptPointE 直线的点
// ptPoint 给定的点
//输出参数:
// ptFixPoint 直线中距离ptPoint最近的位置
//返回值:
// ptPoint与直线的距离
double FixPointAtLine(CPoint ptPointS,CPoint ptPointE,CPoint ptPoint,CPoint& ptFixPoint);
//计算距离点
//输入参数:
// listPolygon
// ptPointS
// dDistance >=0 计算从ptPointS开始往后距离dDistance的点,
// <0 计算从ptPointS开始往前距离-dDistance的点.
//输出参数:
// ptPoint
//返回值:
// =true 成功计算出距离点,否则false
BOOL GetDistancePointOfPolygon(CList<CPoint,CPoint>& listPolygon,CPoint ptPointS,double dDistance,CPoint& ptPoint);
//计算距离点
//输入参数:
// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米)
// listPolyline
// ptPointS
// dDistance >=0 计算从ptPointS开始往后距离dDistance的点,
// <0 计算从ptPointS开始往前距离-dDistance的点.
//输出参数:
// ptPoint
//返回值:
// =true 成功计算出距离点,否则false
BOOL GetDistancePointOfPolyline(int iDPMM,CList<CPoint,CPoint>& listPolyline,CPoint ptPointS,double dDistance,CPoint& ptPoint);
BOOL GetDistancePointOfPolyline(CList<CPoint,CPoint>& listPolyline,POSITION pos,double dDistance,CPoint& ptPoint);
//计算距离点
//该函数与GetDistancePointOfPolyline(...)的区别在于当搜索长度不够时GetDistancePointOfPolylineEx可以延长到线外
//输入参数:
// listPolyline
// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米)
// ptPointS
// dDistance >=0 计算从ptPointS开始往后距离dDistance的点,
// <0 计算从ptPointS开始往前距离-dDistance的点.
//输出参数:
// ptPoint
//返回值:
// =true 成功计算出距离点,否则false
BOOL GetDistancePointOfPolylineEx(int iDPMM,CList<CPoint,CPoint>& listPolyline,CPoint ptPointS,double dDistance,CPoint& ptPoint);
//计算距离点
//输入参数:
// listPolyline
// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米)
// pos
// dDistance >=0 计算从ptPointS开始往后距离dDistance的点,
// <0 计算从ptPointS开始往前距离-dDistance的点.
//输出参数:
// ptPoint
//返回值:
// =true 成功计算出距离点,否则false
BOOL GetDistancePointOfPolylineEx(int iDPMM,CList<CPoint,CPoint>& listPolyline,POSITION pos,double dDistance,CPoint& ptPoint);
//计算距离点
//输入参数:
// listPolyline
// dDistance >=0 计算从链头开始往后距离dDistance的点,
// <0 计算从链尾开始往前距离-dDistance的点.
//输出参数:
// ptPoint
// posPrev ptPoint的前点位置
// pos ptPoint的位置,若=NULL,则ptPoint不是listPolyline中的点,否则是listPolyline中的点
// posNext ptPoint的后点位置
//返回值:
// =true 成功计算出距离点,否则false
BOOL GetDistancePointOfPolyline(CList<CPoint,CPoint>& listPolyline,double dDistance,CPoint& ptPoint,POSITION &posPrev,POSITION &pos,POSITION &posNext);
//确定一点在线上的位置.
//特别说明:该函数不检查点是否在线上!!!
//输入参数:
// listPoint 已有的点
// ptPoint 需确定的点
//输出参数:
// pos ptPoint的插入位置
//返回值:
// ptPoint的插入序号
int InsertPointAtLine(CList<CPoint,CPoint> &listPoint,CPoint ptPoint,POSITION &pos);
//计算切线点
//输入参数:
// listPolygon
// ptPointS
// dDistance >=0 计算从ptPointS开始往后最短距离dDistance的切线点,
// <0 计算从ptPointS开始往前最短距离-dDistance的切线点.
//输出参数:
// ptPoint
//返回值:
// =true 成功计算出切线点,否则false
BOOL GetTangentPointOfPolygon(CList<CPoint,CPoint>& listPolygon,CPoint ptPointS,double dDistance,CPoint& ptPoint);
//计算切线点
//输入参数:
// listPolyline
// ptPointS
// dDistance >=0 计算从ptPointS开始往后最短距离dDistance的切线点,
// <0 计算从ptPointS开始往前最短距离-dDistance的切线点.
//输出参数:
// ptPoint
//返回值:
// =true 成功计算出切线点,否则false
BOOL GetTangentPointOfPolyline(CList<CPoint,CPoint>& listPolyline,CPoint ptPointS,double dDistance,CPoint& ptPoint);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
// PDSMathExtern.h
#if !defined(PDSMathExtern_h)
#define PDSMathExtern_h
extern CRect g_rectView; //显示窗口的客户区大小,加入该变量的原因是因为显示字符串时需要确定窗口大小,该大小不能用wglGetCurrentDC(),CDC::GetWindow(),CWnd::GetClientRect(...)
#endif

View File

@ -0,0 +1,8 @@
// PDSMathGlobal.h
#if !defined(PDSMathGlobal_h)
#define PDSMathGlobal_h
CRect g_rectView; //显示窗口的客户区大小,加入该变量的原因是因为显示字符串时需要确定窗口大小,该大小不能用wglGetCurrentDC(),CDC::GetWindow(),CWnd::GetClientRect(...)
#endif

View File

@ -0,0 +1,503 @@
/********************************************************************
:2017317
:PDSNurbs.h
:
:B样条
:
*********************************************************************/
#ifndef _PDS_NURBS_H_
#define _PDS_NURBS_H_
#include <math.h>
#include <afxwin.h>
#include <afxtempl.h>
const double PDS_NURBS_ZERO = 0.000001; // 小于该数字的值认为等于0
//全局函数
//判断两个双精度数是否相等
BOOL PDSNurbs_IsEqual(double d1, double d2);
//判断两个双精度数是否不等
BOOL PDSNurbs_NotEqual(double d1, double d2);
//判断给定的双精度数是否等于0
BOOL PDSNurbs_EqualZero(double d);
//判断给定的双精度数是否不为0
BOOL PDSNurbs_NotEqualZero(double d);
//计算非均匀有理B样条使用的点
class CPDSNurbsPoint : public CObject
{
public:
double x;
double y;
double z;
double weight; /* 权重,默认值:1
// 举例:(1,1,1,1)等同于(4,4,4,4),当为某一个点设置权重的时候,一定要将xyz分量全都除以weight才能保证位置不变 */
double knot; // 该点对应的节点数值,默认值:0
int type; // 类型,=1 转折点,=0 曲线点,默认值:0,[20180322 syf]增加该变量
// 当this表示控制点时,启用该变量,那么在反求样条曲线的控制点链时,从转折点出断开,该变量不参与等号operator==的判断
public:
CPDSNurbsPoint(void);
CPDSNurbsPoint(CPDSNurbsPoint& rhs);
CPDSNurbsPoint(CPoint ptPoint);
CPDSNurbsPoint(double x, double y, double z = 0.0, double weight = 1.0);
virtual ~CPDSNurbsPoint(void);
CPDSNurbsPoint& operator=(CPDSNurbsPoint& rhs);
CPDSNurbsPoint operator+(CPDSNurbsPoint& rhs);
CPDSNurbsPoint operator-(CPDSNurbsPoint& rhs);
void operator+=(CPDSNurbsPoint& rhs);
BOOL operator==(CPDSNurbsPoint& rhs);
void Initial(void);
//将this的坐标转换为CPoint并返回
CPoint GetPoint(void);
//设置this的坐标
void SetPoint(CPoint ptPoint);
//乘以给定的数值
void Multiple(double dParam);
//除以给定的数值
void Divide(double dParam);
//将每个分量除以权重,得到规范后的坐标
void DivideWeight(void);
};
//带类型的点的链表
class CPDSNurbsPointList : public CList<CPDSNurbsPoint,CPDSNurbsPoint>
{
public: //扩展的变量
public: //扩展的方法
CPDSNurbsPointList& operator=(CPDSNurbsPointList& rhs); //赋值
CPDSNurbsPoint& operator[](int iIndex); //根据索引值检索,不可越界
//根据listPoint设置this
//特别说明:
// (1)this中每个点z=0,weight=1
void SetPoint(CList<CPoint,CPoint>& listPoint);
//将this的数据输出至listPoint
void GetPoint(CList<CPoint,CPoint>& listPoint);
POSITION AddWithoutDuplicate(CPDSNurbsPoint ptNurbsPoint, BOOL bAddTail = TRUE);
void AddWithoutDuplicate(CPDSNurbsPointList& listNurbsPoint, BOOL bAddTail = TRUE);
//根据给定的节点数值,查找索引值
int FindKnotIndex(double dKnot);
//获取长度
double GetLength(void);
//将this翻转
void Reverse(void);
};
//节点链表
//对于一条NURBS曲线来说(3次),该链表的长度应该等于控制点链长度+4
class CPDSNurbsKnotList : public CList<double,double>
{
public: //扩展的变量
public: //扩展的方法
CPDSNurbsKnotList& operator=(CPDSNurbsKnotList& rhs); //赋值
double& operator[](int iIndex); //根据索引值检索,不可越界
//根据listKnot设置this
void SetKnot(CList<double,double>& listKnot);
//将this的数据输出至listKnot
void GetKnot(CList<double,double>& listKnot);
//添加新的节点,并且相邻的节点不能相同
POSITION AddWithoutDuplicate(double dKnot, BOOL bAddTail = TRUE);
//查找给定的节点在this中的重复次数
int FindRepeatTime(double dKnot);
};
//矩阵
class CPDSMatrix : public CObject
{
protected:
double** m_dMatrix; // 二维数组的指针,为this私有,不同的对象之间不能共享m_dMatrix
int m_iRowCount; // 行数
int m_iColumnCount; // 列数
public:
CPDSMatrix(void);
CPDSMatrix(CPDSMatrix& rhs);
virtual ~CPDSMatrix(void);
CPDSMatrix& operator=(CPDSMatrix& rhs);
CPDSMatrix operator*(CPDSMatrix& rhs); // this的列数必须等于rhs的行数,否则不予计算
//初始化,用于释放内存
void Initial(void);
//设置矩阵的大小
//特别说明:
// 在使用矩阵的数据之前,一定要首先设置大小
void SetSize(int iRowCount, int iColumnCount);
//获取矩阵的数据
void GetMatrix(double**& dMatrix, int& iRowCount, int& iColumnCount);
//获取二维数组的指针
double** GetArray(void);
//获取逆矩阵
//特别说明:
// (1)this必须是方阵
// (2)本函数根据初等变换计算
CPDSMatrix GetInverseMatrix(void);
//输出调试信息
void OutputDebugInfo(void);
//将两行的数据加起来
//输入参数:
// dArray1 数组1,它的数据被增加
// dArray2 数组2,其中的数据被加到dArray1,自身的数据不改变
// iCount 两个数组的长度
// dProp 比例值,dArray2[]*dProp被增加到dArray1
void AddRow(double* dArray1, double* dArray2, int iCount, double dProp = 1.0);
//将数组中的每一项除以指定的参数
//输入参数:
// dArray 数组
// iCount 数组的长度
// dParam 参数,数组的每一项都要除以该值
void DivideRow(double* dArray, int iCount, double dParam);
};
//NURBS曲线类
//特别说明:
// (1)特指3次非均匀有理B样条曲线
// (2)什么是型值点?
// 指的是经过的点,在我们的系统中称之为"控制点",实际上规范化的定义叫做型值点
// 型值点也叫做拟合点
// 英文名:data point
// (3)什么是控制点?
// 用于计算实际点链的点,部分版师形象的称之为"手臂",曲线只会经过第一点与最后一点,不会经过中间的其他点
// 控制点链,也叫做特征多边形,它是非均匀有理B样条的凸包,曲线不会超过它的范围
// 英文名:control point
// (4)NURBS曲线的方程由递推公式给出,详见相关文档
// (5)什么是节点?
// 一组单调不减的数字,标识每一个control point的作用范围,对于相同的特征多边形来说,选择不同的节点,最终的效果不同
// (6)节点有多少个?
// 对于degree=3来说,节点个数=特征多边形个数+degree+1=特征多边形个数+4
// 并且前degree+1=4个节点相等(未必等于0),末尾degree+1=4个节点相等(未必等于1)
// 例如:{A,A,A,A,B,C,D,E,E,E,E}就是7个control point所形成的节点,每一个{A,B,C,D,E}都对应于一个data point,而这个data point在屏幕上可以看到的点
// 如果{A,B,C,D,E}构成等差数列,曲线叫做均匀有理B样条,否则叫做非均匀有理B样条
// (7)如果只有3个控制点,那么只能计算2次曲线
// (8)如果只有2个控制点,那么只能得到一条线段
class CPDSNurbsCurve : public CObject
{
public:
//将4条链表封装在一起,方便写代码,NURBS曲线的计算函数并不使用成员变量
CPDSNurbsPointList m_listCtrlPoint; // 控制点链,也叫特征多边形,最终的实际点链只经过头尾点,而不经过中间的其他点
CPDSNurbsKnotList m_listKnot; // 节点链表,长度等于m_listCtrlPoint.GetCount()+4
CPDSNurbsPointList m_listDataPoint; // 型值点链,经过的那些点
CPDSNurbsPointList m_listRealPoint; // 实际点链,插值后的点
public:
CPDSNurbsCurve(void);
CPDSNurbsCurve(CPDSNurbsCurve& rhs);
virtual ~CPDSNurbsCurve(void);
CPDSNurbsCurve& operator=(CPDSNurbsCurve& rhs);
void Initial(void);
//根据型值点计算开口线
//输入参数:
// listDataPoint 型值点
// dMaxError 最大误差值
// bTangentH =true 头点有切线,=false 头点没有切线
// ptTangentPointH 头点的切线方向,指的是实际点链GetPrev的方向
// bTangentT =true 尾点有切线,=false 尾点没有切线
// ptTangentPointT 尾点的切线方向,指的是实际点链GetNext的方向
//输出参数:
// listOutputPoint 实际点链
//返回值:
// =true 计算成功,=false 计算失败
BOOL Calculate_DataPoint_Open(CList<CPoint,CPoint>& listDataPoint, double dMaxError, CList<CPoint,CPoint>& listOutputPoint, BOOL bTangentH = FALSE, CPoint ptTangentPointH = CPoint(0,0), BOOL bTangentT = FALSE, CPoint ptTangentPointT = CPoint(0,0));
//根据型值点和切线点计算闭合线
//输入参数:
// listDataPoint 型值点,尾点可以等于头点,也可以不等,本函数自动处理
// dMaxError 最大误差值
//输出参数:
// listOutputPoint 实际点链,输出时尾点与头点重合
//返回值:
// =true 计算成功,=false 计算失败
BOOL Calculate_DataPoint_Close(CList<CPoint,CPoint>& listDataPoint, double dMaxError, CList<CPoint,CPoint>& listOutputPoint);
//根据实际点链反求型值点
//输入参数:
// listOldPoint 旧的实际点链
// listDataPoint 型值点,如果输入时不为空,表示必须经过这些点
// dSplineError 计算样条曲线的最大误差值
// dMaxError 反求之后的曲线,与listOldPoint的最大误差值
// bTangentH =true 头点有切线,=false 头点没有切线
// ptTangentPointH 头点的切线方向,指的是实际点链GetPrev的方向
// bTangentT =true 尾点有切线,=false 尾点没有切线
// ptTangentPointT 尾点的切线方向,指的是实际点链GetNext的方向
//输出参数:
// listDataPoint 型值点,如果输入时不为空,表示必须经过这些点
//返回值:
// =true 计算成功,=false 计算失败
BOOL ReCalculate_DataPoint(
CList<CPoint,CPoint>& listOldPoint, CList<CPoint,CPoint>& listDataPoint, double dSplineError, double dMaxError,
BOOL bTangentH = FALSE, CPoint ptTangentPointH = CPoint(0,0), BOOL bTangentT = FALSE, CPoint ptTangentPointT = CPoint(0,0));
//根据给定的控制点链与节点链计算实际点链
//特别说明:
// (1)本函数将会自动设置m_listCtrlPoint与m_listKnot,无需事先设置
// (2)输入时要保证listKnot.GetCount()=listCtrlPoint.GetCount()+4,这是NURBS曲线的要求,并且要保证节点数的正确性:单调不减,否则计算的结果就是错误的
// (3)从DXF等文件中读入的NURBS曲线,可以直接调用本函数来计算实际点链
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
// dMaxError 最大误差值
//输出参数:
// listDataPoint 型值点链,即:曲线经过的那些点
// listRealPoint 实际点链
//返回值:
// =true 计算成功,=false 计算失败
BOOL Calculate_CtrlPoint(CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot, double dMaxError, CPDSNurbsPointList& listDataPoint, CPDSNurbsPointList& listRealPoint);
//根据给定的控制点链与节点链计算型值点
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
//输出参数:
// listDataPoint 型值点链,即:曲线经过的那些点
//返回值:
// =true 计算成功,=false 计算失败
BOOL Calculate_CtrlPoint(CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot, CPDSNurbsPointList& listDataPoint);
protected:
//根据给定的型值点计算控制点(计算开口线)
//输入参数:
// listDataPoint 型值点链,指的是曲线经过的那些点
// bTangentH =true 头点有切线,=false 头点没有切线
// ptTangentPointH 头点的切线方向,指的是实际点链GetPrev的方向
// bTangentT =true 尾点有切线,=false 尾点没有切线
// ptTangentPointT 尾点的切线方向,指的是实际点链GetNext的方向
//输出参数:
// listCtrlPoint 控制点链,它是NURBS曲线的控制多边形或者说特征多边形,其长度=listDataPoint.GetCount()+2
// listKnot 节点链表
void CalculateCtrlPoint_Open(CPDSNurbsPointList& listDataPoint, BOOL bTangentH, CPDSNurbsPoint ptTangentPointH, BOOL bTangentT, CPDSNurbsPoint ptTangentPointT, CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot);
//根据给定的型值点计算控制点(闭合线)
//特别说明:
// (1)listInputPoint的尾点可以等于头点,也可以不等于
// (2)最终输出的listCtrlPoint头尾点相等,表示再次回到头点上
//输入参数:
// listInputPoint 型值点链,指的是曲线经过的那些点
//输出参数:
// listCtrlPoint 控制点链,它是NURBS曲线的控制多边形或者说特征多边形
// listKnot 节点链表
void CalculateCtrlPoint_Close(CPDSNurbsPointList& listInputPoint, CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot);
//获取给定线段的长度
//输入参数:
// listCtrlPoint 控制点链
// iIndex 段的索引值,指的是(listCtrlPoint[iIndex], [iIndex+1])所形成的线段,例如:第0段指的是([0],[1])
//返回值:
// 长度,如果传入的索引值越界则返回0
double GetSegmentLength(CPDSNurbsPointList& listCtrlPoint, int iIndex);
//查找给定节点的索引值
//特别说明:
// (1)如果给定的节点位于[listKnot[i],listKnot[i+1]),那么返回i
// (2)注意可以等于listKnot[i],一定要严格小于[i+1]
// (3)从NURBS曲线的定义可以知道,由于{A,A,A,A...}前四个数据重复,所以该函数的返回值从3开始
//输入参数:
// listKnot 节点链表,单调不减
// dKnot 节点
//返回值:
// 索引值,从0开始,若为-1则表示查找失败
int FindKnotIndex(CPDSNurbsKnotList& listKnot, double dKnot);
//根据给定的节点数值,计算B样条基函数的值
//特别说明:
// (1)这是一个递归函数,需要调用iDegree-1的数据进行计算
// (2)在计算的过程中可能出现分母为0/0的情况,此处我们定义0/0=0
//输入参数:
// listKnot 节点链表
// dKnot 给定的节点数值
// iIndex dKnot所在的索引值
// iDegree NURBS曲线的次数,一般等于3,如果只有三个控制点,那么只能生成2次曲线
//返回值:
// B样条基函数的值
double CalculateKnot(CPDSNurbsKnotList& listKnot, double dKnot, int iIndex, int iDegree);
//根据给定的节点数值,计算NURBS曲线上的点坐标
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
// dKnot 给定的节点数值
// iDegree 样条曲线的次数
//返回值:
// 计算出的点位置
CPDSNurbsPoint CalculateNurbsPoint(CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot, double dKnot, int iDegree);
//根据给定的两个节点,计算弦高
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
// ptPrevNurbsPoint 前一个点的坐标
// dPrevKnot 前一个点的节点
// ptNextNurbsPoint 后一个点的坐标
// dNextKnot 后一个点的节点
// iDegree 样条曲线的次数
//返回值:
// 弦高
double CalculateChordHeight(
CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot,
CPDSNurbsPoint ptPrevNurbsPoint, double dPrevKnot,
CPDSNurbsPoint ptNextNurbsPoint, double dNextKnot, int iDegree);
//根据给定的数量计算等分后的节点
//特别说明:
// (1)若dPrevKnot=dNextKnot,那么输出链表为空
//输入参数:
// dPrevKnot 前一个节点
// dNextKnot 后一个节点
// iCount 给定节点之间的点数量,若=2,表示有2个点,输出链表为{dPrevKnot,节点1,节点2,dNextKnot}
//输入参数:
// listDivideKnot 分割后的节点链表,包括dPrevKnot与dNextKnot
void CalculateDivideKnot(double dPrevKnot, double dNextKnot, int iCount, CPDSNurbsKnotList& listDivideKnot);
//计算两个节点之间的实际点链
//特别说明:
// (1)若dPrevKnot=dNextKnot,那么输出链表只有一个点
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
// dPrevKnot 前一个节点
// dNextKnot 后一个节点
// iDegree 样条曲线的次数
// dMaxError 最大误差值,即:每条线段的弦高不能超过该值
//输出参数:
// listOutputPoint 实际点链,包含dPrevKnot与dNextKnot对应的点
void CalculateNurbsPoint_BetweenTwoKnot(
CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot, double dPrevKnot, double dNextKnot,
int iDegree, double dMaxError, CPDSNurbsPointList& listOutputPoint);
//根据等分后的节点链表计算实际点链
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
// listDivideKnot 等分后的节点链表
// iDegree 样条曲线的次数
// dMaxError 最大误差值,即:每条线段的弦高不能超过该值
//输出参数:
// listOutputPoint 实际点链,如果计算成功,则不为空,如果计算失败,该链表为空
void CalculateNurbsPoint_UseDivideKnot(
CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot, CPDSNurbsKnotList& listDivideKnot,
int iDegree, double dMaxError, CPDSNurbsPointList& listOutputPoint);
//计算中点
//输入参数:
// ptPrevNurbsPoint 前一个点,将其weight去掉之后再求解
// ptNextNurbsPoint 后一个点,将其weight去掉之后再求解
//返回值:
// 中点,它的weight=1
CPDSNurbsPoint GetMiddleNurbsPoint(CPDSNurbsPoint ptPrevNurbsPoint, CPDSNurbsPoint ptNextNurbsPoint);
//计算两个点之间的距离
//输入参数:
// ptPrevNurbsPoint 前一个点,将其weight去掉之后再求解
// ptNextNurbsPoint 后一个点,将其weight去掉之后再求解
//返回值:
// 距离
double TwoNurbsPointLength(CPDSNurbsPoint ptPrevNurbsPoint, CPDSNurbsPoint ptNextNurbsPoint);
//根据给定点在线段上的参数,计算该点
CPDSNurbsPoint ParamToNurbsPoint(CPDSNurbsPoint ptPrevNurbsPoint, CPDSNurbsPoint ptNextNurbsPoint, double dParam);
//查找链表中的哪个点与给定点最近,返回其索引值
//输入参数:
// listPoint 链表
// ptSelPoint 给定点
//输出参数:
// dMinDistance 最近距离
//返回值:
// 索引值,从0开始
int FindNearestIndex(CList<CPoint,CPoint>& listPoint, CPoint ptSelPoint, double& dMinDistance);
//以累加弦长的方式生成节点
//输入参数:
// listDataPoint 型值点,至少3个点
//输出参数:
// listUniqueKnot 不重复的节点链表
// listKnot 重复的节点链表
void GenerateKnot_ChordLength(CPDSNurbsPointList& listDataPoint, CPDSNurbsKnotList& listUniqueKnot, CPDSNurbsKnotList& listKnot);
//计算垂足在矢量上的参数值
//输入参数:
// ptNurbsPointS 矢量S
// ptNurbsPointE 矢量E
// ptNurbsPoint1 给定点
//返回值:
// 垂足点在矢量上的参数,如果SE点重合则直接返回0
double GetNurbsPointVerticalParam(CPDSNurbsPoint ptNurbsPointS, CPDSNurbsPoint ptNurbsPointE, CPDSNurbsPoint ptNurbsPoint1);
//获取给定点到链表的距离
//输入参数:
// ptNurbsPoint1 给定点
// listNurbsPoint 链表
//返回值:
// 距离
double DistanceOfNurbsPointPloyline(CPDSNurbsPoint ptNurbsPoint1, CPDSNurbsPointList& listNurbsPoint);
//查找链表中的哪个点与给定点最近
//输入参数:
// ptNurbsPoint1 给定点
// listNurbsPoint 链表
//输出参数:
// dDistance 最近距离
//返回值:
// 最近点
CPDSNurbsPoint FindNearestNurbsPoint(CPDSNurbsPoint ptNurbsPoint1, CPDSNurbsPointList& listNurbsPoint, double& dDistance);
//判断新链表与旧链表的距离是否小于误差值
//输入参数:
// listOldPoint 旧的链表
// listNewPoint 新的链表
// dMaxError 最大误差值
//返回值:
// =true 新链表的每个点,到旧链表的距离都小于或者等于误差值,=false 某个点的距离大于误差值
BOOL DistanceSmallerThanError(CList<CPoint,CPoint>& listOldPoint, CList<CPoint,CPoint>& listNewPoint, double dMaxError);
//根据给定的控制点链与节点链计算实际点链,并且实际点链与旧点链的距离小于误差
//输入参数:
// listCtrlPoint 控制点链
// listKnot 节点链表
// iSelIndex 给定的索引值,从0开始,从该索引值开始,向前和向后逐段计算,并比较偏差,该索引值附近的偏差是最大的
// dSplineError 计算NURBS曲线的最大误差值
// dMaxError 实际点链与旧点链的最大误差值
// listOldPoint 旧点链
//返回值:
// =true 计算成功,每个点都小于等于误差值,=false 计算失败,某个点的距离大于误差值
BOOL Calculate_CtrlPoint_SmallerThanError(CPDSNurbsPointList& listCtrlPoint, CPDSNurbsKnotList& listKnot, int iSelIndex, double dSplineError, double dMaxError, CList<CPoint,CPoint>& listOldPoint);
};
#endif // _PDS_NURBS_H_

View File

@ -0,0 +1,87 @@
/********************************************************************
:2015115
:PDSReadWriteFile.h
:
:
:
*********************************************************************/
#ifndef PDSREADWRITEFILE_H
#define PDSREADWRITEFILE_H
#include "PDSMath.h"
//将字体lfFont格式化成字符串
CString PDSFormatFontString(LOGFONT lfFont);
//将strFont中的信息写入到lfFont字体中
void PDSFormatStringFont(LOGFONT& lfFont, CString strFont);
//写入整型数
void PDSWriteInt(CString strAppName, CString strKeyName, int iData, CString strFileName);
//写入布尔值
void PDSWriteBool(CString strAppName, CString strKeyName, BOOL bData, CString strFileName);
//写入颜色
void PDSWriteColor(CString strAppName, CString strKeyName, COLORREF crColor, CString strFileName);
//写入浮点数
void PDSWriteFloat(CString strAppName, CString strKeyName, float fData, CString strFileName);
//写入双精度数
void PDSWriteDouble(CString strAppName, CString strKeyName, double dData, CString strFileName);
//写入字符串
void PDSWriteString(CString strAppName, CString strKeyName, CString strText, CString strFileName);
//写入字体
void PDSWriteFont(CString strAppName, CString strKeyName, LOGFONT lfFont, CString strFileName);
//写入整型数链表
void PDSWriteListInt(CString strAppName, CString strKeyName, CList<int,int>& listData, CString strFileName);
void PDSWriteArrayInt(CString strAppName, CString strKeyName, CArray<int,int>& arryData, CString strFileName);
//写入双精度链表
void PDSWriteListDouble(CString strAppName, CString strKeyName, CList<double,double>& listData, CString strFileName);
//写入双精度数组
void PDSWriteArrayDouble(CString strAppName, CString strKeyName, CArray<double,double>& arryData, CString strFileName);
//写入点链
void PDSWriteListPoint(CString strAppName, CString strKeyName, CList<CPoint,CPoint>& listPoint, CString strFileName);
//写入颜色链表
void PDSWriteListColor(CString strAppName, CString strKeyName, CList<COLORREF,COLORREF>& listColor, CString strFileName);
//读取整型数
void PDSReadInt(CString strAppName, CString strKeyName, int& iData, CString strFileName);
//读取布尔值
void PDSReadBool(CString strAppName, CString strKeyName, BOOL& bData, CString strFileName);
//读取颜色
void PDSReadColor(CString strAppName, CString strKeyName, COLORREF& crColor, CString strFileName);
//读取浮点数
void PDSReadFloat(CString strAppName, CString strKeyName, float& fData, CString strFileName);
//读取双精度数
void PDSReadDouble(CString strAppName, CString strKeyName, double& dData, CString strFileName);
//读取字符串
void PDSReadString(CString strAppName, CString strKeyName, CString& strText, CString strFileName);
//读取字体
void PDSReadFont(CString strAppName, CString strKeyName, LOGFONT& lfFont, CString strFileName);
//读取整型数链表
void PDSReadListInt(CString strAppName, CString strKeyName, CList<int,int>& listData, CString strFileName);
void PDSReadArrayInt(CString strAppName, CString strKeyName, CArray<int,int>& arryData, CString strFileName);
//读取双精度链表
void PDSReadListDouble(CString strAppName, CString strKeyName, CList<double,double>& listData, CString strFileName);
//读取双精度数组
void PDSReadArrayDouble(CString strAppName, CString strKeyName, CArray<double,double>& arryData, CString strFileName);
//读取点链
void PDSReadListPoint(CString strAppName, CString strKeyName, CList<CPoint,CPoint>& listPoint, CString strFileName);
//读取字符串链表
void PDSReadListString(CString strAppName, CString strKeyName, CList<CString, CString>& listString, CString strFileName);
//写入字符串链表
void PDSWriteListString(CString strAppName, CString strKeyName, CList<CString, CString>& listString, CString strFileName);
//读取字符串数组
void PDSReadArrayString(CString strAppName, CString strKeyName, CStringArray& arrString, CString strFileName);
//写入字符串数组
void PDSWriteArrayString(CString strAppName, CString strKeyName, CStringArray& arrString, CString strFileName);
//读取颜色链表
void PDSReadListColor(CString strAppName, CString strKeyName, CList<COLORREF,COLORREF>& listColor, CString strFileName);
#endif

View File

@ -0,0 +1,106 @@
/********************************************************************
:201869
:PDSUID.h
:
:ID类
:
*********************************************************************/
#ifndef _PDS_UID_H_
#define _PDS_UID_H_
#include <afxwin.h>
//唯一ID
class CPDSUID : public CObject
{
public:
GUID guid;
public:
CPDSUID(void);
CPDSUID(const CPDSUID& rhs);
virtual ~CPDSUID();
CPDSUID& operator=(const CPDSUID& rhs);
BOOL operator==(const CPDSUID& rhs) const;
//初始化
//特别说明:
// 将guid的每一个成员都设置为0
void Initial(void);
//生成UID,并保存在guid中(每次调用都会生成不同的结果)
void CreateUID(void);
//判断this是否为空
//返回值:
// =true 为空,guid的每一个成员变量都是0,=false 非空
BOOL IsNULL(void);
//判断this是否有效
//返回值:
// =true 有效,=false 无效,即IsNULL
BOOL IsValid(void);
//将this格式化为字符串并返回
//返回值:
// 38位字符串,例如{77046E66-C274-42CE-85AD-5DCFA5B4D2A5}
CString GetString(void);
//解析字符串,将结果保存在guid
void ParseString(CString strGUID);
//将id赋值给this
void SetUID(GUID id);
BOOL Read(CArchive& ar);
BOOL Write(CArchive& ar);
};
CArchive& AFXAPI operator>>(CArchive& ar, CPDSUID& uid);
CArchive& AFXAPI operator<<(CArchive& ar, CPDSUID& uid);
//唯一ID的Map
class CPDSUIDMap : public CMap <CPDSUID,CPDSUID&,int,int&>
{
public: //扩展的变量
public: //扩展的方法
};
//唯一ID的链表
class CPDSUIDList : public CList<CPDSUID,CPDSUID&>
{
public: //扩展的变量
public: //扩展的方法
CPDSUIDList& operator=(CPDSUIDList& rhs); //赋值
CPDSUID& operator[](int iIndex); //根据索引值检索,不可越界
void Read(CArchive& ar);
void Write(CArchive& ar);
};
CArchive& AFXAPI operator>>(CArchive& ar, CPDSUIDList& listUID);
CArchive& AFXAPI operator<<(CArchive& ar, CPDSUIDList& listUID);
//唯一ID链表的数组
class CPDSUIDListArray : public CArray<CPDSUIDList,CPDSUIDList>
{
public: //扩展的变量
public: //扩展的方法
CPDSUIDListArray& operator=(CPDSUIDListArray& rhs); //赋值
void Read(CArchive& ar);
void Write(CArchive& ar);
};
CArchive& AFXAPI operator>>(CArchive& ar, CPDSUIDListArray& alUID);
CArchive& AFXAPI operator<<(CArchive& ar, CPDSUIDListArray& alUID);
template<>
AFX_INLINE UINT AFXAPI HashKey(CPDSUID& key)
{
return HashKey(key.guid.Data1); // 将第一个unsigned long传入
}
#endif // _PDS_UID_H_

View File

@ -0,0 +1,164 @@
// PDSUnit.h
#if !defined(PDSUnit_h)
#define PDSUnit_h
//有关长度单位及精度的说明:1、在公制的长度输入中,最高输入精度为0.01mm,显示的最高精度为0.01mm
// 2、在英制分数的长度输入中,最高输入精度为1/2048英寸,显示的最高精度为1/2048英寸
// 3、在英制小数的长度输入中,最高输入精度为0.001英寸,显示的最高精度为0.001英寸
//长度单位
#define UNIT_INCHFRACTION 0 //英制分数
#define UNIT_INCHDECIMA 1 //英制小数
#define UNIT_CENTIMETER 2 //公制cm
#define UNIT_MILLIMETER 3 //公制mm
#define UNIT_CHINACUN 4 //市制寸
//精确度
//使用英制分数时的精确度,=1 整数,=2 2分数制,=4 4分数制,=8 8分数制,
// =16 16分数制,=32 32分数制,=64 64分数制,=128 128分数制,
// =256 256分数制,=512 分数制,=1024 1024分数制,=2048 2048分数制.
//使用英制小数或公制(cm,mm)时的精确度,=1 精确到整数位,=10 精确到0.1,=100 精确到0.01,
// =1000 精确到0.001,=10000 精确到0.0001
#define PRECISION_INTEGER 1 //整数
#define PRECISION_FRACTION2 2 //2分数制
#define PRECISION_FRACTION4 4 //4分数制
#define PRECISION_FRACTION8 8 //8分数制
#define PRECISION_FRACTION16 16 //16分数制
#define PRECISION_FRACTION32 32 //32分数制
#define PRECISION_FRACTION64 64 //64分数制
#define PRECISION_FRACTION128 128 //128分数制
#define PRECISION_FRACTION256 256 //256分数制
#define PRECISION_FRACTION512 512 //512分数制
#define PRECISION_FRACTION1024 1024 //1024分数制
#define PRECISION_FRACTION2048 2048 //2048分数制
#define PRECISION_DECIMAL10 10 //精确到0.1
#define PRECISION_DECIMAL100 100 //精确到0.01
#define PRECISION_DECIMAL1000 1000 //精确到0.001
#define PRECISION_DECIMAL10000 10000 //精确到0.0001
//使用英制时,以inch表示的坐标的字符串
//输入参数:
// iLength 以1/idpmm毫米为单位的坐标值
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以inch为单位的坐标的字符串
CString InchString(int iLength,int idpmm,int iUnit,int iPrecision);
//以cm表示的坐标的字符串
//输入参数:
// iLength 以1/idpmm毫米为单位的坐标值
// idpmm 每毫米的逻辑单位数
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以cm为单位的坐标的字符串
CString CentimetreString(int iLength,int idpmm,int iPrecision);
//以mm表示的坐标的字符串
//输入参数:
// iLength 以1/idpmm毫米为单位的坐标值
// idpmm 每毫米的逻辑单位数
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以mm为单位的坐标的字符串
CString MillimetreString(int iLength,int idpmm,int iPrecision);
//以寸表示的坐标的字符串
//输入参数:
// iLength 以1/idpmm毫米为单位的坐标值
// idpmm 每毫米的逻辑单位数
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以寸为单位的坐标的字符串
CString ChinaCunString(int iLength,int ilpmm,int iPrecision);
//将以内部单位1/idpmm毫米为单位的长度值转换为以当前使用制式的长度值的字符串
//输入参数:
// iLength 以1/idpmm毫米为单位的坐标值
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以当前使用制式为单位的坐标的字符串
CString InternalUnitToString(int iLength,int idpmm,int iUnit,int iPrecision);
//将以内部单位(1/idpmm)*(1/idpmm)毫米2为单位的面积值转换为
//以当前使用的度量单位的面积字符串
//输入参数:
// dArea 以(1/idpmm)*(1/idpmm)毫米2为单位的面积值
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以当前使用的度量单位的面积字符串
CString AreaToString(double dArea,int idpmm,int iUnit,int iPrecision);
//将以Inch为单位的数字串转换以内部单位1/idpmm毫米为单位的数字
//输入参数:
// strInch 以inch为单位的坐标的字符串
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
// bEnableDefaultDenominator =true 则在未包含分母时使用iPrecision指定的分母
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以1/idpmm毫米为单位的坐标值
int InchStrToInternalUnit(CString strInch,int idpmm,int iUnit,BOOL bEnableDefaultDenominator,int iPrecision);
//将以当前使用制式的长度字符串转换为以1/idpmm毫米为单位的长度值
//输入参数:
// string 以当前使用制式为单位的坐标的字符串
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
// bEnableDefaultDenominator =true 则在未包含分母时使用iPrecision指定的分母
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 以1/idpmm毫米为单位的坐标值
int StringToInternalUnit(CString string,int idpmm,int iUnit,BOOL bEnableDefaultDenominator,int iPrecision);
//将英寸分数形式的字符串转化成小数
//输入参数:
// string 英寸分数形式的字符串
// bEnableDefaultDenominator =true 则在未包含分母时使用iPrecision指定的分母
// iPrecision 精确度(见"PDSUnit.h"文件关于精确度的宏定义)
//返回值:
// 英寸的小数值
double InchFractionStringToDecimal(CString string,BOOL bEnableDefaultDenominator,int iPrecision);
//将分数字符串转化成小数
//输入参数:
// string 分数表示的字符串
//返回值:
// 小数值
double FractionStringToDecimal(CString string);
//取得当前使用的长度单位名称字符串
//输入参数:
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
//返回值:
// In. 当iUnit=UNIT_INCHFRACTION
// In. 当iUnit=UNIT_INCHDECIMA
// cm 当iUnit=UNIT_CENTIMETER
// mm 当iUnit=UNIT_MILLIMETER
CString GetUnitStr(int iUnit);
//20111130 将以当前使用制式的长度转换为以1/idpmm毫米为单位的长度值
//输入参数:
// dValue 以当前使用制式为单位的值
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
//返回值:
// 以1/idpmm毫米为单位的值
//说明:
// dValue的单位与iUnit一致即dValue按照iUnit单位计算得到的值
int DoubleToInternalUnit(double dValue, int idpmm, int iUnit);
//20111130 将以内部单位1/idpmm毫米为单位的长度值转换为以当前使用制式的长度值的浮点数
//输入参数:
// iValue 以1/idpmm毫米为单位的坐标值
// idpmm 每毫米的逻辑单位数
// iUnit 长度单位(见"PDSUnit.h"文件关于长度单位的宏定义)
double InternalUnitToDouble(int iValue, int idpmm, int iUnit);
#endif

View File

@ -0,0 +1,178 @@
#ifndef _POINT_3D_H
#define _POINT_3D_H
#include "PDSMath.h"
//#define CONST_PI 3.1415926
class CVector;
class CUnitVector;
class CPoint_3D
{
private:
double m_dCoord[3]; // x, y and z coordinates of the position
// Scale the object space.
// This requires care, and so the operator is private.
friend CPoint_3D operator*(CPoint_3D pos, double ss);
public:
// Force creation of all positions to be by constructor.
CPoint_3D();
// Construct a CPoint_3D from three doubles.
CPoint_3D(double xi, double yi, double zi);
// Construct a CPoint_3D from an array of three doubles.
CPoint_3D(double p[3]);
// Copy a CPoint_3D
CPoint_3D(CPoint_3D const &p);
// Extract a coordinate value.
double x() const;
double y() const;
double z() const;
double Coordinate(int i);
// Set coordinate values.
void Set_x(double new_x);
void Set_y(double new_y);
void Set_z(double new_z);
void Set_coordinate(int i, double new_c);
void Set_xyz(double new_x, double new_y, double new_z);
// Translate a CPoint_3D by a vector.
friend CPoint_3D operator+(CPoint_3D pos, CVector vect);
friend CPoint_3D operator+(CVector vect, CPoint_3D pos);
friend CPoint_3D operator+(CPoint_3D ps1,CPoint_3D ps2);
friend CPoint_3D operator-(CPoint_3D pos, CVector vect);
friend CPoint_3D operator-(CVector vect, CPoint_3D pos);
// Position operators
// Get displacement, i.e. a vector, as difference of two positions.
friend CVector operator-(CPoint_3D pos1, CPoint_3D pos2);
// Interpolate between two positions. The parameter gives the
// proportion of the segment between p1 and p2. In fact, the
// parameter can be < 0 or > 1, in which case the function
// extrapolates.
friend CPoint_3D Interpolate(double para, CPoint_3D pos1, CPoint_3D pos2);
// STI let: add some general functions
// Determine if 2 positions are equal, given some resolution
friend BOOL Same_point(CPoint_3D pos1, CPoint_3D pos2, double tol);
// calculate distance between two CPoint_3D
//3.calculate the distance of two point
friend double Cal_two_pos_length(CPoint_3D pos1, CPoint_3D pos2);
friend double Cal_two_pos_length(double x1,double y1,double z1,double x2,double y2,double z2);
friend CPoint_3D Cal_two_pos_centre(CPoint_3D pos1, CPoint_3D pos2);
};
class CVector
{
protected:
double m_dComp[3]; // the x, y and z components of the vector
public:
// default constructor
CVector();
// Construct a vector from three doubles.
CVector(double x, double y, double z);
// Construct a vector from an array of three doubles.
CVector(double v[3]);
// Copy a vector.
CVector(CVector const &v);
// Extract the components of a vector.
double x() const;
double y() const;
double z() const;
double Component(int i) const;
// Set component values.
void Set_x(double new_x);
void Set_y(double new_y);
void Set_z(double new_z);
void Set_xyz(double new_x, double new_y, double new_z);
void Set_component(int i, double new_c);
// Unary minus.
friend CVector operator-(CVector vect);
// Addition of vectors.
friend CVector operator+(CVector vect1, CVector vect2);
// Binary minus.
friend CVector operator-(CVector vect1, CVector vect2);
// Scalar product of two vectors.
friend double operator%(CVector vect1, CVector vect2);
// Scalar product of a CPoint_3D.
friend double operator%(CPoint_3D pos, CVector vect);
friend double operator%(CVector vect, CPoint_3D pos);
// Cross product of general vectors. Also applies to unit vectors.
friend CVector operator*(CVector vect1, CVector vect2);
// Multiplication of a vector by a scalar.
friend CVector operator*(double ss, CVector vect);
friend CVector operator*(CVector vect, double ss);
// Division of a vector by a scalar.
friend CVector operator/(CVector vect, double ss);
// Length of a vector.
double Len_sq(); // len^2
double Len();
// Form a CUnitVector by normalising a vector.
CUnitVector Normalise();
// Determine if a vector is a zero vector,
// i.e., its length is less than a given tolerance
BOOL Is_zero(double tol);
};
class CUnitVector: public CVector
{
public:
CUnitVector(); // allow unitialised unit_vectors
// Construct a unit vector from three components.
// Always normalises result.
CUnitVector(double x, double y, double z);
// Construct a unit vector from an array of three doubles.
// Always normalises result.
CUnitVector(double u[3]);
// Unary minus.
friend CUnitVector operator-(CUnitVector unit_vect);
// Scalar product of a CPoint_3D. This is just as for a vector,
// but declared explicitly to avoid an ambiguity.
friend double operator%(CPoint_3D pos, CUnitVector unit_vect);
friend double operator%(CUnitVector unit_vect, CPoint_3D pos);
// Find a CPoint_3D as the cross-product of a CPoint_3D with a
// unit vector.
friend CPoint_3D operator*(CPoint_3D pos, CUnitVector unit_vect);
friend CPoint_3D operator*(CUnitVector unit_vect, CPoint_3D pos);
};
#endif

View File

@ -0,0 +1,44 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__F57A3BD3_E702_479A_9F06_C4BAD2BE9F88__INCLUDED_)
#define AFX_STDAFX_H__F57A3BD3_E702_479A_9F06_C4BAD2BE9F88__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/*
Ìí¼Ó
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0502
#endif
½â¾ö:
¾¯¸æ
_WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
*/
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0502
#endif
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
//#include <afxwin.h> // MFC core and standard components
//#include <afxext.h> // MFC extensions
//#include <afxdisp.h> // MFC Automation classes
//#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_OLE_SUPPORT
#endif // _AFX_NO_OLE_SUPPORT
// #ifndef ULONG_PTR
// #define ULONG_PTR unsigned long*
// #endif
#include "Gdiplus.h"
using namespace Gdiplus;
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__F57A3BD3_E702_479A_9F06_C4BAD2BE9F88__INCLUDED_)

View File

@ -0,0 +1,215 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 0.15 beta, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip */
// modified by Tadeusz Dracz - 01.2000:
// - added class' wrapers
// - several bugs fixed
// - several enhancements added
// - MFC support added
// - memory leaks eliminated when read error occured
// - automaticaly free used memory on destruction or exception
// - modern error notification using exceptions
// Copyright (C) 2000 Tadeusz Dracz
// This notice may not be removed or altered from any source distribution.
// UnzipFile.h: interface for the CUnzipFile class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_UNZIPFILE_H__44D45340_D71F_11D3_B7C7_E77339672847__INCLUDED_)
#define AFX_UNZIPFILE_H__44D45340_D71F_11D3_B7C7_E77339672847__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZUBaseFile.h"
#include "ZipStruct.h"
/* unz_s contain internal information about the zipfile
*/
struct unz_s
{
unz_s();
~unz_s();
CFile file; /* io structore of the zipfile */
unz_global_info gi; /* public global information 公共的全局信息*/
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
uLong num_file; /* number of the current file in the zipfile*/
uLong pos_in_central_dir; /* pos of the current file in the central dir*/
uLong current_file_ok; /* flag about the usability of the current file 当前文件可用性标志符*/
uLong central_pos; /* position of the beginning of the central dir*/
uLong size_central_dir; /* size of the central directory */
uLong offset_central_dir; /* offset of start of central directory with
respect to the starting disk number */
unz_file_info cur_file_info; /* public info about the current file in zip*/
unz_file_info_internal cur_file_info_internal; /* private info about it*/
file_in_zip_read_info* pfile_in_zip_read; /* structure about the current
file if we are decompressing it */
public:
void free_pfile_in_zip_read();
void alloc_pfile_in_zip_read();
};
class CUnzipFile : public CZUBaseFile
{
public:
/*
fill in attibutes and time fields of the fileStatus with unz_file_info data
WARNING: if the file is opened the function closes it
*/
void UpdateFileStatus(CFile & f, unz_file_info &ui);
CUnzipFile();
void Open(LPCTSTR lpszPath);
/*
Give the current position in uncompressed data
*/
z_off_t tell();
/*
return true if the end of file was reached, false elsewhere
*/
bool eof();
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied
*/
int GetGlobalComment (char* szComment, uLong uSizeBuf);
/*
Read extra field from the current file (opened by OpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf
*/
int GetLocalExtrafield (void* buf, UINT len);
/*
Get Info about the current file
if file_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
void GetCurrentFileInfo ( unz_file_info* file_info, LPSTR szFileName = NULL,
uLong fileNameBufferSize = 0, void *extraField = NULL, uLong extraFieldBufferSize = 0,
LPSTR szComment = NULL, uLong commentBufferSize = 0);
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
*/
void GetGlobalInfo(unz_global_info & global_info);
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
/*
Set the current file of the zipfile to the first file.
*/
void GoToFirstFile();
/*
Set the current file of the zipfile to the next file.
return true if there is no problem
return false if the actual file was the latest.
*/
bool GoToNextFile();
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
true if the file is found. It becomes the current file.
false if the file is not found
*/
bool LocateFile(CString szFileName, bool bCaseSensitive = false);
/*
Open for reading data the current file in the zipfile.
*/
void OpenCurrentFile();
/*
Close the file in zip opened with OpenCurrentFile
throw badCrc error if all the file was read but the CRC is not good
*/
void CloseCurrentFile();
/*
Read bytes from the current file (opened by OpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
*/
int ReadCurrentFile(void* buf, UINT len);
void Close();
int StringFileNameCompare(CString fileName1, CString fileName2, bool caseSensitive = false);
CUnzipFile(LPCTSTR lpszPath);
virtual ~CUnzipFile();
protected:
void unzlocal_GetCurrentFileInfoInternal( unz_file_info & file_info,
unz_file_info_internal & file_info_internal, LPSTR szFileName,
uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize,
LPSTR szComment, uLong commentBufferSize);
void unzlocal_DosDateToTmuDate(unz_file_info & file_info);
void unzlocal_CheckCurrentFileCoherencyHeader (uInt & iSizeVar, uLong & offset_local_extrafield, uLong & size_local_extrafield);
uLong unzlocal_SearchCentralDir();
void unzlocal_getLong (uLong & pX);
void unzlocal_getShort (uLong & pX);
void unzlocal_getByte(int & pi);
unz_s uf;
};
#endif // !defined(AFX_UNZIPFILE_H__44D45340_D71F_11D3_B7C7_E77339672847__INCLUDED_)

View File

@ -0,0 +1,217 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 0.15 beta, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip */
// modified by Tadeusz Dracz - 01.2000:
// - added class' wrapers
// - several bugs fixed
// - several enhancements added
// - MFC support added
// - memory leaks eliminated when read error occured
// - automaticaly free used memory on destruction or exception
// - modern error notification using exceptions
// Copyright (C) 2000 Tadeusz Dracz
// This notice may not be removed or altered from any source distribution.
// UnzipFile_Memory.h: interface for the CUnzipFile_Memory class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_UNZIPFILE_MEMORY_H__44D45340_D71F_11D3_B7C7_E77339672847__INCLUDED_)
#define AFX_UNZIPFILE_MEMORY_H__44D45340_D71F_11D3_B7C7_E77339672847__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZUBaseFile_Memory.h"
#include "ZipStruct.h"
/* unz_s contain internal information about the zipfile
*/
struct unz_s_Memory
{
unz_s_Memory();
~unz_s_Memory();
char *m_pfilebuf; // 需要解压的内存
unz_global_info gi; /* public global information */
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
uLong num_file; /* number of the current file in the zipfile 当前解压的文件在整个文件个数中的索引*/
uLong pos_in_central_dir; /* pos of the current file in the central dir 在中心目录结构中当前文件的相对位置*/
uLong current_file_ok; /* flag about the usability of the current file 当前文件是否处于解压状态*/
uLong central_pos; /* position of the beginning of the central dir 中心目录结构开始的相对位置*/
uLong size_central_dir; /* size of the central directory 中心目录结构大小 */
uLong offset_central_dir; /* offset of start of central directory with
respect to the starting disk number */
unz_file_info cur_file_info; /* public info about the current file in zip 在压缩文件中当前解压文件的公开信息*/
unz_file_info_internal cur_file_info_internal; /* private info about it 在压缩文件中当前解压文件的隐藏信息*/
file_in_zip_read_info* pfile_in_zip_read; /* structure about the current
file if we are decompressing it */
public:
void free_pfile_in_zip_read();
void alloc_pfile_in_zip_read();
};
class CUnzipFile_Memory : public CZUBaseFile_Memory
{
public:
/*
fill in attibutes and time fields of the fileStatus with unz_file_info data
WARNING: if the file is opened the function closes it
*/
CUnzipFile_Memory();
void Open(void* pBuf, LONG lCount);
/*
Give the current position in uncompressed data
*/
z_off_t tell();
/*
return true if the end of file was reached, false elsewhere
*/
bool eof();
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied
*/
int GetGlobalComment (char* szComment, uLong uSizeBuf);
/*
Read extra field from the current file (opened by OpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf
*/
int GetLocalExtrafield (void* buf, UINT len);
/*
Get Info about the current file
if file_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
void GetCurrentFileInfo ( unz_file_info* file_info, LPSTR szFileName = NULL,
uLong fileNameBufferSize = 0, void *extraField = NULL, uLong extraFieldBufferSize = 0,
LPSTR szComment = NULL, uLong commentBufferSize = 0);
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
*/
void GetGlobalInfo(unz_global_info & global_info);
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
/*
Set the current file of the zipfile to the first file.
*/
void GoToFirstFile();
/*
Set the current file of the zipfile to the next file.
return true if there is no problem
return false if the actual file was the latest.
*/
bool GoToNextFile();
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
true if the file is found. It becomes the current file.
false if the file is not found
*/
bool LocateFile(CString szFileName, bool bCaseSensitive = false);
/*
Open for reading data the current file in the zipfile.
*/
void OpenCurrentFile();
/*
Close the file in zip opened with OpenCurrentFile
throw badCrc error if all the file was read but the CRC is not good
*/
void CloseCurrentFile();
/*
Read bytes from the current file (opened by OpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
*/
int ReadCurrentFile(void* buf, UINT len);
//得到当前文件未压缩大小
int GetCurUnCompressFileSize();
void Close();
int StringFileNameCompare(CString fileName1, CString fileName2, bool caseSensitive = false);
CUnzipFile_Memory(void* pBuf, LONG lCount);
virtual ~CUnzipFile_Memory();
protected:
void unzlocal_GetCurrentFileInfoInternal( unz_file_info & file_info,
unz_file_info_internal & file_info_internal, LPSTR szFileName,
uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize,
LPSTR szComment, uLong commentBufferSize);
void unzlocal_DosDateToTmuDate(unz_file_info & file_info);
void unzlocal_CheckCurrentFileCoherencyHeader (uInt & iSizeVar, uLong & offset_local_extrafield, uLong & size_local_extrafield);
uLong unzlocal_SearchCentralDir();
void unzlocal_getLong (uLong & pX);
void unzlocal_getShort (uLong & pX);
void unzlocal_getByte(int & pi);
unz_s_Memory uf;
};
#endif // !defined(AFX_UNZIPFILE_MEMORY_H__44D45340_D71F_11D3_B7C7_E77339672847__INCLUDED_)

View File

@ -0,0 +1,39 @@
// ZUBaseFile.h: interface for the CZUBaseFile class.
//
// Copyright (C) 2000 Tadeusz Dracz
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZUBASEFILE_H__AEA985C0_D813_11D3_B7C7_8E2FB86D3347__INCLUDED_)
#define AFX_ZUBASEFILE_H__AEA985C0_D813_11D3_B7C7_8E2FB86D3347__INCLUDED_
#include "zlib.h"
#include "ZipException.h"
class CPtrList;
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// base class for CUnzipFile and CZipFile
class CZUBaseFile
{
public:
CZUBaseFile();
virtual ~CZUBaseFile();
// specify whether to control memory allocation and freeing by zlib library
// strongly suggested to set it to true (default)
bool m_bDetectZlibMemoryLeaks;
protected:
CPtrList m_list;
void CheckForError(int err);
void ThrowError(int err);
static void myfree(void* opaque, void* address);
static void* myalloc(void* opaque, UINT items, UINT size);
bool IsClosed();
CFile* m_pFile;
bool m_bZipFile;
};
#endif // !defined(AFX_ZUBASEFILE_H__AEA985C0_D813_11D3_B7C7_8E2FB86D3347__INCLUDED_)

View File

@ -0,0 +1,62 @@
// ZUBaseFile_Memory.h: interface for the CZUBaseFile_Memory class.
//
// Copyright (C) 2000 Tadeusz Dracz
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZUBASEFILE_MEMORY_H__AEA985C0_D813_11D3_B7C7_8E2FB86D3347__INCLUDED_)
#define AFX_ZUBASEFILE_MEMORY_H__AEA985C0_D813_11D3_B7C7_8E2FB86D3347__INCLUDED_
#include "zlib.h"
#include "ZipException.h"
class CPtrList;
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// base class for CUnzipFile_Memory and CZipFile_Memory
class CZUBaseFile_Memory
{
public:
CZUBaseFile_Memory();
virtual ~CZUBaseFile_Memory();
// specify whether to control memory allocation and freeing by zlib library
// strongly suggested to set it to true (default)
bool m_bDetectZlibMemoryLeaks;
//设置内存开始读入位置
void Seek(LONG lOff);
//读内存内容
UINT Read(void* lpBuf, UINT nCount);
//将内容写入内存
void Write(const void* lpBuf, UINT nCount);
//偏移量指向内存尾部
void SeekToEnd();
//得到当前偏移位置的位置
DWORD GetPosition();
//在内存最后位置写入结束符
//返回值:
// 内存大小
LONG WriteCloseMemory();
protected:
CPtrList m_list;
void CheckForError(int err);
void ThrowError(int err);
static void myfree(void* opaque, void* address);
static void* myalloc(void* opaque, UINT items, UINT size);
bool IsClosed();
//CFile* m_pFile;
bool m_bZipFile;
char *m_pBufferData;
LONG m_lDataOffset;
LONG m_lDataCount;
};
#endif // !defined(AFX_ZUBASEFILE_MEMORY_H__AEA985C0_D813_11D3_B7C7_8E2FB86D3347__INCLUDED_)

View File

@ -0,0 +1,42 @@
//ZipCompress.h
#if !defined(ZIPCOMPRESS_H)
#define ZIPCOMPRESS_H
#define BUF_SIZE 2048
//对给定的内存进行压缩
//[输入] pUnCompressData 需要压缩的数据
//[输入] iUnCompressCount内存大小
//[输入][输出] pCompressData 压缩后的数据,内存在函数外申请
//[输入][输出] iCompressCount 输出: 压缩后的大小,实际使用的大小; 输入: 为pCompressData在外面申请的空间大小,申请空间的大小: iUnCompressCount + 100 , 100为zip压缩头文件大小
void CompressMemory(char *pUnCompressData, int iUnCompressCount, char *&pCompressData, int &iCompressCount);
//对给定的内存进行解压
//输入参数:
// pCompressData 压缩后的数据
// iCompressCount 压缩后的大小
//输出参数:
// pUnCompressData 需要压缩的数据,内存在函数中申请,需要在函数外删除
// iUnCompressCount 内存大小
void UnCompressMemory(char *pCompressData, int iCompressCount, char *&pUnCompressData, int &iUnCompressCount);
//对给定的文件进行压缩
//输入参数:
// strFilePath 需要压缩的文件路径(全路径,包含文件名,后缀)
// strFileName 压缩的文件名称(文件名,文件后缀)
// strName 压缩的文件名
//输出参数:
// strZipSaveName 保存的压缩文件(全路径)
void CompressFile(CString strFilePath, CString strFileName, CString strZipSaveName);
//对给定的文件进行解压
//输入参数:
// strZipFilePath ZIP文件路径(包含文件名和后缀)
//输出参数:
// strSaveName 保存的文件路径(只需要路径,没有文件名)
void UnCompressFile(CString strZipFilePath, CString strSavePath);
#endif

View File

@ -0,0 +1,55 @@
// ZipException.h: interface for the CZipException class.
//
// Copyright (C) 2000 Tadeusz Dracz
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZIPEXCEPTION_H__E3546921_D728_11D3_B7C7_E77339672847__INCLUDED_)
#define AFX_ZIPEXCEPTION_H__E3546921_D728_11D3_B7C7_E77339672847__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CZipException : public CException
{
public:
DECLARE_DYNAMIC(CZipException)
// sygnalize whether the error occured during zip or unzip
bool m_bDuringZip;
// convert zlib library error code to a ZipException code
static int ZipErrToCause(int iZipError);
// name of the zip file where the error occured
CString m_szFileName;
enum
{
noError,
generic,
streamEnd,
needDict,
errNo,
streamError,
dataError,
memError,
bufError,
versionError,
badFuncParam,
badZipFile,
badCrc,
};
// cause - takes one of the codes above
int m_iCause;
CZipException(int iCause = generic, LPCTSTR lpszZipName = NULL, bool bDuringZip = true);
virtual ~CZipException();
};
// throw zip exception
// Parameters:
// iZipError - zlib error code
// lpszZipName - name of the file where the error occured
// bzipFile - true if the error occured while compression,
// false - decompression
void AfxThrowZipException(int iZipError = 1000, LPCTSTR lpszZipName = NULL, bool bZipFile = true);
#endif // !defined(AFX_ZIPEXCEPTION_H__E3546921_D728_11D3_B7C7_E77339672847__INCLUDED_)

View File

@ -0,0 +1,145 @@
/* zip.h -- IO for compress .zip files using zlib
Version 0.15 alpha, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
For uncompress .zip file, look at unzip.h
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/zip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
// modified by Tadeusz Dracz - 01.2000:
// - added class' wrapers
// - several bugs fixed
// - several enhancements added
// - MFC support added
// - memory leaks eliminated when write error occured
// - automaticaly free used memory on destruction or exception
// - modern error notification using exceptions
// Copyright (C) Tadeusz Dracz
// This notice may not be removed or altered from any source distribution.
// ZipFile.h: interface for the CZipFile class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZIPFILE_H__7F795F27_D6BD_11D3_B7C7_BBF03FA53147__INCLUDED_)
#define AFX_ZIPFILE_H__7F795F27_D6BD_11D3_B7C7_BBF03FA53147__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZUBaseFile.h"
#include "ZipStruct.h"
struct zip_internal
{
zip_internal();
~zip_internal();
CFile filezip;
linkedlist_data central_dir;/* datablock with central dir in construction*/
int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
struct curfile_info ci; /* info on the file curretly writing */
DWORD begin_pos; /* position of the beginning of the zipfile */
DWORD number_entry;
};
class CZipFile : public CZUBaseFile
{
public:
CZipFile();
void Open(LPCTSTR pathname, bool append);
/*
Create a zipfile.
if the file pathname exist and append is true, the zip will be created at the end
of the file. (useful if the file contain a self extractor code)
*/
CZipFile(LPCTSTR pathname, bool append = false);
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
*/
void OpenNewFileInZip ( CString filename,
zip_fileinfo& zipfi,
int level = Z_DEFAULT_COMPRESSION,
CString comment = "",
const void* extrafield_local = NULL,
uInt size_extrafield_local = 0,
const void* extrafield_global = NULL,
uInt size_extrafield_global = 0,
int method = Z_DEFLATED);
/*
Write data in the zipfile
*/
void WriteInFileInZip(const void *buf, UINT len);
/*
Close the current file in the zipfile
*/
void CloseFileInZip();
/*
Close the zipfile and the current file in the zipfile if is opened
*/
void Close(CString global_comment = "");
/*
Fill in zip_fileinfo fields (time an attributes) according to CFile data
*/
void UpdateZipInfo(zip_fileinfo &zi, CFile &f);
virtual ~CZipFile();
protected:
void ziplocal_putValue_inmemory(Byte dest, uLong x, int nbByte);
void ziplocal_putValue(uLong x, int nbByte);
zip_internal zi;
};
#endif // !defined(AFX_ZIPFILE_H__7F795F27_D6BD_11D3_B7C7_BBF03FA53147__INCLUDED_)

View File

@ -0,0 +1,146 @@
/* zip.h -- IO for compress .zip files using zlib
Version 0.15 alpha, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
For uncompress .zip file, look at unzip.h
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/zip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
// modified by Tadeusz Dracz - 01.2000:
// - added class' wrapers
// - several bugs fixed
// - several enhancements added
// - MFC support added
// - memory leaks eliminated when write error occured
// - automaticaly free used memory on destruction or exception
// - modern error notification using exceptions
// Copyright (C) Tadeusz Dracz
// This notice may not be removed or altered from any source distribution.
// ZipFile_Memory.h: interface for the CZipFile_Memory class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZIPFILE_MEMORY_H__7F795F27_D6BD_11D3_B7C7_BBF03FA53147__INCLUDED_)
#define AFX_ZIPFILE_MEMORY_H__7F795F27_D6BD_11D3_B7C7_BBF03FA53147__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZUBaseFile_Memory.h"
#include "ZipStruct.h"
struct zip_internal_Memory
{
zip_internal_Memory();
~zip_internal_Memory();
char *m_pZipbuf; //压缩后的数据
linkedlist_data central_dir;/* datablock with central dir in construction*/
int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
struct curfile_info ci; /* info on the file curretly writing */
DWORD begin_pos; /* position of the beginning of the zipfile */
DWORD number_entry;
};
class CZipFile_Memory : public CZUBaseFile_Memory
{
public:
CZipFile_Memory();
void Open(void* pBuf, LONG lCount);
/*
Create a zipfile.
if the file pathname exist and append is true, the zip will be created at the end
of the file. (useful if the file contain a self extractor code)
*/
CZipFile_Memory(void* pBuf, LONG lCount);
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
*/
void OpenNewFileInZip ( CString filename,
zip_fileinfo& zipfi,
int level = Z_DEFAULT_COMPRESSION,
CString comment = "",
const void* extrafield_local = NULL,
uInt size_extrafield_local = 0,
const void* extrafield_global = NULL,
uInt size_extrafield_global = 0,
int method = Z_DEFLATED);
/*
Write data in the zipfile_Memory
*/
void WriteInFileInZip(const void *buf, UINT len);
/*
Close the current file in the zipfile
*/
void CloseFileInZip();
/*
Close the zipfile and the current file in the zipfile if is opened
*/
int Close(CString global_comment = "");
/*
Fill in zip_fileinfo fields (time an attributes) according to CFile data
*/
void UpdateZipInfo(zip_fileinfo &zi, CFile &f);
virtual ~CZipFile_Memory();
protected:
void ziplocal_putValue_inmemory(Byte dest, uLong x, int nbByte);
void ziplocal_putValue(uLong x, int nbByte);
zip_internal_Memory zi;
};
#endif // !defined(AFX_ZIPFILE_MEMORY_H__7F795F27_D6BD_11D3_B7C7_BBF03FA53147__INCLUDED_)

View File

@ -0,0 +1,199 @@
//ZipStruct.h
#if !defined(ZIPSTRUCT_H)
#define ZIPSTRUCT_H
#include "zlib.h"
#include "ZipException.h"
//解压用到的结构
#define SIZECENTRALDIRITEM (0x2e)
#define SIZEZIPLOCALHEADER (0x1e)
#ifndef UNZ_BUFSIZE
#define UNZ_BUFSIZE (16384)
#endif
#ifndef UNZ_MAXFILENAMEINZIP
#define UNZ_MAXFILENAMEINZIP (256)
#endif
#define BUFREADCOMMENT (0x400)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_CRCERROR (-105)
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
struct unz_global_info
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
};
/* unz_file_info contain information about a file in the zipfile */
struct unz_file_info
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
CTime tmu_date;
};
/* unz_file_info_interntal contain internal info about a file in zipfile*/
struct unz_file_info_internal
{
uLong offset_curfile;/* relative offset of local header 4 bytes */
};
/* file_in_zip_read_info_s contain internal information about a file in zipfile,
when reading and decompress it */
struct file_in_zip_read_info
{
file_in_zip_read_info();
~file_in_zip_read_info();
char *read_buffer; /* internal buffer for compressed data */
z_stream stream; /* zLib stream structure for inflate */
uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
uLong stream_initialised; /* flag set if stream structure is initialised*/
uLong offset_local_extrafield;/* offset of the local extra field */
uInt size_local_extrafield;/* size of the local extra field */
uLong pos_local_extrafield; /* position in the local extra field in read*/
uLong crc32; /* crc32 of all data uncompressed */
uLong crc32_wait; /* crc32 we must obtain after decompress all */
uLong rest_read_compressed; /* number of byte to be decompressed */
uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
// CFile* file; /* io structore of the zipfile */
uLong compression_method; /* compression method (0==store) */
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
};
//压缩用到的结构
#ifndef VERSIONMADEBY
# define VERSIONMADEBY (0x0) /* platform depedent */
#endif
#define FLAG_LOCALHEADER_OFFSET (0x06)
#define CRC_LOCALHEADER_OFFSET (0x0e)
#define SIZECENTRALHEADER (0x2e) /* 46 */
#ifndef Z_BUFSIZE
#define Z_BUFSIZE (16384)
#endif
#ifndef Z_MAXFILENAMEINZIP
#define Z_MAXFILENAMEINZIP (256)
#endif
#ifndef DEF_MEM_LEVEL
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
#endif
#define SIZEDATA_INDATABLOCK (4096-(4*4))
#define LOCALHEADERMAGIC (0x04034b50)
#define CENTRALHEADERMAGIC (0x02014b50)
#define ENDHEADERMAGIC (0x06054b50)
#define SIZECENTRALHEADER (0x2e) /* 46 */
// it doesn't compile anyway
// const char z_copyright[] =
// " unzip & zip 0.15 Copyright 1998 Gilles Vollant & MFC/C++ revision Copyright 2000 Tadeusz Dracz";
#define ZIP_PARAMERROR (-102)
struct zip_fileinfo
{
CTime tmz_date; /* date in understandable format */
uLong dosDate; /* if dos_date == 0, tmu_date is used */
/* uLong flag; */ /* general purpose bit flag 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
public:
uLong get_dos_date();
zip_fileinfo();
};
struct curfile_info
{
curfile_info();
~curfile_info();
z_stream stream; /* zLib stream structure for inflate */
int stream_initialised; /* 1 is stream is initialised */
UINT pos_in_buffered_data; /* last written byte in buffered_data */
DWORD pos_local_header; /* offset of the local header of the file
currenty writing */
char* central_header; /* central header data for the current file */
DWORD size_centralheader; /* size of the central header for cur file */
uLong flag; /* flag of the file currently writing */
int method; /* compression method of file currenty wr.*/
Byte* buffered_data;/* buffer contain compressed data to be writ*/
uLong dosDate;
uLong crc32;
public:
void free_central_header();
void alloc_central_header();
};
class linkedlist_datablock_internal
{
public:
linkedlist_datablock_internal();
~linkedlist_datablock_internal();
class linkedlist_datablock_internal* next_datablock;
uLong avail_in_this_block;
uLong filled_in_this_block;
uLong unused; /* for future use and alignement */
unsigned char* data;
};
class CZipFile_Memory;
class linkedlist_data
{
public:
void add_data_in_datablock(char* buf, uLong len);
linkedlist_data();
~linkedlist_data();
int write_datablock(CFile & f);
int write_datablock(CZipFile_Memory *pZipFile_Memory);
linkedlist_datablock_internal* first_block;
linkedlist_datablock_internal* last_block;
};
#endif

View File

@ -0,0 +1,279 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef _ZCONF_H
#define _ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateReset z_inflateReset
# define compress z_compress
# define compress2 z_compress2
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
# ifndef STDC
# define STDC
# endif
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Old Borland C incorrectly complains about missing returns: */
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR _far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR _cdecl _export
# endif
# endif
# if defined (__BORLANDC__)
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
# include <windows.h>
# define ZEXPORT __declspec(dllexport) WINAPI
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
# else
# if defined (_Windows) && defined (__DLL__)
# define ZEXPORT _export
# define ZEXPORTVA _export
# endif
# endif
# endif
#endif
#if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#ifdef HAVE_UNISTD_H
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(inflate_blocks,"INBL")
# pragma map(inflate_blocks_new,"INBLNE")
# pragma map(inflate_blocks_free,"INBLFR")
# pragma map(inflate_blocks_reset,"INBLRE")
# pragma map(inflate_codes_free,"INCOFR")
# pragma map(inflate_codes,"INCO")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_flush,"INFLU")
# pragma map(inflate_mask,"INMA")
# pragma map(inflate_set_dictionary,"INSEDI2")
# pragma map(inflate_copyright,"INCOPY")
# pragma map(inflate_trees_bits,"INTRBI")
# pragma map(inflate_trees_dynamic,"INTRDY")
# pragma map(inflate_trees_fixed,"INTRFI")
# pragma map(inflate_trees_free,"INTRFR")
#endif
#endif /* _ZCONF_H */

View File

@ -0,0 +1,893 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.3, July 9th, 1998
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
#ifndef _ZLIB_H
#define _ZLIB_H
#include "zconf.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ZLIB_VERSION "1.1.3"
/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms will be added later and will have the same
stream interface.
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio.
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never
crash even in case of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
/*
The application must update next_in and avail_in when avail_in has
dropped to zero. It must update next_out and avail_out when avail_out
has dropped to zero. The application must initialize zalloc, zfree and
opaque before calling the init function. All other fields are set by the
compression library and must not be updated by the application.
The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the
opaque value.
zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe.
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
pointers returned by zalloc for objects of exactly 65536 bytes *must*
have their offset normalized to zero. The default allocation function
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or
progress reports. After compression, total_in holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step).
*/
/* constants */
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
/* Allowed flush values; see deflate() below for details */
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* Possible values of the data_type field */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
/* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by deflateInit and inflateInit.
*/
/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
use default allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
compression (currently equivalent to level 6).
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
with the version assumed by the caller (ZLIB_VERSION).
msg is set to null if there is no error message. deflateInit does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some
output latency (reading input without producing any output) except when
forced to flush.
The detailed semantics are as follows. deflate performs one or both of the
following actions:
- Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating avail_in or avail_out accordingly; avail_out
should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular
avail_in is zero after the call if enough output space has been provided
before the call.) Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
If flush is set to Z_FULL_FLUSH, all output is flushed as with
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
restart from this point if previous compressed data has been damaged or if
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
the compression.
If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero
avail_out).
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there
was enough output space; if deflate returns with Z_OK, this function must be
called again with Z_FINISH and more output space (updated avail_out) but no
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
deflate() may update data_type if it can make a good guess about
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
(for example avail_in or avail_out was zero).
*/
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case,
msg may be set but then points to a static string (which must not be
deallocated).
*/
/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
value depends on the compression method), inflateInit determines the
compression method from the zlib header and allocates all data structures
accordingly; otherwise the allocation will be deferred to the first call of
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
use default allocation functions.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller. msg is set to null if there is no error
message. inflateInit does not perform any decompression apart from reading
the zlib header if present: this will be done by inflate(). (So next_in and
avail_in may be modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may some
introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. inflate performs one or both of the
following actions:
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing
will resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there
is no more input data or no more space in the output buffer (see below
about the flush parameter).
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for
example when the output buffer is full (avail_out == 0), or after each
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
output as possible to the output buffer. The flushing behavior of inflate is
not specified for values of the flush parameter other than Z_SYNC_FLUSH
and Z_FINISH, but the current implementation actually flushes as much output
as possible anyway.
inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step
(a single call of inflate), the parameter flush should be set to
Z_FINISH. In this case all pending input is processed and all pending
output is flushed; avail_out must be large enough to hold all the
uncompressed data. (The size of the uncompressed data may have been saved
by the compressor for this purpose.) The next operation on this stream must
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
is never required, but can be used to inform inflate that a faster routine
may be used for the single inflate() call.
If a preset dictionary is needed at this point (see inflateSetDictionary
below), inflate sets strm-adler to the adler32 checksum of the
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
it sets strm->adler to the adler32 checksum of all output produced
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
an error code as described below. At the end of the stream, inflate()
checks that its computed adler32 checksum is equal to that saved by the
compressor and returns Z_STREAM_END only if the checksum is correct.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
corrupted (input stream not conforming to the zlib format or incorrect
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
case, the application may then call inflateSync to look for a good
compression block.
*/
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated).
*/
/* Advanced functions */
/*
The following functions are needed only in some special applications.
*/
/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by
the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead.
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but
is slow and reduces compression ratio; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
string match). Filtered data consists mostly of small values with a
somewhat random distribution. In this case, the compression algorithm is
tuned to compress them better. The effect of Z_FILTERED is to force more
Huffman coding and less string matching; it is somewhat intermediate
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
the compression ratio but not the correctness of the compressed output even
if it is not set appropriately.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
method). msg is set to null if there is no error message. deflateInit2 does
not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called
immediately after deflateInit, deflateInit2 or deflateReset, before any
call of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy; the data can then be compressed better than
with the default empty dictionary.
Depending on the size of the compression data structures selected by
deflateInit or deflateInit2, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size in
deflate or deflate2. Thus the strings most likely to be useful should be
put at the end of the dictionary, not at the front.
Upon return of this function, strm->adler is set to the Adler32 value
of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.)
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and
can consume lots of memory.
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
The stream will keep the same compression level and any other attributes
that may have been set by deflateInit2.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
/*
Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2. This can be
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different
strategy. If the compression level is changed, the input available so far
is compressed with the old level (and may be flushed); the new level will
take effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/
/*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
before by the caller.
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used
instead. If a compressed stream with a larger window size is given as
input, inflate() will return with the error code Z_DATA_ERROR instead of
trying to allocate a larger window.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
memLevel). msg is set to null if there is no error message. inflateInit2
does not perform any decompression apart from reading the zlib header if
present: this will be done by inflate(). (So next_in and avail_in may be
modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the Adler32 value returned by this call of
inflate. The compressor and decompressor must use exactly the same
dictionary (see deflateSetDictionary).
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
expected one (incorrect Adler32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of
inflate().
*/
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
case, the application may save the current current value of total_in which
indicates where valid compressed data was found. In the error case, the
application may repeatedly call inflateSync, providing more input each time,
until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
The stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
/* utility functions */
/*
The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some
default options are assumed (compression level and memory usage,
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
*/
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be at least 0.1% larger than
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
compressed buffer.
This function can be used to compress a whole file at once if the
input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
*/
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level));
/*
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
typedef voidp gzFile;
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
Huffman only compression as in "wb1h". (See the description
of deflateInit2 for more information about the strategy parameter.)
gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression.
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR). */
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen).
The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
*/
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description
of deflateInit2 for the meaning of these parameters.
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
opened for writing.
*/
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number
of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
const voidp buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written (0 in case of error).
*/
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
*/
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
Reads bytes from the compressed file until len-1 characters are read, or
a newline character is read and transferred to buf, or an end-of-file
condition is encountered. The string is then terminated with a null
character.
gzgets returns buf, or Z_NULL in case of error.
*/
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
*/
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
*/
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function. The return value is the zlib
error number (see function gzerror below). gzflush returns Z_OK if
the flush parameter is Z_FINISH and all output could be flushed.
gzflush should be called only when strictly necessary because it can
degrade compression.
*/
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
/*
Sets the starting position for the next gzread or gzwrite on the
given compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new
starting position.
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
would be before the current position.
*/
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
Rewinds the given file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
error occurred in the file system and not in the compression library,
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
/* checksum functions */
/*
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
*/
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application.
Usage example:
uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
*/
/* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel,
int strategy, const char *version,
int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
ZEXTERN const char * ZEXPORT zError OF((int err));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
#ifdef __cplusplus
}
#endif
#endif /* _ZLIB_H */

View File

@ -0,0 +1,448 @@
#if !defined (READASTM_H)
#define READASTM_H
#pragma once
#include "PDSMath/StdAfx.h"
#include <iostream>
//#include <afxtempl.h>
#include "GroupCode.h"
//某曲线层的信息
class CCurveLayerInfor : public CObject
{
public:
CCurveNotchInforList m_listCurveLayer; //将圆弧,椭圆都转成控制点
CCurveNotchInforList m_listCurveCheckLayer; //该层校验层 将圆弧,椭圆都转成控制点
CPointDataList m_listTurnPointLayer; //该层转折点 记录POINT的数据 该变量对SPline 圆弧,圆,椭圆无效
CPointDataList m_listCurvePointLayer; //该层曲线点 记录POINT的数据 该变量对SPline圆弧椭圆无效
CTextDataList m_listPointGrade; //记录标志符为TEXT/MTEXT的放码点序号
public:
CCurveLayerInfor(void);
CCurveLayerInfor(CCurveLayerInfor& a);
~CCurveLayerInfor(void);
void operator=(CCurveLayerInfor& a);
void Initial(void);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
//void SetScale(double dScale);
//设置层中的点类型和放码ID
//输入参数:
// listPointGrade 放码点
// listTurnPointLayer 转折点
// listCurvePointLayer 曲线点
//说明:
// 先查找this中的如果没有再在传入的中查找
void SetPointTypeGradeID(CTextDataList &listPointGrade, CPointDataList &listTurnPointLayer, CPointDataList &listCurvePointLayer);
private:
//根据效验层点确定曲线点
//将在点链listAllValidatePoint中但是没有在listAllPoint中的点加入到listCurvePoint中
//输入参数:
// listAllPoint 曲线层
// listAllValidatePoint 校验层
//输入输出:
// listCurvePoint 曲线点
void FindCurvePoint(CPointDataList &listAllPoint, CPointDataList &listAllValidatePoint, CPointDataList &listCurvePoint);
};
//AAMA/ASTM的块信息
class CAMBlockInfor : public CObject
{
public:
//文件中读入的数据
CString m_strBlockName; //为了记录BLOCK的块名(在组码2的后面)
CString m_strPatternName; //纸样名
CString m_strSizeName; //号型名
BOOL m_bBaseSize; //=true 表示为基码;=false 不是, 这个用于在款式信息中没有读到基码号型是使用, 默认False
CString m_strComment; //注释COMMENT/ANNOTATION
CStringArray m_arrMaterial; //布料名
CUIntArray m_arrQuantity; //总片布料份数 Quantity:<R,L>
CUIntArray m_arrLQuantity; //左片布料份数 Quantity:<R,L>
//m_arrQuantity, m_arrLQuantity大小保持一致
BOOL m_bFlip; //翻转信息 =true 允许翻转
double m_dRotation; //最大倾斜角 Rotation<0...360>
BOOL m_bFold; //折叠 Fold:<Y/N> =true 允许折叠
double m_dTilt; //最大倾斜角度 Tilt:<+/-0..90>
CCurveLayerInfor m_Layer1; //第1层 边线
CCurveLayerInfor m_Layer14; //第14层缝份线
CCurveLayerInfor m_Layer8; //第8层辅助线
CCurveLayerInfor m_Layer11; //第11层 内部裁剪线
CCurveNotchInfor m_CurveLayer5; //放码线
CCurveNotchInfor m_CurveLayer6; //对称线
CCurveNotchInfor m_CurveLayer7; //布纹线
CCurveNotchInforList m_listCurveLayer910; //条格线
CCurveLayerInfor m_Layer; //除以上之外的所有层, 将圆弧,椭圆都转成控制点, m_listTurnPointLayer/m_listCurvePointLayer/m_listPointGrade存放该块中读入的所有放码点转折点曲线点
CTextDataList m_listTextData; //记录标志符为TEXT/MTEXT的数据 T文字
//CNotchInforList m_listNotchInfo; //剪口信息
CDrillInforList m_listDrillInfo; //13层或者Circle标识符钻孔信息
CInsertDataList m_listInsertData_Block; //块中插入信息
public:
CStringArray m_arrCategory; //20180614 记录CATEGORY字段CATEGORY作为布料还是注释 根据情况而定,读入时另外保存
public:
CAMBlockInfor(void);
CAMBlockInfor(CAMBlockInfor& a);
~CAMBlockInfor(void);
void operator=(CAMBlockInfor& a);
void Initial(void);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
//void SetScale(double dScale);
//设置块中的点类型和放码ID
//[输入] bAllInfor = true使用所有层设置;=false使用对应层设置
void SetPointTypeGradeID(BOOL bAllInfor);
//20180614 判断m_arrCategory是否为布料名如果是放入m_arrMaterial中如果不是放入m_strComment中
void DisposeMaterilaName();
private:
void CopyBlockInfor(CAMBlockInfor &a);
};
class CAMBlockInforList : public CList<CAMBlockInfor,CAMBlockInfor&>
{
public:
CAMBlockInforList& operator=(CAMBlockInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CAMBlockInfor& operator[](int iIndex);
//位置偏移,旋转和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
//void SetScale(double dScale);
//设置块中的点类型和放码ID
//[输入] bAllInfor = true使用所有层设置;=false使用对应层设置
void SetPointTypeGradeID(BOOL bAllInfor);
//将给定号型名替换成给定字符串
//输入参数:
// strOldSizeName 旧号型名
// strNewSizeName 新号型名
void ReplaceSizeName(CString strOldSizeName, CString strNewSizeName);
//在给定名称的号型对应的纸样链
//输入参数:
// strSizeName 需要查找到号型名
//输出参数:
// listBlockInfor 找到的纸样列表
//返回值:
// =true 找到;=false 没有找到
BOOL FindSizeName(CString strSizeName, CAMBlockInforList &listBlockInfor);
};
//放码文件中的数据
class CRulInfor : public CObject
{
public:
BOOL m_bReadRul; //=true 表示读了rul文件
int m_iUnit; //= CONST_MM METRICmm= CONST_INCH ENGLISH : 英寸; 默认mm
int m_iSizeCount; //号型个数
CString m_strSampleSize; //基码
CList<CString, CString> m_listAllSize; //所有号型 大小与m_iSizeCount一致
int m_iGradeCount; //放码量个数
CPointData **m_pRulData; //m_RulData[iSizeIndex][iGradeIndex]
public:
CRulInfor(void);
CRulInfor(CRulInfor& a);
~CRulInfor(void);
void operator=(CRulInfor& a);
void Initial(void);
//放缩
//输入参数:
//dScale 放大缩小比例
//说明:
// 不需要偏移,放码量本身是相对量
void SetScale( double dScale);
private:
void DeleteElta();
};
//Entities信息
class CAMEntitiesInfor : public CObject
{
public:
CString m_strStyleName; //Style Name:<string>
CString m_strSampleSize; //基码Sample Size:<string>
int m_iUnit; //= CONST_MM METRICmm= CONST_INCH ENGLISH : 英寸; 默认mm
CString m_strGradeRulTable; //放码文件rul Grade Rule Table:<string>
CString m_strAuthor; //作者Author:<Vendor name>;<application>;<release #》
CString m_strVersion; //输出的软件版本号
CInsertDataList m_listInsertData;
public:
CAMEntitiesInfor(void);
CAMEntitiesInfor(CAMEntitiesInfor& a);
~CAMEntitiesInfor(void);
void operator=(CAMEntitiesInfor& a);
void Initial(void);
};
class CASTMFileInfor : public CObject
{
public:
// 注意:
//m_listBlockInfor和 m_listSameSizeBlockInfor中的数据是一样的只能选其一使用
//初始值为dxf文件中读到信息
CString m_strSampleSize; //基码, 在处理读入数据时基码以该变量为准
CList<CString, CString> m_listAllSize; //所有号型(不重复) 在处理读入数据时号型个数以该变量为准
CAMBlockInforList m_listBlockInfor; //读Block数据
CAMEntitiesInfor m_EntitiesInfor; //读Entities数据
CRulInfor m_rulInfor; //放码数据
public:
CASTMFileInfor(void);
CASTMFileInfor(CASTMFileInfor& a);
~CASTMFileInfor(void);
void operator=(CASTMFileInfor& a);
void Initial(void);
};
//读文件
/*
1.;
*/
class CReadASTMFile: public CObject
{
public:
CASTMFileInfor m_FileInfo; //读入的所有文件内容
private:
FILE *m_pDXFFile; //文件指针
BOOL m_bReadWindowText; //=ture 读Window/Dos文本文件=false 读Unix/Linux下文本文件
CString m_strFileName; //读取的文件名,同时也可以作为放码文件名
CString m_strValue1, m_strValue2; //用于读组码和数据
BOOL m_bOnlyReadBaseSize; //true 仅读基码
BOOL m_bPattern; //=true 读纸样;=false 结构线
int m_iAllInfor; //确定放码点和曲线转折点 = -1 没有确定 0 使用所有层设置;=1使用对应层设置
public:
CReadASTMFile(void);
~CReadASTMFile(void);
//读入文件
//输入参数:
// strFilePath 文件路径
// bPattern =true 纸样, false 结构线, 结构线不用读rul
// bOnlyReadBaseSize =true 仅读基码, 读纸样有效
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能TIIP文件
int ReadASTMFile(CString strFilePath, BOOL bPattern, BOOL bOnlyReadBaseSize);
protected:
//20200903 XQ 读一行文本
void ReadAString(FILE *fFile, CString &strString1);
//读组码
//[输入] fFile 文件
//[输出] strString1/strString2 连续两行数据
void ReadGroupString(FILE *fFile, CString &strString1, CString &strString2);
//读入文件
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能是TIIP文件
int ReadASTMFile();
//读BLOCK信息
//输出参数:
// BlockInfor 读到的信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能TIIP文件
//说明:
// 返回值为0时BlockInfor才有效
int ReadBlock(CAMBlockInfor &BlockInfor);
//读POLYLINE
//输出信息
// BlockInfor 块信息
// iLayer 所在的层
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能TIIP文件
//说明:
// 返回值为0时BlockInfor才有效
int ReadPolylineData(CAMBlockInfor &BlockInfor, int &iLayer);
//读POLYLINE数据
//输出参数:
// CurveInfor 点信息
// listCurvePoint 曲线点信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能TIIP文件
//说明:
// 返回值为0时CurveInfor才有效
int ReadPolylineData(CCurveNotchInfor &CurveInfor, CPointDataList &listCurvePoint);
//读LINE
//输出信息
// BlockInfor 块信息
// iLayer 所在的层
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能TIIP文件
//说明:
// 返回值为0时BlockInfor才有效
int ReadLineData(CAMBlockInfor &BlockInfor, int &iLayer);
//读LINE
int ReadLineData(CCurveNotchInfor &CurveInfor);
//读TEXT
void ReadTEXTData(CAMBlockInfor &BlockInfor, int iLayer);
//读标识符TEXT信息
BOOL ReadTEXTData(CTextData &TextData);
//纸样基本信息
//输入参数:
// BlockInfor 块信息
// strInformation 纸样的信息字符串
//返回值:
// =true表示为纸样基本信息 =false 不是为T文字
BOOL PatternInfor(CAMBlockInfor &BlockInfor, CString strInformation);
//读POINT
void ReadPointData(CAMBlockInfor &BlockInfor, int iLayer);
//读剪口数据
//输出参数:
// NotchInfor 剪口数据
//返回值:
//= true输出参数可用=false输出参数不可用
BOOL ReadNotch(CNotchInfor &NotchInfor);
//读钻孔数据
//输出参数:
// DrillInfor 钻孔数据
//返回值:
//= true输出参数可用=false输出参数不可用
BOOL ReadDrill(CDrillInfor &DrillInfor);
//读CIRCLE
void ReadCircleData(CAMBlockInfor &BlockInfor);
//读ARC
int ReadArcData(CAMBlockInfor &BlockInfor, int &iLayer);
//读ARC
BOOL ReadArcData(CCurveNotchInfor &CurveInfor);
//读INSERT
void ReadInsertData(CAMBlockInfor &BlockInfor);
BOOL ReadInsertInfor(CInsertData &InsertData);
//读Entities信息
//输出参数:
// EntitiesInfor 读到的信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 不是AAMA/ASTM文件
int ReadEntities(CAMEntitiesInfor &EntitiesInfor);
//款式基本信息
//输入参数:
// EntitiesInfor 块信息
// strInformation 纸样的信息字符串
//返回值:
// =true表示为款式基本信息 =false 不是
BOOL StyleInfor(CAMEntitiesInfor &EntitiesInfor, CString strInformation);
//读放码文件
void ReadRulFile();
//读rul文件中的放码信息
void ReadRulSize(FILE *pRulFile);
//读rul文件中的放码量
void ReadRulGradeValue(FILE *pRulFile);
//处理文件读入的数据
void DisposeFileData();
//处理纸样边线存在多段
void DisPosePatternBorder();
};
#endif

View File

@ -0,0 +1,485 @@
#if !defined (READAUTCAD_H)
#define READAUTCAD_H
#pragma once
#include "PDSMath/StdAfx.h"
#include <iostream>
//#include <afxtempl.h>
#include "GroupCode.h"
/////////////////////////////////Start: CDimension/////////////////////////////////////////
//标注组码, 目前只识别一种标注
class CDimension : public CGroupCode
{
public:
int m_iType; // -1 = 初始化值
// 0 = 转角标注、水平标注或垂直标注
// 1 = 对齐标注
// 2 = 角度标注
// 3 = 直径标注
// 4 = 半径标注
// 5 = 角度三点标注
// 6 = 坐标标注
// 32 = 标注信息在给定的块中
CString m_strBlockName;
CPointData m_ptLU; //文字显示的位置
//标注的显示位置坐标
CPointData m_ptPoint0;
CPointData m_ptPoint1;
CPointData m_ptPoint2;
CPointData m_ptPoint3;
CPointData m_ptPoint4;
CPointData m_ptPoint5;
CPointData m_ptPoint6;
BOOL m_bNoString; //=true 表示标注没有字符串,字符串需要根据计算得到; false 标注字符串为m_strDimension
CString m_strDimension; //用户明确地输入了标注文字(可选,缺省值为测量结果) 如果为空或"<>",以文字方式标注测量结果; 如果为 " "(一个空格),禁止输出文字
public:
CDimension(void);
CDimension(CDimension& a);
~CDimension(void);
BOOL operator==(CDimension& a);
void operator=(CDimension& a);
void Initial(void);
//处理读入的数据
//返回值:
// true 数据可用 =false数据不可用
BOOL DisPoseReadData();
//处理字符串
//说明:
//将读入的字符串"{\fSimSun|b0|i0|c134|p2;线性}",处理为"线性"
void DisPoseText(CString &strString);
//标注设置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(0,0), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//将标注转成字符串信息
//输出参数:
// TextData 字符串信息
void TransText(CTextData &TextData);
};
class CDimensionList : public CList<CDimension,CDimension&>
{
public:
CDimensionList& operator=(CDimensionList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CDimension& operator[](int iIndex);
//标注位置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(0,0), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//将标注转成字符串
void TransText(CTextDataList &listTextData);
};
//////////////////////////////////End: CDimension////////////////////////////////////////
//////////////////////////////////Start: CSolidInfor////////////////////////////////////////
class CSolidInfor : public CGroupCode
{
public:
CCurveNotchInfor m_CurveInfor;
public:
CSolidInfor(void);
CSolidInfor(CSolidInfor& a);
~CSolidInfor(void);
void operator=(CSolidInfor& a);
void Initial(void);
//设置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(0,0), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
//void SetScale(double dScale);
};
class CSolidInforList : public CList<CSolidInfor,CSolidInfor&>
{
public:
CSolidInforList& operator=(CSolidInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CSolidInfor& operator[](int iIndex);
//标注位置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(0,0), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//得到链表中所有曲线
void GetCurveInforList(CCurveNotchInforList &listCurveInfor);
};
///////////////////////////////////End: CSolidInfor///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//Auto CAD中块信息
class CAuBlockInfor : public CObject
{
public:
CString m_strBlockName; //为了记录BLOCK的块名(在组码2的后面)
CString m_strPatternName; //纸样名
CString m_strSizeName; //号型名
CStringArray m_arrMaterial; //布料名
CUIntArray m_arrQuantity; //总片布料份数 Quantity:<R,L>
//纸样名号型名两个变量是为了防止客户使用AutoCAD读ASTM/TIIP文件
CCurveNotchInforList m_listCurveInfo; //所有的线信息
CTextDataList m_listTextData; //记录标志符为TEXT/MTEXT的数据
CPointDataList m_listPointInfo; //所有点 记录POINT的数据
CDimensionList m_listDimension; //标注信息
CSolidInforList m_listSolidInfor; //实体信息, 标注中的三角形
CInsertDataList m_listInsertData_Block; //块中插入信息
//在m_listCurveInfo/m_listArcCircle/m_listEllispse中找出纸样块
CPatternBlockList m_listPatternBlock; //纸样块
public:
CAuBlockInfor(void);
CAuBlockInfor(CAuBlockInfor& a);
~CAuBlockInfor(void);
void operator=(CAuBlockInfor& a);
void Initial(void);
//位置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(0,0), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//判断该块是否为空块
//返回值:
// =true 是;=false不是
//说明:
// 空块是没有任何数据,即所有链表为空
BOOL IsEmptyBlock();
//得到纸样块信息存在在m_listPatternBlock中
void GetPatternBlock();
private:
//得到纸样块
//输入参数:
// listAllCurveInfor 所有曲线
// listTextData 所有文字
//输出参数:
// listPatternBlock 纸样块
void GetPatternBlock(CCurveNotchInforList &listAllCurveInfor, CTextDataList &listTextData, CPointDataList &listPointInfo, CPatternBlockList &listPatternBlock);
};
class CAuBlockInfoList : public CList<CAuBlockInfor,CAuBlockInfor&>
{
public:
CAuBlockInfoList& operator=(CAuBlockInfoList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CAuBlockInfor& operator[](int iIndex);
//根据给定的块名找出对应的块
//[输入] strBlockName 块名
//[输出] BlockInfor 找到的块
//返回值:
// 找到块的位置, 没有找到返回NULL
POSITION FindBlockName(CString strBlockName, CAuBlockInfor &BlockInfor);
//标注位置偏移
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(0,0), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//删除空块(没有任何数据的块)
void DeleteEmptyBlock();
//得到纸样块
void GetPatternBlock();
};
//////////////////////////////////////////////////////////////////////////
//TABLE ->LTYPE
class CLTypeInfor : public CObject
{
public:
//说明: 由于AutoCAD文件中输出的类型都是通过代号表示的这里都使用字符串
CString m_strLTypeName; //线型名称
CString m_strDescribe; //描述
public:
CLTypeInfor(void);
CLTypeInfor(CLTypeInfor& a);
~CLTypeInfor(void);
void operator=(CLTypeInfor& a);
void Initial(void);
};
class CLTypeInforList : public CList<CLTypeInfor,CLTypeInfor&>
{
public:
CLTypeInforList& operator=(CLTypeInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CLTypeInfor& operator[](int iIndex);
};
//////////////////////////////////////////////////////////////////////////
//TABLE ->LAYER
class CLayerInfor : public CObject
{
public:
//说明: 由于AutoCAD文件中输出的类型都是通过代号表示的这里都使用字符串
CString m_strLayerName; //图层名
int m_iStandard; //标准标志值
/*
m_iStandard ()
1 =
2 =
4 =
*/
CString m_strColor; //颜色数
CString m_strLineType; //线型名
public:
CLayerInfor(void);
CLayerInfor(CLayerInfor& a);
~CLayerInfor(void);
void operator=(CLayerInfor& a);
void Initial(void);
};
class CLayerInforList : public CList<CLayerInfor,CLayerInfor&>
{
public:
CLayerInforList& operator=(CLayerInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CLayerInfor& operator[](int iIndex);
//给定的层名对应颜色
//输入参数:
// strLayerName 层名
//返回值:
// 层名对应颜色;没有为空
CString FindColor(CString strLayerName);
};
//////////////////////////////////////////////////////////////////////////
class CAuTableInfor : public CObject
{
public:
//说明: 由于AutoCAD文件中输出的类型都是通过代号表示的所有这里都使用字符串
CLTypeInforList m_listLType; //标识符 LTYPE 整个文件所用线型
CLayerInforList m_listLayer; //标识符 LAYER 整个文件图层信息, Entities可以包含该列表中没有的图层信息
public:
CAuTableInfor(void);
CAuTableInfor(CAuTableInfor& a);
~CAuTableInfor(void);
void operator=(CAuTableInfor& a);
void Initial(void);
};
//////////////////////////////////////////////////////////////////////////
class CAutoCADFileInfo : public CObject
{
public:
CAuBlockInfoList m_listBlockInfor;
CAuBlockInfor m_EntitiesInfor;
//层信息
CAuTableInfor m_TableInfor; //层信息 TABLES
public:
CAutoCADFileInfo(void);
CAutoCADFileInfo(CAutoCADFileInfo& a);
~CAutoCADFileInfo(void);
void operator=(CAutoCADFileInfo& a);
void Initial(void);
//得到纸样块
//m_listBlockInfor/m_EntitiesInfor中信息转成CPatternBlockList
void GetPatternBlock();
//除去隐藏不用的BLOCK
void RemoveUnUseBlock();
};
/*
1.;
*/
class CReadAutoCAD: public CObject
{
public:
CAutoCADFileInfo m_FileInfo; //读入的所有文件内容
private:
FILE *m_pDXFFile; //文件指针
BOOL m_bReadWindowText; //=ture 读Window/Dos文本文件=false 读Unix/Linux下文本文件
CString m_strValue1, m_strValue2; //用于读组码和数据
BOOL m_bPattern; //=true要创建纸样=false 结构线
BOOL m_bReadSolid; //=true填充标识线=false 不读入
public:
CReadAutoCAD(void);
~CReadAutoCAD(void);
//读入文件
//输入参数:
// strFilePath 文件路径
// bPattern = true 读入纸样;=false 结构线
// bReadSolid = true读入填充标识线=false不读入 20210902 XQ
BOOL ReadAutoCADFile(CString strFilePath, BOOL bPattern, BOOL bReadSolid);
private:
//读组码
//[输入] fFile 文件
//[输出] strString1/strString2 连续两行数据
void ReadGroupString(FILE *fFile, CString &strString1, CString &strString2);
//读数据
// 返回值:
// =true 读数据成功;=false 读数据失败
//说明:
//读入数据存放在m_FileInfo
BOOL ReadFileData();
//读TABLE信息
// TableInfor读到的TABLE信息
// 返回值:
// =true 读数据成功;=false 读数据失败
//说明:
// 在函数中不能对TableInfor初始化
BOOL ReadTableData(CAuTableInfor &TableInfor);
//读标识符LAYER
BOOL ReadLayerData(CLayerInfor &LayerInfor);
//读标识符LTYPE
BOOL ReadLTypeData(CLTypeInfor &LTypeInfor);
//读BLOCK信息
// BlockInfor读到的BLOCK信息
// bReadBlock =true 读BLOCK=false读ENTITIES
// 返回值:
// =true 读数据成功;=false 读数据失败
BOOL ReadBlockData(CAuBlockInfor &BlockInfor, BOOL bReadBlock);
//读标识符ARC信息
BOOL ReadArcData(CCurveNotchInfor &ArcCircleData);
//读标识符CIRCLE信息
BOOL ReadCircleData(CCurveNotchInfor &ArcCircleData);
//读标识符ELLIPSE信息
BOOL ReadEllipseData(CCurveNotchInfor &EllipseData);
//读标识符LINE信息
BOOL ReadLineData(CCurveNotchInfor &CurveInfor);
//读标识符MLINE信息
BOOL ReadMLineData(CCurveNotchInfor &CurveInfor);
//读标识符POLYLINE信息
BOOL ReadPolylineData(CCurveNotchInfor &CurveInfor);
//读标识符LWPOLYLINE信息
BOOL ReadLWPolylineData(CCurveNotchInfor &CurveInfor);
//读标识符SPLINE信息
BOOL ReadSPLineData(CCurveNotchInfor &CurveInfor);
//读标识符TEXT信息
BOOL ReadTEXTData(CTextData &TextData);
//分析字符串是否为纸样名称或者号型名称
//[输入] strRef 参考字符串
//[输出] strName 名称 该值只有在返回值大于0时有效
//返回值:
// =0 不是任何名称
// =1 纸样名称
// =2 号型名称
// =3 布料名
// =4 布料份数
int NameSizeInfor(CString strRef, CString &strName);
//读标识符MTEXT信息
BOOL ReadMTEXTData(CTextData &TextData);
//读标识符POINT信息
BOOL ReadPointData(CPointData &PointData);
//读标识符DIMENSION信息
BOOL ReadDimensionData(CDimension &Dimension);
//读标识符SOLID信息
BOOL ReadSolidData(CSolidInfor &SolidInfor);
//读标识符INSERT信息
BOOL ReadInsertData(CInsertData &InsertData);
//计算SPline曲线
// pBlockInfor 需要计算SPline的块
void CalcuateSPlineCurve(CAuBlockInfor *pBlockInfor);
};
#endif

View File

@ -0,0 +1,196 @@
#if !defined (READDXFFILE_H)
#define READDXFFILE_H
#include "PDSMath/StdAfx.h"
#include <iostream>
//#include <afxtempl.h>
#include "ReadAutoCAD.h"
#include "ReadASTM.h"
#include "ReadTIIP.h"
//////////////////////////////////////////////////////////////////////////
//款式信息
class CStyleInfo : public CObject
{
public:
CString m_strStyleName;
CString m_strBaseSizeName;
CList<CString, CString> m_listAllSize;
int m_iUnit; //0 mm;=1 Inch
CString m_strAuthor;
CString m_strVersion; //20180127 版本号
CStyleInfo(void);
CStyleInfo(CStyleInfo& a);
~CStyleInfo(void);
void operator=(CStyleInfo& a);
void Initial(void);
};
class CReadDxfData : public CObject
{
public:
int m_iDPMM;
//款式信息,款式号型信息
CStyleInfo m_StyleInfo;
BOOL m_bPattern; //=true 纸样;=false结构线
//结构线信息
CCurveNotchInforList m_listCurveOfFile; //文件中所有点线信息
CTextDataList m_listTextOfFile; //文件中所有字符信息
CLayerInforList m_listLayer;
//纸样信息
CPatternBlockList m_listPattern; //纸样
//放码量 该变量只有读入rul文件有用
int m_iGradeCount; //放码量个数
int m_iSizeCount; //号型个数
//m_iSizeCount, m_iGradeCount只对m_RulData起作用
CPointData **m_pRulData; //m_RulData[iSizeIndex][iGradeIndex]
public:
CReadDxfData(void);
CReadDxfData(CReadDxfData& a);
~CReadDxfData(void);
void operator=(CReadDxfData& a);
void Initial(void);
CRect GetRect();
//计算实际点链
void CalcuateActualPoint(int iDPMM);
//20200219 XQ 计算给定纸样的实际点链
//[输入][输出] pPatternBlock 纸样
void CalcuateActualPoint(int iDPMM, CPatternBlock *pPatternBlock);
//放缩
//输入参数:
//dScale 放大缩小比例
//说明:
// 不需要偏移,放码量本身是相对量
void SetScale(double dScale);
//颜色
//输入参数:
// strLayer 颜色所有在层
//返回值:
//颜色
COLORREF GetColor(CString strLayer);
//查找颜色表(Auto CAD 根据索引对应颜色)
//输入参数:
// strColor 颜色索引
COLORREF FinColorTable(CString strColor);
//得到线形
//输入参数:
// iFileType = 0 ASTM/AAMA;=1 TIIP;=2 AutoCAD
// strCurveViewType 文件读入的线形
//返回值:
// 系统线形PS_SOLID...
int GetCurveType(int iFileType, CString strCurveViewType);
private:
void DeleteElta();
void CopyData(CReadDxfData &a);
//TIIP文件线形转换
//输入参数:
// iValue 文件中的值
//返回值:
// 系统的线类型
int CurveType_TIIP(int iValue);
};
//读入文件
//输入参数:
// strFilePath文件路径
// bPattern =true读纸样false 结构线
// bReadSolid = true读入填充标识线=false不读入 20210902 XQ
//输出参数:
// AutoCADDxfData 读入数据
//返回值:
// =true 读入正确;=false读入错误
BOOL ReadAutoCADFile(CString strFilePath, BOOL bPattern, BOOL bReadSolid, CReadDxfData &AutoCADDxfData);
//将读入的数据转成输出的数据
//[输入] EntitiesInfor 读入数据
//[输入] bPattern =true读纸样false 结构线
//[输出] AutoCADDxfData 输出数据
void GetAutoCADDxfData(CAutoCADFileInfo FileInfo, BOOL bPattern, CReadDxfData &AutoCADDxfData);
//得到输出数据
//[输入] BlockInfor 块信息
//[输入] listBlockInfor 所有块信息
//[输入][输出] listCurveOfFile 线条信息
//[输入][输出] listTextOfFile 文本信息
//[输入] dOffsetX/dOffsetY插入位置
//[输入] dSin, dCos 旋转角度
//[输入] dScaleX/dScaleY 放大缩小 20220408 XQ
void GetAutoCADDxfData(CAuBlockInfor BlockInfor, CAuBlockInfoList &listBlockInfor, CCurveNotchInforList &listCurveOfFile, CTextDataList &listTextOfFile, double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//将读入的数据转成输出的数据
//输入参数:
// strFilePath 文件路径
// bPattern =true 纸样, false 结构线, 结构线不用读rul
// bOnlyReadBaseSize =true 仅读基码, 读纸样有效
//输出参数:
//ASTMDxfData 输出数据
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能TIIP文件
int ReadASTMFile(CString strFilePath, BOOL bPattern, BOOL bOnlyReadBaseSize, CReadDxfData &ASTMDxfData);
//将读入的数据转成输出的数据
//输入参数:
// FileInfo 文件信息
// bPattern =true 纸样, false 结构线, 结构线不用读rul
// bOnlyReadBaseSize =true 仅读基码, 读纸样有效
//输出参数:
//ASTMDxfData 输出数据
void GetASTMData(CASTMFileInfor FileInfo, BOOL bPattern, BOOL bOnlyReadBaseSize, CReadDxfData &ASTMDxfData);
//将CAMBlockInfor转CPatternBlock类型
BOOL TrantsAMPatternBlock(CString strAuthor, CAMBlockInfor BlockInfor, CPatternBlock &PatternBlock);
//将读入的数据转成输出的数据
//输入参数:
// strFilePath 文件路径
// bPattern =true 纸样, false 结构线, 结构线不用读rul
// bOnlyReadBaseSize =true 仅读基码, 读纸样有效
//输出参数:
//AutoCADDxfData 输出数据
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM/AAMA文件
int ReadTIIPFile(CString strFilePath, BOOL bPattern, BOOL bOnlyReadBaseSize, CReadDxfData &AutoCADDxfData);
//将读入的数据转成输出的数据
//输入参数:
// FileInfo 文件信息
// bPattern =true 纸样, false 结构线, 结构线不用读rul
// bOnlyReadBaseSize =true 仅读基码, 读纸样有效
//输出参数:
//AutoCADDxfData 输出数据
void GetTIIPData(CTIIPFileInfor FileInfo, BOOL bPattern, BOOL bOnlyReadBaseSize, CReadDxfData &AutoCADDxfData);
//将CTPBlockInfor转CPatternBlock类型
BOOL TrantsTPPatternBlock(CTPBlockInfor BlockInfor, CPatternBlock &PatternBlock);
#endif

View File

@ -0,0 +1,309 @@
#if !defined (READTIIP_H)
#define READTIIP_H
#pragma once
#include "PDSMath/StdAfx.h"
#include <iostream>
//#include <afxtempl.h>
#include <QObject>
#include "GroupCode.h"
//TIIP的块信息
class CTPBlockInfor : public QObject
{
public:
//文件中读入的数据
CString m_strBlockName; //为了记录BLOCK的块名(在组码2的后面)
CString m_strPatternName; //纸样名
CString m_strSizeName; //号型名
CStringArray m_arrComment; //注释COMMENT/ANNOTATION
CStringArray m_arrMaterial; //布料名 Fabric
CUIntArray m_arrQuantity; //布料份数 Quantity
CCurveNotchInforList m_Layer1; //第1层 边线
CCurveNotchInforList m_Layer2; //第2层缝份线
CCurveNotchInforList m_Layer5; //第5层辅助线
CCurveNotchInforList m_Layer6; //第6层 内部裁剪线
CCurveNotchInfor m_CurveLayer7; //放码线
CCurveNotchInfor m_CurveLayer4; //对称线
CCurveNotchInfor m_CurveLayer3; //布纹线
CTextDataList m_listTextData; //T文字
CDrillInforList m_listDrillInfo; //钻孔信息
public:
CTPBlockInfor(void);
CTPBlockInfor(CTPBlockInfor& a);
~CTPBlockInfor(void);
void operator=(CTPBlockInfor& a);
void Initial(void);
//位置偏移和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
private:
//拷贝数据
void CopyData(CTPBlockInfor &a);
};
class CTPBlockInforList : public CList<CTPBlockInfor,CTPBlockInfor&>
{
public:
CTPBlockInforList& operator=(CTPBlockInforList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CTPBlockInfor& operator[](int iIndex);
//位置偏移,旋转和放缩
//输入参数:
//dOffsetX/dOffsetY 偏移量
//dSin/dCos 旋转角度, 旋转点为CPoint(dOffsetX, dOffsetY), 水平为零度
//dScaleX/dScaleY 放大缩小 20220408 XQ
//说明:
// 偏移->旋转->放大缩小
void SetRotateOffset(double dOffsetX, double dOffsetY, double dSin, double dCos, double dScaleX, double dScaleY);
//设置放大
//输入参数:
//dScale 放大缩小比例
void SetScale(double dScale);
//将给定号型名替换成给定字符串
//输入参数:
// strOldSizeName 旧号型名
// strNewSizeName 新号型名
void ReplaceSizeName(CString strOldSizeName, CString strNewSizeName);
//在给定名称的号型对应的纸样链
//输入参数:
// strSizeName 需要查找到号型名
//输出参数:
// listBlockInfor 找到的纸样列表
//返回值:
// =true 找到;=false 没有找到
BOOL FindSizeName(CString strSizeName, CTPBlockInforList &listBlockInfor);
};
//Entities信息
class CTPEntitiesInfor : public CObject
{
public:
CString m_strStyleName; //Style Name:<string>
CString m_strSampleSize; //基码Sample Size:<string>
int m_iUnit; //= CONST_MM METRICmm= CONST_INCH ENGLISH : 英寸; 默认mm
CString m_strAuthor; //作者Author:<Vendor name>;<application>;<release #》
CString m_strVersion; //输出软件版本号
CInsertDataList m_listInsertData;
public:
CTPEntitiesInfor(void);
CTPEntitiesInfor(CTPEntitiesInfor& a);
~CTPEntitiesInfor(void);
void operator=(CTPEntitiesInfor& a);
void Initial(void);
};
class CTIIPFileInfor : public CObject
{
public:
// 注意:
//m_listBlockInfor和 m_listSameSizeBlockInfor中的数据是一样的只能选其一使用
//初始值为dxf文件中读到信息
CString m_strSampleSize; //基码, 在处理读入数据时基码以该变量为准
CList<CString, CString> m_listAllSize; //所有号型(不重复) 在处理读入数据时号型个数以该变量为准
CTPBlockInforList m_listBlockInfor; //读Block数据
CTPEntitiesInfor m_EntitiesInfor; //读Entities数据
public:
CTIIPFileInfor(void);
CTIIPFileInfor(CTIIPFileInfor& a);
~CTIIPFileInfor(void);
void operator=(CTIIPFileInfor& a);
void Initial(void);
};
//读文件
/*
1.;
*/
class CReadTIIPFile: public CObject
{
public:
CTIIPFileInfor m_FileInfo; //读入的所有文件内容
private:
FILE *m_pDXFFile; //文件指针
BOOL m_bReadWindowText; //=ture 读Window/Dos文本文件=false 读Unix/Linux下文本文件
CString m_strFileName; //读取的文件名,同时也可以作为放码文件名
CString m_strValue1, m_strValue2; //用于读组码和数据
// BOOL m_bOnlyReadBaseSize; //true 仅读基码
// BOOL m_bPattern; //=true 读纸样;=false 结构线
public:
CReadTIIPFile(void);
~CReadTIIPFile(void);
//读入文件
//输入参数:
// strFilePath 文件路径
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM/AAMA文件
int ReadTIIPFile(CString strFilePath);
protected:
//读组码
//[输入] fFile 文件
//[输出] strString1/strString2 连续两行数据
void ReadGroupString(FILE *fFile, CString &strString1, CString &strString2);
//读入文件
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM/AAMA文件
int ReadTIIPFile();
//读BLOCK信息
//输出参数:
// BlockInfor 读到的信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM文件
//说明:
// 返回值为0时BlockInfor才有效
int ReadBlock(CTPBlockInfor &BlockInfor);
//分析组码999的字符串值
//输入参数:
// strValue 组码999的字符串值
//输出参数:
// iValue1 第一个数值 图元类型
// iValue2 第二个数值 点类型
// iValue3 第三个数值 剪口
// iValue4 第四个数值 放码ID
//说明:
// 当strValue中没有四个值时没有的等于-1
void Dispose999Value(CString strValue, int &iValue1, int &iValue2, int &iValue3, int &iValue4);
//读POLYLINE
//输出信息
// BlockInfor 块信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM文件
//说明:
// 返回值为0时BlockInfor才有效
int ReadPolylineData(CTPBlockInfor &BlockInfor);
//读POLYLINE
//输出信息
// CurveInfor 读的线包含剪口
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM文件
//说明:
// 返回值为0时CurveInfor才有效
int ReadPolylineData(CCurveNotchInfor &CurveInfor);
//读LINE
//输出信息
// BlockInfor 块信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM文件
//说明:
// 返回值为0时BlockInfor才有效
int ReadLineData(CTPBlockInfor &BlockInfor);
//读LINE
//输出信息
// CurveInfor 直线两点
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM文件
//说明:
// 返回值为0时CurveInfor才有效
int ReadLineData(CCurveNotchInfor &CurveInfor);
//读TEXT
//输出信息
// BlockInfor 块信息
void ReadTEXTData(CTPBlockInfor &BlockInfor);
//读标识符TEXT信息
BOOL ReadTEXTData(CTextData &TextData);
//纸样基本信息
//输入参数:
// BlockInfor 块信息
// strInformation 纸样的信息字符串
//返回值:
// =true表示为纸样基本信息 =false 不是为T文字
BOOL PatternInfor(CTPBlockInfor &BlockInfor, CString strInformation);
//读POINT
//输出信息
// BlockInfor 块信息
void ReadPointData(CTPBlockInfor &BlockInfor);
//读Entities信息
//输出参数:
// EntitiesInfor 读到的信息
//返回值:
// = 0 读入成功
// = 1 文件打不开
// = 2 可能是AutoCAD文件
// = 3 可能ASTM文件
int ReadEntities(CTPEntitiesInfor &EntitiesInfor);
//款式基本信息
//输入参数:
// EntitiesInfor 块信息
// strInformation 纸样的信息字符串
//返回值:
// =true表示为款式基本信息 =false 不是
BOOL StyleInfor(CTPEntitiesInfor &EntitiesInfor, CString strInformation);
BOOL ReadInsertInfor(CInsertData &InsertData);
//处理文件读入的数据
void DisposeFileData();
};
#endif

View File

@ -0,0 +1,219 @@
#if !defined (WRITEASTM_H)
#define WRITEASTM_H
#include "WriteDxfFile.h"
class CWriteASTM : public CObject
{
private:
CWriteDxfData m_Data;
CString m_strFilePath; //文件路径(全)
//int m_iFileType; // =0 只输出基码;=1 输出所有码带rul=2 输出所有码所有码都在dxf不带rul
int m_iOutputType; // =0 ASTM; =1 AAMA
//BOOL m_bSeamToAssistant; //=true 缝份线按辅助线输出;=false 缝份线按缝份输出
FILE *m_pDXFFile; //文件指针
CPoint m_ptPatternOffset; //纸样偏移
double m_dScale;
float m_fTextHeight, m_fTextDeltaY; //字体高度,文字间隔
public:
CWriteASTM();
~CWriteASTM();
//输出AAMA、ASTM文件
//输入参数:
// strPath 保存文件路径(全路径)
// OutputType =0 ASTM; =1 AAMA
// DxfData 需要输出的数据
//返回值:
// =true 输出正确;=false路径无法保存
BOOL WriteFile(CString strPath, int iOutputType, CWriteDxfData &DxfData);
private:
void Initial();
//纸样坐标转换成设备坐标
//输入参数:
// ptPoint 纸样坐标
//输出参数:
// fx, fy 对应的设备坐标的X和Y值
void PttnToDP(CPoint ptPoint, float &fx, float &fy);
//输出所有纸样块
//说明
//文件m_pDXFFile 数据m_Data
void WriteBlockS();
//输出纸样块
// 输入参数:
// pPatternData 输出块信息
// bBaseSize 基码
//说明
//文件m_pDXFFile 数据m_Data
void WriteBlock(CPatternData *pPatternData, BOOL bBaseSize);
//输出纸样基本信息
//输入参数:
// pPatternData 纸样信息
// bBaseSize 基码
void WritePatternInfo(CPatternData *pPatternData, BOOL bBaseSize);
//输出边线
//输入参数:
// listBorder 边线链
// bBorder =true 边线;=false 缝份
// listNotch 剪口, 在该边线中输出了的剪口从链表中删除
void WriteBorder(CCurveIDataList &listBorder, BOOL bBorder, CNotchIDataList &listNotch);
//输出辅助线
//输入参数:
// listAssistantCurve 辅助线链
void WriteAssistantCurve(CCurveIDataList &listAssistantCurve);
//输出圆弧
//输入数据:
// pFile 写入的文件指针
// CurveData 圆弧数据
// iLayer 层
//返回值:
// =true 该数据输出;=false 该数据没有输出
BOOL WriteArc(FILE *pFile,CCurveIData CurveData, int iLayer);
//输出圆
//输入数据:
// pFile 写入的文件指针
// CurveData 圆数据
// iLayer 层
//返回值:
// =true 该数据输出;=false 该数据没有输出
BOOL WriteCircle(FILE *pFile,CCurveIData CurveData, int iLayer);
//输出钻孔
//输入参数:
// listDrill 钻孔链
void WriteDrill(CDrillIDataList &listDrill);
//20190527 XQ 输出文本文字
//输入参数:
// listText文本文字链
void WriteText(CTextIDataList &listText);
//输出布纹线
//输入参数:
// GrainLine 布纹线
void WriteGrainLine(CCurveIData GrainLine);
//输出放码线
//输入参数:
// GrainLine 布纹线
//说明:
//放码线按照布纹线中点,输出水平线
void WriteGradeLine(CCurveIData GrainLine);
//输出对称轴
//输入参数:
// SymmetryLine 对称轴
void WriteSymmetry(CCurveIData SymmetryLine);
//写POLYLINE
// pFile 写入的文件指针
// iLayer 所在的层
// listPoint 多段线点链(纸样坐标)
// bClose =true 折线是封闭的 =false 折线是开口的
void WritePolyLine(FILE *pFile,int iLayer, CPointIDataList &listPointData, BOOL bClose);
//写POLYLINE
// pFile 写入的文件指针
// iLayer 所在的层
// listPoint 多段线点链(纸样坐标)
// bClose =true 折线是封闭的 =false 折线是开口的
void WritePolyLine(FILE *pFile,int iLayer, CList<CPoint, CPoint> &listPoint, BOOL bClose);
//写LINE
// pFile 写入的文件指针
// iLayer 所在的层
// ptPointS, ptPointE 直线的两点(纸样坐标)
void WriteLine(FILE *pFile,int iLayer, CPointIData PointIDataS, CPointIData PointIDataE);
//写多线段顶点
// pFile 写入的文件指针
// iLayer 所在的层
// ptPoint 点坐标(纸样坐标)
void WriteVertex(FILE *pFile, int iLayer, CPoint ptPoint);
//写点
// pFile 写入的文件指针
// iLayer 所在的层
// ptPoint 点坐标
void WritePoint(FILE *pFile, int iLayer, CPoint ptPoint);
//写剪口
// pFile 写入的文件指针
// NotchData 剪口数据
//说明:
// 角度是与水平线的夹角
void WriteNotch(FILE *pFile, CNotchIData NotchData);
//写放码标识符文本
//输入参数:
// pFile 写入的文件指针
// iLayer 所在的层
// ptGrade 放码点
// iGradeIndex 放码索引
void WriteGradeText(FILE *pFile, int iLayer, CPoint ptGrade, int iGradeIndex);
//写字符串文本
//输入参数:
// pFile 写入的文件指针
// iLayer 所在的层
// TextData 文本
void WriteText(FILE *pFile, int iLayer, CTextIData TextData);
//输出Entities
//说明
//文件m_pDXFFile 数据m_Data
void WrtieEntities();
//写插入信息
//输入参数:
// fFile 写入的文件指针
// fx, fy 插入坐标(显示器坐标)
// strBlockName 块名
// dAngle 角度
void WriteInsert(FILE *fFile, float fx, float fy, CString strBlockName, double dAngle);
//写字符串文本
//输入参数:
// fFile 写入的文件指针
// iLayer 所在的层
// fx, fy 字符串坐标(显示器坐标)
// strString 字符串信息
void WriteEntitiesText(FILE *fFile, int iLayer, float fx, float fy, CString strString);
void WriteRule();
void WriteRule_Empty();
//输出rul头部分
//输入参数:
// pRulFile 文件
// StyleInfo 款式信息
// strFileName rul文件名称
void WriteRuleHead(FILE *pRulFile, CWriteStyleInfo StyleInfo, CString strFileName);
//输出rul内容部分
//输入参数:
// pRulFile 文件
// pRulData 放码数据
// iSizeCount 号型总数
// iGradeCount 放码点总数
void WriteRule(FILE *pRulFile, CPoint **pRulData, int iSizeCount, int iGradeCount);
};
#endif

View File

@ -0,0 +1,170 @@
#if !defined (WRITEAUTOCAD_H)
#define WRITEAUTOCAD_H
#include "WriteDxfFile.h"
class CWriteAutoCAD : public CObject
{
private:
double m_dScale;
CPoint m_ptPatternOffset; //纸样偏移
CWriteDxfData m_Data;
FILE *m_pDXFFile; //文件指针
int m_iHandleIndex; //句柄索引
BOOL m_bVer15; //=true输出R15 输出控制点有Spline=false输出R12 输出实际点链
public:
CWriteAutoCAD();
~CWriteAutoCAD();
void Initial();
//写文件
//输入参数:
// strPath; 文件全路径
// Data 输出的数据
// bVer15 true输出R15 输出控制点有Spline=false输出R12 输出实际点链
//返回值:
// =true 输出正确;=false路径无法保存
BOOL WriteFile(CString strPath, CWriteDxfData &DxfData, BOOL bVer15);
private:
//纸样坐标转换成设备坐标
//输入参数:
// ptPoint 纸样坐标
//输出参数:
// fx, fy 对应的设备坐标的X和Y值
void PttnToDP(CPoint ptPoint, float &fx, float &fy);
//得到句柄
//返回值:
// 句柄字符
//文件中所有的句柄都不能相同
CString GetHandle();
//输出HEADER
//说明
//文件m_pDXFFile
void WriteHEADER();
void WriteHEADER_12();
void WriteHEADER_15();
//输出TABLE
//说明
//文件m_pDXFFile
void WriteTABLES();
void WriteTABLES_12();
void WriteTABLES_15();
//输出BLOCKS
//说明
//文件m_pDXFFile 数据m_Data
void WriteBLOCKS();
void WriteBLOCKS_15();
//输出纸样块
// 输入参数:
// PatternData 输出块信息
//说明
//文件m_pDXFFile 数据m_Data
void WriteBLOCK(CPatternData &PatternData);
//输出Entities
//说明
//文件m_pDXFFile 数据m_Data
void WriteENTITIES();
//输出曲线
//输入参数:
// iLayer 所属层
// listCurveOfFile 曲线,所有曲线都在给定层
void WriteCurve(int iLayer, CCurveIDataList &listCurveOfFile);
//输出圆弧
//输入参数:
// iLayer 所属层
// CurveData 曲线
void WriteArc(int iLayer, CCurveIData &CurveData);
//输出圆
//输入参数:
// iLayer 所属层
// CurveData 曲线
void WriteCircle(int iLayer, CCurveIData &CurveData);
//输出点
//输入参数:
// iLayer 所属层
// PointData 点
void WritePoint(int iLayer, CPoint ptPoint);
//输出直线
//输入参数:
// iLayer 所属层
// ptHead/ ptTail 直线两点
void WriteLine(int iLayer, CPoint ptHead, CPoint ptTail, COLORREF crColor);
//输出折线
//输入参数:
// iLayer 所属层
// CurveData 曲线
void WritePolyline(int iLayer, CCurveIData &CurveData);
//输出折线
//输入参数:
// iLayer 所属层
// CurveData 曲线
void WriteLWPolyline(int iLayer, CCurveIData &CurveData);
//输出曲线
//输入参数:
// iLayer 所属层
// CurveData 曲线
void WriteSpline(int iLayer, CCurveIData &CurveData);
//输出VERTEX
//输入参数:
// iLayer 所属层
// ptPoint 输出点
void WriteVertex(int iLayer, CPoint ptPoint);
//输出文本
//输入参数:
// iLayer 所属层
// listTextOfFile 文本,所有文本都在给定层
void WriteTexts(int iLayer, CTextIDataList &listTextOfFile);
//写文本
//输入参数:
// pfWrite 文件
// iLayer 所属层
// TextData 文本
void WriteText(int iLayer, CTextIData TextData);
//写文本
//输入参数:
// iLayer 所属层
// TextData 文本
void WriteMText(int iLayer, CTextIData TextData);
//写插入
//输入参数:
// strInsertName 插入名字
// PointData 插入文字
// dAngle 角度
void WriteInsert(CString strInsertName, CPoint PointData, double dAngle);
//转换成AutoCAD颜色索引
CString ConvertColor(COLORREF crColor);
void WriteOBJECT();
};
#endif

View File

@ -0,0 +1,343 @@
#if !defined (WRITEDXFFILE_H)
#define WRITEDXFFILE_H
#include "StdAfx.h"
#include <iostream>
#include <afxtempl.h>
//点类型
#define POINT_TURN 0
#define POINT_CURVE 1
#define POINT_ARC 2
//曲线类型
#define CURVE_POLYLINE 0
#define CURVE_ARC 1
#define CURVE_CIRCLE 2
#define CURVE_SPLINE 3 //只用于AutoCAD
//剪口类型
#define NOTCH_T 0
#define NOTCH_I 1
#define NOTCH_U 2
#define NOTCH_V 3
//款式信息
class CWriteStyleInfo : public CObject
{
public:
CPoint m_ptDesignOffset; //款式开始坐标(系统坐标)
CString m_strStyleName;
CString m_strBaseSizeName;
CList<CString, CString> m_listAllSize;
CWriteStyleInfo(void);
CWriteStyleInfo(CWriteStyleInfo& a);
~CWriteStyleInfo(void);
void operator=(CWriteStyleInfo& a);
void Initial(void);
};
/////////////////////////////////////////////////////////////////////////
class CPointIData : public CObject
{
public:
CPoint m_ptPoint;
int m_iGradeIndex;
int m_iPointType; //POINT_TURN
public:
CPointIData(void);
CPointIData(CPointIData& a);
~CPointIData(void);
void operator=(CPointIData& a);
void Initial(void);
};
class CPointIDataList : public CList<CPointIData,CPointIData&>
{
public:
CPointIDataList& operator=(CPointIDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CPointIData& operator[](int iIndex);
};
//////////////////////////////////////////////////////////////////////////
class CCurveIData : public CObject
{
public:
CPointIDataList m_listCtrlPoint; //控制点链
CList<CPoint, CPoint> m_listActualPoint; //实际点链
BOOL m_bClose; //=true闭合=false 开口
int m_iCurveType; //=CURVE_ARC, CURVE_CIRCLE, CURVE_POLYLINE
int m_iDrawType; //线形
COLORREF m_crColor; //颜色
int m_iLayer; //曲线所在的层
//说明:
/* 根据曲线类型确定输出数据:
CURVE_ARC m_listCtrlPoint 线 m_listActualPoint为实际点链
CURVE_CIRCLE m_listCtrlPoint 线 m_listActualPoint为实际点链
CURVE_POLYLINE m_listCtrlPoint为曲线输出控制点 m_listActualPoint为实际点链 m_listCtrlPoint与m_listActualPoint值是一样的
CURVE_SPLINE指用于AutoCAD的输出
CURVE_SPLINE m_listCtrlPoint为曲线经过的控制点 m_listActualPoint为曲线不经过的控制点 m_listActualPoint点的个数是m_listCtrlPoint点个数* 4 - 4
*/
public:
CCurveIData(void);
CCurveIData(CCurveIData& a);
~CCurveIData(void);
void operator=(CCurveIData& a);
void Initial(void);
private:
void CopyData(CCurveIData &a);
};
class CCurveIDataList : public CList<CCurveIData,CCurveIData&>
{
public:
CCurveIDataList& operator=(CCurveIDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CCurveIData& operator[](int iIndex);
//得到链表所有控制点, 不包含重复点
//输出参数:
// listPointData 链表中所有控制点,控制点顺序按照链表顺序输出
void GetCtrlPointIData(CPointIDataList &listPointData);
//得到链表所有实际点, 不包含重复点
//输出参数:
// listPoint 链表中所有实际点,实际点顺序按照链表顺序输出
void GetActualPoint(CList<CPoint, CPoint> &listPoint);
};
//////////////////////////////////////////////////////////////////////////
//文字
class CTextIData : public CObject
{
public:
CPointIData m_PointData;
CString m_strText;
double m_dHeight; //单位 mm
double m_dAngle; //与水平方向的角度
public:
CTextIData(void);
CTextIData(CTextIData& a);
~CTextIData(void);
void operator=(CTextIData& a);
void Initial(void);
};
class CTextIDataList : public CList<CTextIData,CTextIData&>
{
public:
CTextIDataList& operator=(CTextIDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CTextIData& operator[](int iIndex);
};
//////////////////////////////////////////////////////////////////////////
//钻孔信息
class CDrillIData : public CObject
{
public:
CPointIData m_ptDrill;
public:
CDrillIData(void);
CDrillIData(CDrillIData& a);
~CDrillIData(void);
void operator=(CDrillIData& a);
void Initial(void);
};
class CDrillIDataList : public CList<CDrillIData,CDrillIData&>
{
public:
CDrillIDataList& operator=(CDrillIDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CDrillIData& operator[](int iIndex);
};
//////////////////////////////////////////////////////////////////////////
//剪口信息
class CNotchIData : public CObject
{
public:
BOOL m_bBorder; //=true 边线剪口;=false 缝份剪口
CPointIData m_ptNotch;
int m_iType; //剪口类型,输出的层类型 480,81,82,83
int m_iWidth; // 剪口宽度 系统单位
int m_iHeight; //剪口深度 系统单位
BOOL m_bAngle; //=true剪口角度输出=false剪口角度不输出
double m_dAngle; //剪口角度与X轴角度
public:
CNotchIData(void);
CNotchIData(CNotchIData& a);
~CNotchIData(void);
void operator=(CNotchIData& a);
void Initial(void);
};
class CNotchIDataList : public CList<CNotchIData,CNotchIData&>
{
public:
CNotchIDataList& operator=(CNotchIDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CNotchIData& operator[](int iIndex);
//根据给定,找到对应剪口
//输入参数:
// ptPoint 剪口点
//返回值:
// == NULL 没有找到;=false 找到
POSITION FindNotch(CPoint ptPoint);
//查找边线/缝份上的剪口
//输入参数:
// bBorder = true 边线;=false 缝份
//输出参数:
// listNotch 对应线上的剪口
void GetNotch(BOOL bBorder, CNotchIDataList &listNotch);
};
//////////////////////////////////////////////////////////////////////////
//说明:
// 按 AutoCAD输出时只输出m_listBorder/m_listSeam/m_listAssistantCurve/m_listText/ m_ptOffset/m_dAngle
class CPatternData : public CObject
{
public:
CString m_strBlockName; //块名
CString m_strPatternName; //纸样名
CString m_strSizeName; //号型名
CString m_strComment; //注释COMMENT/ANNOTATION
CStringArray m_arrMaterial; //布料名
CUIntArray m_arrQuantity; //总片布料份数 Quantity:<R,L>
CUIntArray m_arrLQuantity; //左片布料份数 Quantity:<R,L>
//m_arrQuantity, m_arrLQuantity大小保持一致
BOOL m_bFlip; //翻转信息 =true 允许翻转
double m_dRotation; //最大倾斜角 Rotation<0...360>
BOOL m_bFold; //折叠 Fold:<Y/N> =true 允许折叠
double m_dTilt; //最大倾斜角度 Tilt:<+/-0..90>
CCurveIDataList m_listBorder; //边线
CCurveIDataList m_listSeam; //缝份线
CCurveIDataList m_listAssistantCurve; //辅助线
CTextIDataList m_listText; //字符串
CNotchIDataList m_listNotch; //剪口 剪口点最好在控制点上,要不然剪口没有输出出去
CDrillIDataList m_listDrill; //钻孔
CCurveIData m_GrainLine; //布纹线
CCurveIData m_SymmetryLine; //对称轴
//纸样的偏移和旋转角度旋转点为CPoint(0,0), 水平为零度
CPoint m_ptOffset;
double m_dAngle;
public:
CPatternData(void);
CPatternData(CPatternData& a);
~CPatternData(void);
void operator=(CPatternData& a);
void Initial(void);
private:
void CopyData(CPatternData &a);
};
class CPatternDataList : public CList<CPatternData,CPatternData&>
{
public:
CPatternDataList& operator=(CPatternDataList& rhs); // 赋值
//获取指定索引值上的项
//输入参数:
// iIndex 索引值,从0开始,不可越界
//返回值:
CPatternData& operator[](int iIndex);
//设置块名
//说明:
// 目前按照在列表中索引命名
void SetBlockName();
};
//////////////////////////////////////////////////////////////////////////
class CWriteDxfData : public CObject
{
public:
int m_iDPMM;
//款式信息,款式号型信息
CWriteStyleInfo m_StyleInfo;
//结构线信息
CCurveIDataList m_listCurveOfFile; //文件中所有点线信息
CTextIDataList m_listTextOfFile; //文件中所有字符信息
//纸样信息
CPatternDataList m_listPattern; //纸样
//放码量 该变量只有读入rul文件有用
int m_iGradeCount; //放码量个数
int m_iSizeCount; //号型个数
//m_iSizeCount, m_iGradeCount只对m_RulData起作用
CPoint **m_pRulData; //m_RulData[iSizeIndex][iGradeIndex]
public:
CWriteDxfData(void);
CWriteDxfData(CWriteDxfData& a);
~CWriteDxfData(void);
void operator=(CWriteDxfData& a);
void Initial(void);
private:
void DeleteElta();
void CopyData(CWriteDxfData &a);
};
//写文件
//输入参数:
// strPath; 文件全路径
// iFileType; = 0 ASTM文件= 1 AAMA文件; =2 AutoCAD文件
// Data 输出的数据
// bAutoCADVer15 =true输出R15 输出控制点有Spline=false输出R12 输出实际点链, 只用于AutoCAD
//返回值:
// =true 输出正确;=false路径无法保存
//说明:
// 单位按mm处理
BOOL WriteFile( CString strPath, int iFileType, CWriteDxfData &Data, BOOL bAutoCADVer15);
//纸样坐标转换成设备坐标
//输入参数:
// ptPoint 纸样坐标
//输出参数:
// fx, fy 对应的设备坐标的X和Y值
void PttnToDP(double dScale, CPoint ptOffset, CPoint ptPoint, float &fx, float &fy);
#endif

View File

@ -3,8 +3,7 @@
#include <QObject>
#include <QTextCodec>
#include "dxflib/dl_dxf.h"
#include "dxflib/dl_creationadapter.h"
#include "dxflib/ReadDxfFile.h"
#include <QMetaType>
#include <QtCore/QList>

View File

@ -693,6 +693,7 @@ void ImportHPGL::AddPoint2listXY(QPoint ptPoint)
{
double angle, sina, cosa;
double rcx, rcy;
angle = sina = cosa = rcx = rcy = 0;
if(m_rotateAngle != 0)
{

View File

@ -1,11 +1,14 @@
#include "drawdata.h"
QPicture creatPictureByData(Marker marker, QPainterPath &painterPath, int penWidth)
CreatPictureStr creatPictureByData(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
QPainterPath painterPath;
CBitmapInfo bitmapInfo;
QRect rect = marker.GetRect();
int minX = rect.left();
int maxY = rect.bottom();
int rectSize = 20;//20毫米-对接符矩形框大小
int blockSpace = 50;//50毫米-块与块之间的间距
int nLineCount = marker.m_listPolyline.size();
for(int i = 0; i < nLineCount; i++)
@ -43,14 +46,14 @@ QPicture creatPictureByData(Marker marker, QPainterPath &painterPath, int penWid
int lux = bitmapInfo.m_ptAbPostLU.x();
int luy = bitmapInfo.m_ptAbPostLU.y();
int nlux = (lux - minX)/M_IDPMM*MMPIXELY;
int nluy = (maxY-luy)/M_IDPMM*MMPIXELY;
int nluy = (maxY - luy)/M_IDPMM*MMPIXELY;
bitmapInfo.m_ptAbPostLU.setX(nlux);
bitmapInfo.m_ptAbPostLU.setY(nluy);
int rdx = bitmapInfo.m_ptAbPostRD.x();
int rdy = bitmapInfo.m_ptAbPostRD.y();
int nrdx = (rdx - minX)/M_IDPMM*MMPIXELY;
int nrdy = (maxY-rdy)/M_IDPMM*MMPIXELY;
int nrdy = (maxY - rdy)/M_IDPMM*MMPIXELY;
bitmapInfo.m_ptAbPostRD.setX(nrdx);
bitmapInfo.m_ptAbPostRD.setY(nrdy);
}
@ -61,13 +64,162 @@ QPicture creatPictureByData(Marker marker, QPainterPath &painterPath, int penWid
qDebug()<<"painterPath.isEmpty";
}
//将路径画在picture上
QPicture pic;
QPen pen(Qt::black, penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
//pen.setCosmetic(true); // 对于固定宽度的笔划很有用
CreatPictureStr picStr;
QPen pen;
pen.setWidth(1);//设置笔号像素为1用于显示的pic
pen.setColor(QColor(Qt::black));
QPainter painter;
painter.begin(&pic);
//当纸张宽度不够打印时需要对接打印
int width = rect.width()/M_IDPMM;
int length = rect.height()/M_IDPMM;
if(rightSpace != 0)
{
if(paperWidth >= length)
{
paperWidth = length - rightSpace;
}
}
double oft = paperWidth*MMPIXELY;
if(width <= rectSize)
{
rectSize = width / 2;
blockSpace = rectSize / 2;
}
int square = rectSize*MMPIXELY;
if(paperWidth < length)
{
int seNum = length / paperWidth;
if(length % paperWidth != 0)
{
seNum += 1;
}
butSpace += rectSize;
int num = width / butSpace;
double space = (double)width / (double)num;
for(int m = 0; m < seNum-1; m++)
{
for(int i = 0; i < num; i++)
{
//绘制对接符5mm的正方形里面是交叉线X
//添加正方形path
int x = i*space * MMPIXELY;
int y = oft + m * oft - square / 2;
painterPath.moveTo(x,y);
QRectF rect(x,y,square,square);
painterPath.addRect(rect);
//添加交叉线(X)
QPointF diagonalStart(rect.left(), rect.top());
QPointF diagonalEnd(rect.right(), rect.bottom());
painterPath.moveTo(diagonalStart);
painterPath.lineTo(diagonalEnd);
// 另一条对角线
QPointF otherDiagonalStart(rect.right(), rect.top());
QPointF otherDiagonalEnd(rect.left(), rect.bottom());
painterPath.moveTo(otherDiagonalStart);
painterPath.lineTo(otherDiagonalEnd);
}
}
QPainterPath pathSegments[seNum];
splitPaintPath(painterPath,oft,seNum,pathSegments);
int startx,starty,targetWidth,targetHeight,blockSize,bmpNum;
if(bitmapInfo.m_iBytes > 0)//有位图
{
startx = bitmapInfo.m_ptAbPostLU.x();
starty = bitmapInfo.m_ptAbPostLU.y();
targetWidth = abs(bitmapInfo.m_ptAbPostRD.x() - bitmapInfo.m_ptAbPostLU.x());
targetHeight = abs(bitmapInfo.m_ptAbPostRD.y() - bitmapInfo.m_ptAbPostLU.y());
blockSize = paperWidth * MMPIXELY;
if(targetHeight > blockSize)
{
bmpNum = targetHeight / blockSize;
if(targetHeight % blockSize != 0)
{
bmpNum += 1;
}
}
}
painter.begin(&picStr.showPic);
painter.setPen(pen);
int oftH = 0;
int oftW = 0;
for(int i = 0; i < seNum; i++)
{
if(i != 0)
{
oftH = 0 - pathSegments[i].boundingRect().height();
oftW = pathSegments[i].boundingRect().width() + blockSpace * MMPIXELY;
}
painter.translate(oftW, oftH);
painter.drawPath(pathSegments[i]);
int boftH = i*(0 - (starty + oftH));
if(targetHeight > blockSize)
{
int bmpH = bitmapInfo.m_pBitmap.height() / bmpNum;
int bmpOft = i*bmpH;
painter.drawPixmap(startx,boftH,targetWidth,blockSize,bitmapInfo.m_pBitmap,
startx,bmpOft, bitmapInfo.m_pBitmap.width(), bmpH);
}
else
{
if(startx <= abs(oftW) && starty <= abs(oftH))
{
painter.drawPixmap(startx,boftH,targetWidth,targetHeight,bitmapInfo.m_pBitmap,
startx,starty, bitmapInfo.m_pBitmap.width(), bitmapInfo.m_pBitmap.height());
}
}
}
painter.end();
painter.begin(&picStr.sendPic);
pen.setWidth(penWidth);
painter.setPen(pen);
oftH = 0;
oftW = 0;
for(int i = 0; i < seNum; i++)
{
if(i != 0)
{
oftH = 0 - pathSegments[i].boundingRect().height();
oftW = pathSegments[i].boundingRect().width() + blockSpace * MMPIXELY;
}
painter.translate(oftW, oftH);
painter.drawPath(pathSegments[i]);
int boftH = i*(0 - (starty + oftH));
if(targetHeight > blockSize)
{
int bmpH = bitmapInfo.m_pBitmap.height() / bmpNum;
int bmpOft = i*bmpH;
painter.drawPixmap(startx,boftH,targetWidth,blockSize,bitmapInfo.m_pBitmap,
startx,bmpOft, bitmapInfo.m_pBitmap.width(), bmpH);
}
else
{
if(startx <= abs(oftW) && starty <= abs(oftH))
{
painter.drawPixmap(startx,boftH,targetWidth,targetHeight,bitmapInfo.m_pBitmap,
startx,starty, bitmapInfo.m_pBitmap.width(), bitmapInfo.m_pBitmap.height());
}
}
}
painter.end();
return picStr;
}
//将路径画在picture上
painter.begin(&picStr.showPic);
painter.setPen(pen);
painter.drawPath(painterPath);
if(bitmapInfo.m_iBytes > 0)//有位图
@ -79,26 +231,79 @@ QPicture creatPictureByData(Marker marker, QPainterPath &painterPath, int penWid
int targetHeight = abs(bitmapInfo.m_ptAbPostRD.y() - bitmapInfo.m_ptAbPostLU.y());
painter.drawPixmap(startx,starty,targetWidth,targetHeight,bitmapInfo.m_pBitmap,
startx,starty, bitmapInfo.m_pBitmap.width(), bitmapInfo.m_pBitmap.height());
// painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap);
// painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap);
}
painter.end();
return pic;
painter.begin(&picStr.sendPic);
pen.setWidth(penWidth);
painter.setPen(pen);//设置笔号像素为penWidth用于发送的pic
painter.drawPath(painterPath);
if(bitmapInfo.m_iBytes > 0)//有位图
{
int startx = bitmapInfo.m_ptAbPostLU.x();
int starty = bitmapInfo.m_ptAbPostLU.y();
//bitmapInfo.m_pBitmap.save("D:\\1.bmp");
int targetWidth = abs(bitmapInfo.m_ptAbPostRD.x() - bitmapInfo.m_ptAbPostLU.x());
int targetHeight = abs(bitmapInfo.m_ptAbPostRD.y() - bitmapInfo.m_ptAbPostLU.y());
painter.drawPixmap(startx,starty,targetWidth,targetHeight,bitmapInfo.m_pBitmap,
startx,starty, bitmapInfo.m_pBitmap.width(), bitmapInfo.m_pBitmap.height());
// painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap);
}
painter.end();
return picStr;
}
QPicture creatPictureByBmp(QPixmap pixmap,int penWidth)
CreatPictureStr creatPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
//将图片画在picture上
QPicture pic;
CreatPictureStr picStr;
QPen pen;
pen.setWidth(penWidth);//设置笔号
pen.setWidth(1);//设置笔号
pen.setColor(QColor(Qt::black));
int height = pixmap.height() / MMPIXELY;
if(rightSpace != 0)
{
if(paperWidth >= height)
{
paperWidth = height - rightSpace;
}
}
QPainter painter;
painter.begin(&pic);
painter.begin(&picStr.showPic);
painter.setPen(pen);
painter.drawPixmap(0,0,pixmap);
if(height > paperWidth)
{
//功能未实现
if(butSpace == 0)//为了去掉警告
{
}
}
else
{
painter.drawPixmap(0,0,pixmap);
}
painter.end();
return pic;
pen.setWidth(penWidth);//设置笔号
pen.setColor(QColor(Qt::black));
painter.begin(&picStr.sendPic);
painter.setPen(pen);
if(height > paperWidth)
{
//功能未实现
}
else
{
painter.drawPixmap(0,0,pixmap);
}
painter.end();
return picStr;
}
void creatMarkerDat(McFilesInfo &curFilesInfo, QString printDir, QString filePath, int fileIdx, double angle)
@ -181,3 +386,197 @@ void creatMarkerDat(McFilesInfo &curFilesInfo, QString printDir, QString filePat
curFilesInfo.m_selectBlockNum = 0;//当前选择块数
curFilesInfo.m_creatDataFlag = 1;
}
void splitPaintPath(QPainterPath originalPath,double segmentHeight,int segmenNum,QPainterPath *pathSegments)
{
QPainterPath::Element element = originalPath.elementAt(0);
QPointF firstPoint(element.x, element.y);
qreal currentY = 0;
pathSegments[0].moveTo(firstPoint);
for (int i = 1; i < originalPath.elementCount(); i++)
{
QPainterPath::Element element = originalPath.elementAt(i);
QPointF curPoint(element.x, element.y);
QPointF prePoint(originalPath.elementAt(i-1).x, originalPath.elementAt(i-1).y);
QPointF prePot = prePoint;
int addFlag = 0;
for(int j = 0; j < segmenNum; j++)
{
currentY = segmentHeight + segmentHeight * j;
//在此块内
if(curPoint.y() <= currentY && curPoint.y() >= (currentY - segmentHeight) &&
prePoint.y() <= currentY && prePoint.y() >= (currentY - segmentHeight))
{
if (element.type == QPainterPath::MoveToElement)
{
pathSegments[j].moveTo(prePot);
pathSegments[j].moveTo(curPoint);
}
if (element.type == QPainterPath::LineToElement)
{
pathSegments[j].moveTo(prePot);
pathSegments[j].lineTo(curPoint);
}
addFlag = 1;
break;
}
}
//未添加时继续判断
if(addFlag == 0)
{
//跨块,要判断跨了几块,求出交点
//判断prePoint在哪个块
int preIdx = 0;
int curIdx = 0;
int flag = 0;
for(int m = 0; m < segmenNum; m++)
{
qreal height = segmentHeight + segmentHeight * m;
//在此块内
if(prePoint.y() <= height && prePoint.y() >= (height - segmentHeight))
{
preIdx = m;
flag |= 1;
}
//在此块内
if(curPoint.y() <= height && curPoint.y() >= (height - segmentHeight))
{
curIdx = m;
flag |= 2;
}
if(flag == 3)
{
break;
}
}
//从上到下
if(preIdx < curIdx)
{
for(int p = preIdx; p < curIdx+1; p++)
{
currentY = segmentHeight + segmentHeight * p;
QPointF intersection;
if (lineIntersection(prePoint, curPoint, currentY, &intersection))
{
if (element.type == QPainterPath::MoveToElement)
{
pathSegments[p].moveTo(prePot);
pathSegments[p].moveTo(intersection);
if(curPoint.y() < currentY + segmentHeight)
{
if(p+1 < segmenNum)
{
pathSegments[p+1].moveTo(intersection);
pathSegments[p+1].moveTo(curPoint);
}
}
}
if (element.type == QPainterPath::LineToElement)
{
pathSegments[p].moveTo(prePot);
pathSegments[p].lineTo(intersection);
if(curPoint.y() < currentY + segmentHeight)
{
if(p+1 < segmenNum)
{
pathSegments[p+1].moveTo(intersection);
pathSegments[p+1].lineTo(curPoint);
}
}
}
prePot = intersection;
}
}
}
else
{
//从下到上
for(int p = preIdx+1; p > curIdx; p--)
{
currentY = segmentHeight * p - segmentHeight;
QPointF intersection;
if (lineIntersection(curPoint, prePoint, currentY, &intersection))
{
if (element.type == QPainterPath::MoveToElement)
{
pathSegments[p-1].moveTo(prePot);
pathSegments[p-1].moveTo(intersection);
if(curPoint.y() > currentY - segmentHeight)
{
if(p-1-1 >= 0)
{
pathSegments[p-1-1].moveTo(intersection);
pathSegments[p-1-1].moveTo(curPoint);
}
}
}
if (element.type == QPainterPath::LineToElement)
{
pathSegments[p-1].moveTo(prePot);
pathSegments[p-1].lineTo(intersection);
if(curPoint.y() > currentY - segmentHeight)
{
if(p-1-1 >= 0)
{
pathSegments[p-1-1].moveTo(intersection);
pathSegments[p-1-1].lineTo(curPoint);
}
}
}
prePot = intersection;
}
}
}
}
}
}
// 求一条线段与y轴的坐标
//返回值:
//-1: 没有交点
// 0: 线段与Y轴重合
// 1: 有一个交点(x)
bool lineIntersection(QPointF p1, QPointF p2, double y, QPointF* intersection)
{
//-1是为了避免double乘除时产生的误差
if (((p1.y() < (y - 1)) && (p2.y() < (y - 1))) ||
((p1.y() > y) && (p2.y() > y)) ||
0)
{// 没有交点
return false;
}
else if ((p1.y() == y) && (p2.y() == y))
{// 线段与Y重合返回false因为这种情况已经被添加到块中
return false;
}
// else if (p1.y() == y)
// {// p1与Y重合
// intersection->setX(p1.x());
// intersection->setY(y);
// return true;
// }
// else if (p2.y() == y)
// {// p2与Y重合
// intersection->setX(p2.x());
// intersection->setY(y);
// return true;
// }
else
{// 有一个交点
double dx1 = p2.x() - p1.x();
double dy1 = p2.y() - p1.y();
double dy = y - p1.y();
double x = (dx1/dy1) * dy + p1.x();
intersection->setX(x);
intersection->setY(y);
return true;
}
return true;
}

View File

@ -2,6 +2,7 @@
#define DRAWDATA_H
#include <QPicture>
#include <QBitmap>
#include "datafile/dxf/dxfhelper.h"
#include "datafile/hpgl/importhpgl.h"
#include "machine/printinfo/mcfiles.h"
@ -9,8 +10,18 @@
#define TYPE_FILE 0
#define TYPE_IMAGE 1
QPicture creatPictureByData(Marker marker, QPainterPath &painterPath,int penWidth = 1);
QPicture creatPictureByBmp(QPixmap pixmap,int penWidth = 1);
typedef struct
{
QPicture showPic;//用于显示的picture画笔为1像素不为1像素时MyGraphicsItem中绘制的线条会很淡
QPicture sendPic;//用于发送的picture画笔为所设置像素
} CreatPictureStr;
//marker数据绘制路径纸宽对接符间距是否对接标志右边距笔宽
CreatPictureStr creatPictureByData(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
CreatPictureStr creatPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
void creatMarkerDat(McFilesInfo &curFilesInfo, QString printDir, QString filePath, int fileIdx = -1, double angle = 0);//创建Marker数据
void splitPaintPath(QPainterPath originalPath,double segmentHeight,int segmenNum,QPainterPath *pathSegments);//纸张宽度不够时分割图形
//计算两线段的交点
bool lineIntersection(QPointF p1, QPointF p2, double y, QPointF* intersection);
#endif // DRAWDATA_H

View File

@ -4,7 +4,6 @@ MyGraphicsItem::MyGraphicsItem()
{
m_point.setX(0);
m_point.setY(0);
m_fileType = TYPE_FILE;
//使item可以被选择
//this->setFlag(QGraphicsItem::ItemIsSelectable);
@ -33,55 +32,25 @@ void MyGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
return QGraphicsItem::mouseReleaseEvent(event);
}
QPicture MyGraphicsItem::getPictureByDat(Marker marker,int penWidth)
CreatPictureStr MyGraphicsItem::getPictureByDat(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
m_fileType = TYPE_FILE;
if(penWidth != 1)
{
QPicture pic;
pic = creatPictureByData(marker,m_drawPath,penWidth);
m_boundingRect = pic.boundingRect();
return pic;
}
return m_picture;
m_pictureStr = creatPictureByData(marker,paperWidth,butSpace,rightSpace,penWidth);
m_boundingRect = m_pictureStr.showPic.boundingRect();
return m_pictureStr;
}
QPicture MyGraphicsItem::getPictureByBmp(QPixmap pixmap,int penWidth)
CreatPictureStr MyGraphicsItem::getPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
m_fileType = TYPE_IMAGE;
m_picture = creatPictureByBmp(pixmap,penWidth);
m_boundingRect = m_picture.boundingRect();
return m_picture;
}
QPainterPath MyGraphicsItem::getDrawPath()
{
return m_drawPath;
m_pictureStr = creatPictureByBmp(pixmap,paperWidth,butSpace,rightSpace,penWidth);
m_boundingRect = m_pictureStr.showPic.boundingRect();
return m_pictureStr;
}
void MyGraphicsItem::setPicture(QPicture pic)
{
m_fileType = TYPE_IMAGE;
m_picture = pic;
m_pictureStr.showPic = pic;
// 外矩形
m_boundingRect = m_picture.boundingRect();
update();
}
void MyGraphicsItem::setPaintPath(QPainterPath path)
{
m_fileType = TYPE_FILE;
m_drawPath = path;
m_boundingRect = m_drawPath.boundingRect();
update();
}
void MyGraphicsItem::setPaintPathAndPic(QPainterPath path, QPicture pic)
{
m_fileType = TYPE_FILE;
m_drawPath = path;
m_picture = pic;
m_boundingRect = m_drawPath.boundingRect();
m_boundingRect = m_pictureStr.showPic.boundingRect();
update();
}
@ -89,7 +58,7 @@ void MyGraphicsItem::reflushBlockPos(QPoint p)
{
m_point = p;
m_blockPixmap = QPixmap(PIXMAPWIDTH,m_picture.height());
m_blockPixmap = QPixmap(PIXMAPWIDTH,m_pictureStr.showPic.height());
m_blockPixmap.fill(Qt::transparent);//透明色
if(m_point.x() >= 0 && m_point.y() >= 0)
{
@ -133,15 +102,7 @@ void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
// painter->setRenderHint(QPainter::Antialiasing, true);
// painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
//用MyGraphicsItem画图缩放时如果笔宽不为1直接画QPicture时线条会很轻所以用m_drawPath绘制pic就为原笔宽pic
//文件类型用m_drawPath图片类型为m_picture
if(m_fileType == TYPE_FILE)
{
painter->drawPath(m_drawPath);
}
else if(m_fileType == TYPE_IMAGE)
{
painter->drawPicture(0,0,m_picture);
}
painter->drawPicture(0,0,m_pictureStr.showPic);
painter->drawPixmap(m_point.x(),m_point.y(),m_blockPixmap);
//painter->end();
}

View File

@ -35,20 +35,15 @@ protected: //事件
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
private:
QPicture m_picture;
QPainterPath m_drawPath;
CreatPictureStr m_pictureStr;
QPixmap m_blockPixmap;
QPoint m_point;
QRectF m_boundingRect;//返回形状
int m_fileType;
public:
QPicture getPictureByDat(Marker marker,int penWidth = 1);
QPicture getPictureByBmp(QPixmap pixmap,int penWidth = 1);
QPainterPath getDrawPath();
CreatPictureStr getPictureByDat(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
CreatPictureStr getPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
void setPicture(QPicture pic);
void setPaintPath(QPainterPath path);
void setPaintPathAndPic(QPainterPath path,QPicture pic);
void reflushBlockPos(QPoint p);//更显打印块位置
public slots:

View File

@ -29,16 +29,6 @@ void MyGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
return QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
void MyGraphicsScene::createScenePathAndPic(QPainterPath path, QPicture pic)
{
if(m_myGraphicsItem != NULL)
{
this->clear();
m_myGraphicsItem->setPaintPathAndPic(path,pic);
this->addItem(m_myGraphicsItem);
}
}
void MyGraphicsScene::addItemToScene()
{
//绘制留边
@ -56,34 +46,24 @@ void MyGraphicsScene::cleanScene()
}
}
QPicture MyGraphicsScene::getPictureByDat(Marker marker,int penWidth)
CreatPictureStr MyGraphicsScene::getPictureByDat(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
QPicture pic;
CreatPictureStr picStr;
if(m_myGraphicsItem != NULL)
{
pic = m_myGraphicsItem->getPictureByDat(marker,penWidth);
picStr = m_myGraphicsItem->getPictureByDat(marker,paperWidth,butSpace,rightSpace,penWidth);
}
return pic;
return picStr;
}
QPicture MyGraphicsScene::getPictureByBmp(QPixmap pixmap,int penWidth)
CreatPictureStr MyGraphicsScene::getPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
QPicture pic;
CreatPictureStr picStr;
if(m_myGraphicsItem != NULL)
{
pic = m_myGraphicsItem->getPictureByBmp(pixmap,penWidth);
picStr = m_myGraphicsItem->getPictureByBmp(pixmap,paperWidth,butSpace,rightSpace,penWidth);
}
return pic;
}
QPainterPath MyGraphicsScene::getDrawPath()
{
QPainterPath path;
if(m_myGraphicsItem != NULL)
{
path = m_myGraphicsItem->getDrawPath();
}
return path;
return picStr;
}
void MyGraphicsScene::swithSceneByPic(QPicture pic)
@ -96,17 +76,7 @@ void MyGraphicsScene::swithSceneByPic(QPicture pic)
}
}
void MyGraphicsScene::swithSceneByPath(QPainterPath path)
{
if(m_myGraphicsItem != NULL)
{
this->clear();
m_myGraphicsItem->setPaintPath(path);
this->addItem(m_myGraphicsItem);
}
}
void MyGraphicsScene::ReflushBlockScene(QPoint p)
void MyGraphicsScene::reflushBlockScene(QPoint p)
{
if(m_myGraphicsItem != NULL)
{

View File

@ -23,15 +23,12 @@ private:
MyGraphicsItem *m_myGraphicsItem;
public:
void createScenePathAndPic(QPainterPath path,QPicture pic);
void addItemToScene();
void cleanScene();
QPicture getPictureByDat(Marker marker,int penWidth = 1);
QPicture getPictureByBmp(QPixmap pixmap,int penWidth = 1);
QPainterPath getDrawPath();
CreatPictureStr getPictureByDat(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
CreatPictureStr getPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
void swithSceneByPic(QPicture pic);
void swithSceneByPath(QPainterPath path);
void ReflushBlockScene(QPoint p);
void reflushBlockScene(QPoint p);
signals:

View File

@ -183,50 +183,30 @@ void MyGraphicsView::wheelEvent(QWheelEvent *event)
verticalScrollBar()->setValue(int(viewPoint.y() - viewHeight * vScale));
}
QPicture MyGraphicsView::getPictureByDat(Marker marker,int penWidth)
CreatPictureStr MyGraphicsView::getPictureByDat(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
QPicture pic;
CreatPictureStr picStr;
if(m_scene != NULL)
{
pic = m_scene->getPictureByDat(marker,penWidth);
picStr = m_scene->getPictureByDat(marker,paperWidth,butSpace,rightSpace,penWidth);
m_scene->addItemToScene();
QRectF rectItem = m_scene->itemsBoundingRect();
this->fitInView(rectItem, Qt::KeepAspectRatio);
}
return pic;
return picStr;
}
QPicture MyGraphicsView::getPictureByBmp(QPixmap pixmap,int penWidth)
CreatPictureStr MyGraphicsView::getPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth)
{
QPicture pic;
CreatPictureStr picStr;
if(m_scene != NULL)
{
pic = m_scene->getPictureByBmp(pixmap,penWidth);
picStr = m_scene->getPictureByBmp(pixmap,paperWidth,butSpace,rightSpace,penWidth);
m_scene->addItemToScene();
QRectF rectItem = m_scene->itemsBoundingRect();
this->fitInView(rectItem, Qt::KeepAspectRatio);
}
return pic;
}
QPainterPath MyGraphicsView::getDrawPath()
{
QPainterPath path;
if(m_scene != NULL)
{
path = m_scene->getDrawPath();
}
return path;
}
void MyGraphicsView::creatViewPathAndPic(QPainterPath path,QPicture pic)
{
if(m_scene != NULL)
{
m_scene->createScenePathAndPic(path,pic);
QRectF rectItem = m_scene->itemsBoundingRect();
this->fitInView(rectItem, Qt::KeepAspectRatio);
}
return picStr;
}
void MyGraphicsView::cleanView()
@ -251,20 +231,10 @@ void MyGraphicsView::swithViewByPic(QPicture pic)
}
}
void MyGraphicsView::swithViewByPath(QPainterPath path)
{
if(m_scene != NULL)
{
m_scene->swithSceneByPath(path);
QRectF rectItem = m_scene->itemsBoundingRect();
this->fitInView(rectItem, Qt::KeepAspectRatio);
}
}
void MyGraphicsView::reflushBlockView(QPoint p)
{
if(m_scene != NULL)
{
m_scene->ReflushBlockScene(p);
m_scene->reflushBlockScene(p);
}
}

View File

@ -34,13 +34,10 @@ protected:
void wheelEvent(QWheelEvent *event);
public:
QPicture getPictureByDat(Marker marker,int penWidth = 1);
QPicture getPictureByBmp(QPixmap pixmap,int penWidth = 1);
QPainterPath getDrawPath();
void creatViewPathAndPic(QPainterPath path,QPicture pic);
CreatPictureStr getPictureByDat(Marker marker,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
CreatPictureStr getPictureByBmp(QPixmap pixmap,int paperWidth,int butSpace,int rightSpace,int penWidth = 1);
void cleanView();
void swithViewByPic(QPicture pic);
void swithViewByPath(QPainterPath path);
void reflushBlockView(QPoint p);
signals:

View File

@ -154,6 +154,7 @@ int BWBmp::Compress(int idx, int dir, int segWidth, int segHeight)
//---------------------------------------------------------
// 读取位图信息,对数组赋值
unsigned char sta,tmpdat,mod;
sta = tmpdat = mod = 0;
const unsigned char * pBitDat;
int i, j, k, l, m, n;
int addr;
@ -163,7 +164,7 @@ int BWBmp::Compress(int idx, int dir, int segWidth, int segHeight)
int * segdat = new int [msegnum];
//------------------------------------
unsigned char tgtdat;
unsigned char tgtdat = 0;
QVector<unsigned char> compType(wsegnum); // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩(分段压缩);
QVector<unsigned int> compSegOffset(wsegnum); // 分段数据起始位置

View File

@ -58,7 +58,7 @@ int CreatPrintBmp::creatFileListMarker(int idx)
{
McFilesInfo curFilesInfo;//当前文件信息
creatMarkerDat(curFilesInfo,m_printFileDir,filePath,m_listFileIdx,m_rotateAngle);
long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM;
long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/MMPIXELY;
m_mcPrintInfo->m_fileNums += 1;
m_mcPrintInfo->m_fileTotalLength += fileTotalLength;
m_mcPrintInfo->m_filesList.append(curFilesInfo);
@ -107,43 +107,20 @@ int CreatPrintBmp::creatFileListDatAndSend(int idx)
}
QPicture pic;
QPen pen;
pen.setWidth(1);
pen.setColor(QColor(Qt::black));
int oft = 0;//起始打印位置的偏移
if(curFilesInfo.m_fileType == TYPE_FILE)
pic = m_mcPrintInfo->m_filesList[idx].m_sendPic;
oft = (int)(m_mcPrintInfo->m_filesList[idx].m_startPoint*MMPIXELY);
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
m_mcPrintInfo->m_totalNums = (pic.width() - oft) / PIXMAPWIDTH;
int lwidth = (pic.width() - oft) % (PIXMAPWIDTH);
if(lwidth != 0)
{
pic = m_mcPrintInfo->m_filesList[idx].m_pic;
oft = (int)(m_mcPrintInfo->m_filesList[idx].m_startPoint*MMPIXELY);
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
m_mcPrintInfo->m_totalNums = (pic.width() - oft) / PIXMAPWIDTH;
int lwidth = (pic.width() - oft) % (PIXMAPWIDTH);
if(lwidth != 0)
{
m_mcPrintInfo->m_totalNums += 1;
}
m_mcPrintInfo->m_totalNums += 1;
}
else if(curFilesInfo.m_fileType == TYPE_IMAGE)
{
//将图片画在picture上
QPainter painter;
painter.begin(&pic);
painter.setPen(pen);
painter.drawPixmap(0,0,m_mcPrintInfo->m_filesList[idx].m_pixmap);
painter.end();
//将pixmap保存为多个宽度为PIXMAPWIDTH像素的bmp
m_mcPrintInfo->m_totalNums = curFilesInfo.m_pixmap.width() / PIXMAPWIDTH;
int lwidth = curFilesInfo.m_pixmap.width() % PIXMAPWIDTH;
if(lwidth != 0)
{
m_mcPrintInfo->m_totalNums += 1;
}
}
m_mcPrintInfo->m_filesList[idx].m_totalBlocks = (pic.width() - oft)/ PIXMAPWIDTH;
int lwidth = (pic.width() - oft) % PIXMAPWIDTH;
lwidth = (pic.width() - oft) % PIXMAPWIDTH;
if(lwidth != 0)
{
m_mcPrintInfo->m_filesList[idx].m_totalBlocks += 1;
@ -178,7 +155,7 @@ int CreatPrintBmp::creatBmpBlockDatAndSend(int fileidx, int idx)
int nextNum = idx / oneNumCount;
idx = idx - nextNum * oneNumCount;
QPicture pic = m_mcPrintInfo->m_filesList[fileidx].m_pic;
QPicture pic = m_mcPrintInfo->m_filesList[fileidx].m_sendPic;
int oft = (int)(m_mcPrintInfo->m_filesList[fileidx].m_startPoint*MMPIXELY);
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
@ -568,7 +545,7 @@ void CreatPrintBmp::setDeleteFile(McPrintInfo *printInfo, int fileIdx)
if(m_deleteFileIdx != m_fileBegIdx && m_deleteFileIdx != -1)
{
int length = (m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.right() - m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.left())/M_IDPMM;
int length = (m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.right() - m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.left())/MMPIXELY;
m_mcPrintInfo->m_fileTotalLength -= length;
QString mcFile = m_printFileDir + QString::number(m_deleteFileIdx+1);

View File

@ -17,7 +17,6 @@
#include "datafile/view/drawdata.h"
#define PIXMAPWIDTH 1200
#define PENWIDTH 5
#define PRINTDIR "print"
#define PRINTMCDIR "mc"

View File

@ -138,7 +138,7 @@ Machine::~Machine()
void Machine::startFileTrans(FileTransCtrl &transCtrl)
{
int rslt;
int rslt = 0;
OperPacket sendPacket;
memset(&sendPacket, 0, sizeof(OperPacket));
sendPacket.startTrans.cmdCode = UCMD_START_TRANS;
@ -969,7 +969,7 @@ void Machine::onSendTimer()
void Machine::slotSendDatToMc(QByteArray dat)
{
if(m_connected == Connected)
//if(m_connected == Connected)
{
if (dat.size() <= 0 || m_pCompBmpHead == NULL)
{
@ -1039,8 +1039,8 @@ void Machine::slotSendPlotFileListToMc(int idx)
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
u32 id =qrand() % (UINT16_MAX);//产生0到UINT16_MAX的随机数
m_pPlotFileList->fileId = id;
m_pPlotFileList->totalWidth = (m_mcPrintInfo.m_filesList[idx].m_pic.width() - oft) * m_mcPrintInfo.m_filesList[idx].m_printNum;
m_pPlotFileList->totalHeight = m_mcPrintInfo.m_filesList[idx].m_pic.height();
m_pPlotFileList->totalWidth = (m_mcPrintInfo.m_filesList[idx].m_sendPic.width() - oft) * m_mcPrintInfo.m_filesList[idx].m_printNum;
m_pPlotFileList->totalHeight = m_mcPrintInfo.m_filesList[idx].m_sendPic.height();
m_pPlotFileList->blkNums = m_mcPrintInfo.m_filesList[idx].m_totalBlocks;
m_pPlotFileList->blkWidth = PIXMAPWIDTH;

View File

@ -45,8 +45,8 @@ public:
s16 m_printNum;//打印份数
s16 m_startPoint;//打印起始点
s16 m_printState;//打印状态
QPicture m_pic;//文件-发送的图片-实际笔宽绘制的pic
QPainterPath m_drawPath;//文件-数据绘图路径-用MyGraphicsItem画图时如果笔宽不为1直接画QPicture时线条会很轻所以用m_drawPath绘制
QPicture m_showPic;//文件-显示的图片-1像素绘制的pic
QPicture m_sendPic;//文件-发送的图片-实际笔宽绘制的pic
QBitmap m_pixmap;//图片-图片
s16 m_totalBlocks;//总块数
s16 m_curPrintBlock;//当前打印块数
@ -58,7 +58,6 @@ public:
void clear()
{
QPicture pic;
QPainterPath path;
m_creatDataFlag = -1;
m_creatBmpFlag = -1;//是否已经生成bmp的标志
@ -68,8 +67,8 @@ public:
m_printNum = 0;//打印份数
m_startPoint = 0;//打印起始点
m_printState = Waitting;//打印状态
m_pic = pic;
m_drawPath = path;
m_showPic = pic;
m_sendPic = pic;
m_pixmap.clear();
m_totalBlocks = 0;//总块数
m_curPrintBlock = 0;//当前打印块数
@ -107,8 +106,8 @@ public:
m_printNum = item.m_printNum;//打印份数
m_startPoint = item.m_startPoint;//打印起始点
m_printState = item.m_printState;//打印状态
m_pic = item.m_pic;
m_drawPath = item.m_drawPath;
m_showPic = item.m_showPic;
m_sendPic = item.m_sendPic;
m_pixmap = item.m_pixmap;
m_totalBlocks = item.m_totalBlocks;//总块数
m_curPrintBlock = item.m_curPrintBlock;//当前打印块数
@ -129,8 +128,8 @@ public:
m_printNum = item.m_printNum;//打印份数
m_startPoint = item.m_startPoint;//打印起始点
m_printState = item.m_printState;//打印状态
m_pic = item.m_pic;
m_drawPath = item.m_drawPath;
m_showPic = item.m_showPic;
m_sendPic = item.m_sendPic;
m_pixmap = item.m_pixmap;
m_totalBlocks = item.m_totalBlocks;//总块数
m_curPrintBlock = item.m_curPrintBlock;//当前打印块数

View File

@ -109,13 +109,19 @@ void MainWindow::reflushPreview(int row)
ui->tableView_Connection->setEnabled(false);
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();
int paperWidth = m_pSettings->value("DrawSet/paperwidth").toInt();
int butSpace = m_pSettings->value("DrawSet/buttmargin").toInt();
int rightSpace = m_pSettings->value("DrawSet/rightmargin").toInt();
//生成绘制图
g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic = creatFilePicture(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row],penWidth);
CreatPictureStr picStr;
picStr = creatFilePicture(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row],paperWidth,butSpace,rightSpace,penWidth);
g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_showPic = picStr.showPic;
g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_sendPic = picStr.sendPic;
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
int num = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic.width() / PIXMAPWIDTH;
int lwidth = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic.width() % PIXMAPWIDTH;
int num = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_sendPic.width() / PIXMAPWIDTH;
int lwidth = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_sendPic.width() % PIXMAPWIDTH;
if(lwidth != 0)
{
num +=1;
@ -130,16 +136,8 @@ void MainWindow::reflushPreview(int row)
//刷新图形
m_preView->cleanView();
if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_fileType == TYPE_FILE)
{
QPainterPath path = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_drawPath;
m_preView->swithViewByPath(path);
}
else if(g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_fileType == TYPE_IMAGE)
{
QPicture pic = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_pic;
m_preView->swithViewByPic(pic);
}
QPicture pic = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row].m_showPic;
m_preView->swithViewByPic(pic);
m_curFilesInfo = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[row];
}
@ -325,24 +323,20 @@ void MainWindow::stopPrint(int mcIdx)
}
}
QPicture MainWindow::creatFilePicture(McFilesInfo & mcFileInfo, s16 penWidth)
CreatPictureStr MainWindow::creatFilePicture(McFilesInfo & mcFileInfo,int paperWidth,int butSpace,int rightSpace,s16 penWidth)
{
//将图片画在picture上
QPicture pic;
CreatPictureStr picStr;
if(mcFileInfo.m_fileType == TYPE_IMAGE)
{
pic = creatPictureByBmp(mcFileInfo.m_pixmap,penWidth);
picStr = creatPictureByBmp(mcFileInfo.m_pixmap,paperWidth,butSpace,rightSpace,penWidth);
}
else
{
pic = creatPictureByData(mcFileInfo.m_marker,mcFileInfo.m_drawPath,penWidth);
if(mcFileInfo.m_drawPath.isEmpty())
{
qDebug()<<"painterPath.isEmpty";
}
picStr = creatPictureByData(mcFileInfo.m_marker,paperWidth,butSpace,rightSpace,penWidth);
}
return pic;
return picStr;
}
void MainWindow::refConnectUi()
@ -490,10 +484,10 @@ int MainWindow::refreshMcFileListShow(int idx)
QRect rect = filesList[i].m_fileRect;
QString length = QString::number((rect.right() - rect.left())/(int)M_IDPMM)+"mm";
QString length = QString::number((int)((rect.right() - rect.left())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_LENGTH),length);
QString width = QString::number((rect.bottom() - rect.top())/(int)M_IDPMM)+"mm";
QString width = QString::number((int)((rect.bottom() - rect.top())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(i,COLUMN_WIDTH),width);
QString start = QString::number(filesList[i].m_startPoint)+"mm";
@ -676,10 +670,10 @@ void MainWindow::slotAddNewFileToList(int newFlag)
QRect rect = m_curFilesInfo.m_fileRect;
QString length = QString::number((rect.right() - rect.left())/(int)M_IDPMM)+"mm";
QString length = QString::number((int)((rect.right() - rect.left())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_LENGTH),length);
QString width = QString::number((rect.bottom() - rect.top())/(int)M_IDPMM)+"mm";
QString width = QString::number((int)((rect.bottom() - rect.top())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_WIDTH),width);
QString start = QString::number(m_printViewWi->getStartPoint())+"mm";
@ -712,23 +706,10 @@ void MainWindow::slotAddNewFileToList(int newFlag)
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row,COLUMN_FILEPATH),m_curFilesInfo.m_filePath);
//m_preView->cleanView();
// int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽
// if(m_curFilesInfo.m_fileType == TYPE_FILE)
// {
// //刷新显示
// m_curFilesInfo.m_pic = m_preView->getPictureByDat(m_curFilesInfo.m_marker,penWidth);
// m_curFilesInfo.m_drawPath = m_preView->getDrawPath();
// }
// else if(m_curFilesInfo.m_fileType == TYPE_IMAGE)
// {
// m_curFilesInfo.m_pic = m_preView->getPictureByBmp(m_curFilesInfo.m_pixmap);
// }
m_curFilesInfo.m_creatBmpFlag = 1;
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
int num = m_curFilesInfo.m_pic.width() / PIXMAPWIDTH;
int lwidth = m_curFilesInfo.m_pic.width() % PIXMAPWIDTH;
int num = m_curFilesInfo.m_sendPic.width() / PIXMAPWIDTH;
int lwidth = m_curFilesInfo.m_sendPic.width() % PIXMAPWIDTH;
if(lwidth != 0)
{
num +=1;
@ -745,7 +726,7 @@ void MainWindow::slotAddNewFileToList(int newFlag)
McPrintInfo McF;
McF.m_fileNums = row+1;
McF.m_fileTotalLength = (m_curFilesInfo.m_fileRect.right() - m_curFilesInfo.m_fileRect.left())/M_IDPMM;
McF.m_fileTotalLength = (m_curFilesInfo.m_fileRect.right() - m_curFilesInfo.m_fileRect.left())/MMPIXELY;
McF.m_filesList.append(m_curFilesInfo);
m_curFileRow = row;
@ -826,9 +807,13 @@ void MainWindow::slotMcListMenu(QPoint pos)
void MainWindow::slotPrintPreview()
{
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();
int paperWidth = m_pSettings->value("DrawSet/paperwidth").toInt();
int butSpace = m_pSettings->value("DrawSet/buttmargin").toInt();
int rightSpace = m_pSettings->value("DrawSet/rightmargin").toInt();
m_curFilesInfo = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[m_curFileRow];
m_printViewWi->refreshShow(m_curFilesInfo,penWidth,0);
m_printViewWi->refreshShow(m_curFilesInfo,paperWidth,butSpace,rightSpace,penWidth,0);
}
void MainWindow::slotPrintNumberSetDlgShow()
@ -849,7 +834,7 @@ void MainWindow::slotStartSetDlgShow()
{
QString fileName = m_curFilesInfo.m_fileName;
QString startPoint= QString::number(m_curFilesInfo.m_startPoint);
QString length= QString::number(m_curFilesInfo.m_fileRect.right()-m_curFilesInfo.m_fileRect.left());
QString length= QString::number((int)((m_curFilesInfo.m_fileRect.right()-m_curFilesInfo.m_fileRect.left())/MMPIXELY));
StartSetDialog startSetDlg;
if(startSetDlg.exec(fileName,startPoint,length) == 1)
{
@ -1005,9 +990,9 @@ void MainWindow::slotLoadAutoPrintFiles()
{
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_FILENAME),g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[i].m_fileName);
QRect rect = g_machineList[m_curMcIdx]->m_mcPrintInfo.m_filesList[i].m_fileRect;
QString length = QString::number((rect.right() - rect.left())/(int)M_IDPMM)+"mm";
QString length = QString::number((int)((rect.right() - rect.left())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_LENGTH),length);
QString width = QString::number((rect.bottom() - rect.top())/(int)M_IDPMM)+"mm";
QString width = QString::number((int)((rect.bottom() - rect.top())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_WIDTH),width);
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_START),start);
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_PRINTEDLENGTH),"0mm");
@ -1025,9 +1010,9 @@ void MainWindow::slotLoadAutoPrintFiles()
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_FILENAME),curFilesInfo.m_fileName);
QRect rect = curFilesInfo.m_fileRect;
QString length = QString::number((rect.right() - rect.left())/(int)M_IDPMM)+"mm";
QString length = QString::number((int)((rect.right() - rect.left())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_LENGTH),length);
QString width = QString::number((rect.bottom() - rect.top())/(int)M_IDPMM)+"mm";
QString width = QString::number((int)((rect.bottom() - rect.top())/MMPIXELY))+"mm";
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_WIDTH),width);
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_START),start);
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_PRINTEDLENGTH),"0mm");
@ -1036,7 +1021,7 @@ void MainWindow::slotLoadAutoPrintFiles()
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_STATE),state);
m_tabelViewModelFile->setData(m_tabelViewModelFile->index(row, COLUMN_FILEPATH),curFilesInfo.m_filePath);
long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM;
long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/MMPIXELY;
g_machineList[m_curMcIdx]->m_mcPrintInfo.m_fileNums = i+1;
g_machineList[m_curMcIdx]->m_mcPrintInfo.m_fileTotalLength += fileTotalLength;
@ -1324,7 +1309,20 @@ void MainWindow::on_actionOpen_File_triggered()
m_pSettings->setValue("LastFilePath/filePath",path.remove(fileName)); //记录路径到QSetting中保存
#if(1)
creatMarkerDat(m_curFilesInfo,m_printPath,filePath,-1,m_rotateAngle);
if(fileInfo.suffix().toUpper() == "DXF")
{
DxfHelper dxfHelper;
if(dxfHelper.generateDxf(filePath))
{
dxfHelper.getDxfPaths(); // 获取转换出来的dxf所有类型图形的点集
QImage img = dxfHelper.generateDXFImage(); // 获取预览图像
img.save("D:\\1.png");
}
}
else
{
creatMarkerDat(m_curFilesInfo,m_printPath,filePath,-1,m_rotateAngle);
}
#else
m_curFilesInfo.m_marker.Initialize();
if(fileInfo.suffix().toUpper() == "DXF")
@ -1366,8 +1364,11 @@ void MainWindow::on_actionOpen_File_triggered()
//m_curFilesInfo.m_painterPath = importHPGL.GetPolylinePainterPath();
}
#endif
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽
m_printViewWi->refreshShow(m_curFilesInfo,penWidth,1);
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();
int paperWidth = m_pSettings->value("DrawSet/paperwidth").toInt();
int butSpace = m_pSettings->value("DrawSet/buttmargin").toInt();
int rightSpace = m_pSettings->value("DrawSet/rightmargin").toInt();
m_printViewWi->refreshShow(m_curFilesInfo,paperWidth,butSpace,rightSpace,penWidth,1);
}
return;
}
@ -1468,12 +1469,15 @@ void MainWindow::on_actionOpen_Image_triggered()
QBitmap pixmap;
pixmap.load(filePath);
QRect rect;
rect.setRect(0,0,pixmap.width()/MMPIXELY*M_IDPMM,pixmap.height()/MMPIXELY*M_IDPMM);
rect.setRect(0,0,pixmap.width()/MMPIXELY*MMPIXELY,pixmap.height()/MMPIXELY*MMPIXELY);
m_curFilesInfo.m_pixmap = pixmap;
m_curFilesInfo.m_fileRect = rect;
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();//线宽
m_printViewWi->refreshShow(m_curFilesInfo,penWidth,1);
int penWidth = m_pSettings->value("DrawSet/linewidth").toInt();
int paperWidth = m_pSettings->value("DrawSet/paperwidth").toInt();
int butSpace = m_pSettings->value("DrawSet/buttmargin").toInt();
int rightSpace = m_pSettings->value("DrawSet/rightmargin").toInt();
m_printViewWi->refreshShow(m_curFilesInfo,paperWidth,butSpace,rightSpace,penWidth,1);
}
}

View File

@ -102,7 +102,7 @@ private:
bool deleteDir(QString path);
void startCreatBmpAndSend(int mcIdx = -1);//开始创建位图并发送
void stopPrint(int mcIdx = -1);//停止打印
QPicture creatFilePicture(McFilesInfo & mcFileInfo, s16 penWidth = 1);
CreatPictureStr creatFilePicture(McFilesInfo & mcFileInfo,int paperWidth,int butSpace,int rightSpace,s16 penWidth = 1);
//刷新连接状态
void refConnectUi();//刷新连接状态(1秒)
void refConnectUi(Machine * pMachine,int & linkSta, int idx);

View File

@ -48,7 +48,7 @@ void PrintInfoDialog::on_listView_blockList_clicked(const QModelIndex &index)
str = QString::number((m_curFilesInfo.m_selectBlockNum-1)*BLOCK_MM)+" - ";
if(row == m_listViewModel->rowCount() - 1)
{
str1 = QString::number((m_curFilesInfo.m_fileRect.right() - m_curFilesInfo.m_fileRect.left())/(int)M_IDPMM);
str1 = QString::number((int)((m_curFilesInfo.m_fileRect.right() - m_curFilesInfo.m_fileRect.left())/MMPIXELY));
}
else
{
@ -84,8 +84,8 @@ void PrintInfoDialog::reflushFileInfo()
ui->label_fileNameVal->setText(m_curFilesInfo.m_fileName);
int length = (m_curFilesInfo.m_fileRect.right() - m_curFilesInfo.m_fileRect.left())/M_IDPMM;
int height = (m_curFilesInfo.m_fileRect.bottom() - m_curFilesInfo.m_fileRect.top())/M_IDPMM;
int length = (m_curFilesInfo.m_fileRect.right() - m_curFilesInfo.m_fileRect.left())/MMPIXELY;
int height = (m_curFilesInfo.m_fileRect.bottom() - m_curFilesInfo.m_fileRect.top())/MMPIXELY;
QString WH = QString::number(length) + "x" + QString::number(height)+ "mm";
ui->label_drawWHVal->setText(WH);
@ -106,14 +106,7 @@ void PrintInfoDialog::setFilesInfo(McFilesInfo info)
m_curFilesInfo = info;
m_preView->cleanView();
if(m_curFilesInfo.m_fileType == TYPE_FILE)
{
m_preView->creatViewPathAndPic(m_curFilesInfo.m_drawPath,m_curFilesInfo.m_pic);//刷新显示
}
else if(m_curFilesInfo.m_fileType == TYPE_IMAGE)
{
m_preView->swithViewByPic(m_curFilesInfo.m_pic);//刷新显示
}
m_preView->swithViewByPic(m_curFilesInfo.m_showPic);//刷新显示
reflushFileInfo();

View File

@ -37,7 +37,7 @@ void PrintViewWindow::refreshLanguage()
ui->retranslateUi(this);
}
void PrintViewWindow::refreshShow(McFilesInfo &mcFilesInfo,int penWidth,int flag)
void PrintViewWindow::refreshShow(McFilesInfo &mcFilesInfo,int paperWidth,int butSpace,int rightSpace,int penWidth,int flag)
{
m_startPoint = 0;
m_printNumber = 1;
@ -54,20 +54,24 @@ void PrintViewWindow::refreshShow(McFilesInfo &mcFilesInfo,int penWidth,int flag
}
m_filePath = mcFilesInfo.m_filePath;
m_length = (mcFilesInfo.m_fileRect.right() - mcFilesInfo.m_fileRect.left())/M_IDPMM;
int width = (mcFilesInfo.m_fileRect.bottom() - mcFilesInfo.m_fileRect.top())/M_IDPMM;
this->setWindowTitle(m_filePath+"("+QString::number(m_length)+"mm"+" * " + QString::number(width) + "mm)");
m_view->cleanView();
CreatPictureStr picStr;
if(mcFilesInfo.m_fileType == TYPE_FILE)
{
mcFilesInfo.m_pic = m_view->getPictureByDat(mcFilesInfo.m_marker,penWidth);
mcFilesInfo.m_drawPath = m_view->getDrawPath();
picStr = m_view->getPictureByDat(mcFilesInfo.m_marker,paperWidth,butSpace,rightSpace,penWidth);
}
else if(mcFilesInfo.m_fileType == TYPE_IMAGE)
{
mcFilesInfo.m_pic = m_view->getPictureByBmp(mcFilesInfo.m_pixmap);
picStr = m_view->getPictureByBmp(mcFilesInfo.m_pixmap,paperWidth,butSpace,rightSpace,penWidth);
}
mcFilesInfo.m_showPic = picStr.showPic;
mcFilesInfo.m_sendPic = picStr.sendPic;
mcFilesInfo.m_fileRect = picStr.sendPic.boundingRect();
m_length = (mcFilesInfo.m_fileRect.right() - mcFilesInfo.m_fileRect.left())/MMPIXELY;
int width = (mcFilesInfo.m_fileRect.bottom() - mcFilesInfo.m_fileRect.top())/MMPIXELY;
this->setWindowTitle(m_filePath+"("+QString::number(m_length)+"mm"+" * " + QString::number(width) + "mm)");
//如果是最大化变为正常大小
if(this->windowState() == Qt::WindowMaximized)

View File

@ -33,7 +33,7 @@ private:
int m_length;
public:
void refreshShow(McFilesInfo &mcFilesInfo,int penWidth,int flag = 0);
void refreshShow(McFilesInfo &mcFilesInfo,int paperWidth,int butSpace,int rightSpace,int penWidth,int flag = 0);
void setStartLineText(QString str);
void setNumberLineText(QString str);
inline int getStartPoint(){return m_startPoint;}