From 9f74511e69bc847a1a226ae630185c956827429c Mon Sep 17 00:00:00 2001 From: huahaiyan <3686255842@qq.com> Date: Fri, 15 Mar 2024 16:49:50 +0800 Subject: [PATCH] =?UTF-8?q?20240315=201=E3=80=81=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E5=89=B2=E5=8A=9F=E8=83=BD=EF=BC=88?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=89=202=E3=80=81=E6=9B=B4=E6=8D=A2dxf?= =?UTF-8?q?=E5=BA=93=EF=BC=88=E8=BF=9B=E8=A1=8C=E4=B8=AD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NPlotter.pro | 80 +- datafile/dxf/dxflib/DxfMath.h | 215 ++ datafile/dxf/dxflib/GroupCode.h | 847 ++++++ datafile/dxf/dxflib/PDSMath.h | 2522 +++++++++++++++ datafile/dxf/dxflib/PDSMath/3BSpline.h | 439 +++ datafile/dxf/dxflib/PDSMath/PDSAlgorithm.h | 196 ++ datafile/dxf/dxflib/PDSMath/PDSBezier.h | 139 + datafile/dxf/dxflib/PDSMath/PDSFormula.h | 333 ++ datafile/dxf/dxflib/PDSMath/PDSLocate.h | 236 ++ datafile/dxf/dxflib/PDSMath/PDSMath.h | 2705 +++++++++++++++++ datafile/dxf/dxflib/PDSMath/PDSMathExtern.h | 8 + datafile/dxf/dxflib/PDSMath/PDSMathGlobal.h | 8 + datafile/dxf/dxflib/PDSMath/PDSNurbs.h | 503 +++ .../dxf/dxflib/PDSMath/PDSReadWriteFile.h | 87 + datafile/dxf/dxflib/PDSMath/PDSUID.h | 106 + datafile/dxf/dxflib/PDSMath/PDSUnit.h | 164 + datafile/dxf/dxflib/PDSMath/Point3D.h | 178 ++ datafile/dxf/dxflib/PDSMath/StdAfx.h | 44 + datafile/dxf/dxflib/PDSMath/UnzipFile.h | 215 ++ .../dxf/dxflib/PDSMath/UnzipFile_Memory.h | 217 ++ datafile/dxf/dxflib/PDSMath/ZUBaseFile.h | 39 + .../dxf/dxflib/PDSMath/ZUBaseFile_Memory.h | 62 + datafile/dxf/dxflib/PDSMath/ZipCompress.h | 42 + datafile/dxf/dxflib/PDSMath/ZipException.h | 55 + datafile/dxf/dxflib/PDSMath/ZipFile.h | 145 + datafile/dxf/dxflib/PDSMath/ZipFile_Memory.h | 146 + datafile/dxf/dxflib/PDSMath/ZipStruct.h | 199 ++ datafile/dxf/dxflib/PDSMath/zconf.h | 279 ++ datafile/dxf/dxflib/PDSMath/zlib.h | 893 ++++++ datafile/dxf/dxflib/ReadASTM.h | 448 +++ datafile/dxf/dxflib/ReadAutoCAD.h | 485 +++ datafile/dxf/dxflib/ReadDxfFile.h | 196 ++ datafile/dxf/dxflib/ReadTIIP.h | 309 ++ datafile/dxf/dxflib/WriteASTM.h | 219 ++ datafile/dxf/dxflib/WriteAutoCAD.h | 170 ++ datafile/dxf/dxflib/WriteDxfFile.h | 343 +++ .../dxf/{dxflib => dxflib1}/dl_attributes.h | 0 datafile/dxf/{dxflib => dxflib1}/dl_codes.h | 0 .../{dxflib => dxflib1}/dl_creationadapter.h | 0 .../dl_creationinterface.h | 0 datafile/dxf/{dxflib => dxflib1}/dl_dxf.cpp | 0 datafile/dxf/{dxflib => dxflib1}/dl_dxf.h | 0 .../dxf/{dxflib => dxflib1}/dl_entities.h | 0 .../dxf/{dxflib => dxflib1}/dl_exception.h | 0 .../dxf/{dxflib => dxflib1}/dl_extrusion.h | 0 datafile/dxf/{dxflib => dxflib1}/dl_global.h | 0 datafile/dxf/{dxflib => dxflib1}/dl_writer.h | 0 .../{dxflib => dxflib1}/dl_writer_ascii.cpp | 0 .../dxf/{dxflib => dxflib1}/dl_writer_ascii.h | 0 datafile/dxf/dxfreader.h | 3 +- datafile/hpgl/importhpgl.cpp | 1 + datafile/view/drawdata.cpp | 433 ++- datafile/view/drawdata.h | 15 +- datafile/view/mygraphicsitem.cpp | 65 +- datafile/view/mygraphicsitem.h | 11 +- datafile/view/mygraphicsscene.cpp | 48 +- datafile/view/mygraphicsscene.h | 9 +- datafile/view/mygraphicsview.cpp | 48 +- datafile/view/mygraphicsview.h | 7 +- machine/bmp/bwbmp.cpp | 3 +- machine/bmp/creatprintbmp.cpp | 45 +- machine/bmp/creatprintbmp.h | 1 - machine/machine.cpp | 8 +- machine/printinfo/mcfiles.h | 17 +- mainwindow.cpp | 116 +- mainwindow.h | 2 +- printinfodialog.cpp | 15 +- printviewwindow.cpp | 18 +- printviewwindow.h | 2 +- 69 files changed, 13825 insertions(+), 314 deletions(-) create mode 100644 datafile/dxf/dxflib/DxfMath.h create mode 100644 datafile/dxf/dxflib/GroupCode.h create mode 100644 datafile/dxf/dxflib/PDSMath.h create mode 100644 datafile/dxf/dxflib/PDSMath/3BSpline.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSAlgorithm.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSBezier.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSFormula.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSLocate.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSMath.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSMathExtern.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSMathGlobal.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSNurbs.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSReadWriteFile.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSUID.h create mode 100644 datafile/dxf/dxflib/PDSMath/PDSUnit.h create mode 100644 datafile/dxf/dxflib/PDSMath/Point3D.h create mode 100644 datafile/dxf/dxflib/PDSMath/StdAfx.h create mode 100644 datafile/dxf/dxflib/PDSMath/UnzipFile.h create mode 100644 datafile/dxf/dxflib/PDSMath/UnzipFile_Memory.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZUBaseFile.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZUBaseFile_Memory.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZipCompress.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZipException.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZipFile.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZipFile_Memory.h create mode 100644 datafile/dxf/dxflib/PDSMath/ZipStruct.h create mode 100644 datafile/dxf/dxflib/PDSMath/zconf.h create mode 100644 datafile/dxf/dxflib/PDSMath/zlib.h create mode 100644 datafile/dxf/dxflib/ReadASTM.h create mode 100644 datafile/dxf/dxflib/ReadAutoCAD.h create mode 100644 datafile/dxf/dxflib/ReadDxfFile.h create mode 100644 datafile/dxf/dxflib/ReadTIIP.h create mode 100644 datafile/dxf/dxflib/WriteASTM.h create mode 100644 datafile/dxf/dxflib/WriteAutoCAD.h create mode 100644 datafile/dxf/dxflib/WriteDxfFile.h rename datafile/dxf/{dxflib => dxflib1}/dl_attributes.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_codes.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_creationadapter.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_creationinterface.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_dxf.cpp (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_dxf.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_entities.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_exception.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_extrusion.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_global.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_writer.h (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_writer_ascii.cpp (100%) rename datafile/dxf/{dxflib => dxflib1}/dl_writer_ascii.h (100%) diff --git a/NPlotter.pro b/NPlotter.pro index 5951c53..56de5b6 100644 --- a/NPlotter.pro +++ b/NPlotter.pro @@ -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 +} diff --git a/datafile/dxf/dxflib/DxfMath.h b/datafile/dxf/dxflib/DxfMath.h new file mode 100644 index 0000000..bf152a6 --- /dev/null +++ b/datafile/dxf/dxflib/DxfMath.h @@ -0,0 +1,215 @@ +#if !defined(DxfMath_h) +#define DxfMath_h + +#include +#include +#include + +#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); + +//得到pdPoint1,pdPoint2的中间点 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 &listBorder, CCurveNotchInforList &listAssistantCurve); + +//找给定边线中的字符串 +//[输入][输出] listAllTextData 所有字符串 输出时没有listText中的字符串 +//[输入] listBorder 边线实际点链 +//[输出] listText 辅助线 +void FindPatternText(CTextDataList &listAllTextData, CList &listBorder, CTextDataList &listText); + +//找给定纸样中的点 +//[输入][输出] listPointData 所有点 输出时没有在纸样中点 +//[输入] listBorder边线 +//[输出] listAssistantPoint 辅助点 +void FindPatternPoint(CPointDataList &listPointData, CList &listBorder, CCurveNotchInforList &listAssistantPoint); + +#endif \ No newline at end of file diff --git a/datafile/dxf/dxflib/GroupCode.h b/datafile/dxf/dxflib/GroupCode.h new file mode 100644 index 0000000..7346530 --- /dev/null +++ b/datafile/dxf/dxflib/GroupCode.h @@ -0,0 +1,847 @@ +#if !defined(GROUPCODE_H) +#define GROUPCODE_H + +#include +#include +#include +#include +//#include + +#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 +{ +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 &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 m_listdCode40; //存放组码为40的值 结点数 + QList m_listdCode41; //存放组码为41的值 权值 如果为空权值为1 + QPointDataList m_listReadCurve; //存放读入的拟合点, 不做任何处理,读入什么数据存放什么数据 + + QList 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 &listPointDataList); + + //设置曲线链中的点类型和放码ID + //输入参数: + // listPointGrade 放码点 + // listTurnPointLayer 转折点 + // listCurvePointLayer 曲线点 + void SetPointTypeGradeID(CTextDataList &listPointGrade, QPointDataList &listTurnPointLayer, QPointDataList &listCurvePointLayer); + + //计算曲线实际点链 + //[输入] iDPMM 放大比例 + void CalcuateActualPoint(int iDPMM); + + //20200219 XQ 获取实际点链 + //输出参数: + // listCurve 实际点链 + //说明: + // 调用该函数之前必须调用计算实际点链函数 + void GetCurve(QList &listCurve); + + //20201021 XQ 移除相邻的相同点,只对控制点操作 + void RemoveSamePoint(); +private: + + //计算实际点链 + //[输入] iDPMM 放大比例 + //[输入] listCtrlPoint 控制点 只有一种类型(头尾点除外,中间点只有一种类型转折点,曲线点,圆弧点) + //[输出] listPoint实际点链 + void CalcuateCurveInfor(int iDPMM, QPointDataList &listCtrlPoint, QList &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 + //[输入] ptPoint0,ptPoint1,ptPoint2,ptPoint3方程的四个已知点 + //[输入] 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 &listPoint); + + //QPoint转QPointData + void PointToPointData(QList &listPoint, int iDPMM, QPointDataList &listPointData); + + //根据listDataPoint中点类型将listDataPoint,listRealPoint分段 + void NurbsSegmention(CPDSNurbsPointList &listDataPoint, CPDSNurbsPointList &listRealPoint, int iDPMM, + CArray < QList , QList > &arCtrlPoint, CArray < QList , QList > &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 +{ +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 &listCurve); +}; + +class CCurveNotchInforList: public QList +{ +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 &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 +{ +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 +{ +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 +{ +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 +{ +public: + CCloseCurveInforList& operator=(CCloseCurveInforList& rhs); // 赋值 + + //获取指定索引值上的项 + //输入参数: + // iIndex 索引值,从0开始,不可越界 + //返回值: + CCloseCurveInfor& operator[](int iIndex); + + //找列表中面积最大的 + POSITION FindMaxAreaRect(); +}; + +///////////////////////////////////////////////////////////////////////// +//纸样块, 该类主要用于读入数据之后处理纸样数据时用到的 + +//说明: +//该类没有SetRotateOffsetScale的原因, 在类中不需要对数据进行偏移->旋转->放大缩小, 偏移和旋转 放在m_ptOffset,m_dAngle中 +class CPatternBlock : public QObject +{ +public: + QString m_strPatternName; //纸样名 + QString m_strSizeName; //号型名 + QString m_strComment; //注释COMMENT/ANNOTATION + CStringArray m_arrMaterial; //布料名 + CUIntArray m_arrQuantity; //总片布料份数 Quantity: + CUIntArray m_arrLQuantity; //左片布料份数 Quantity: + //m_arrQuantity, m_arrLQuantity大小保持一致 + + bool m_bFlip; //翻转信息 =true 允许翻转 + double m_dRotation; //最大倾斜角 Rotation<0...360> + bool m_bFold; //折叠 Fold: =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 +{ +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 &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是否为0,strValue2是否为 POLYLINE, LINE...) +//[输入] strValue1 需要判断的字符串 +//[输入] strValue2 需要判断的字符串 +//返回值: +// =true 是;false 不是 +//说明: +//strValue1为空的话不判断不为空 判断是否为0, 为0继续strValue2的判断 +bool JudgeCode(QString strValue1, QString strValue2); + +#endif diff --git a/datafile/dxf/dxflib/PDSMath.h b/datafile/dxf/dxflib/PDSMath.h new file mode 100644 index 0000000..3061ec2 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath.h @@ -0,0 +1,2522 @@ +// PDSMath.h + +#if !defined(PDSMath_h) +#define PDSMath_h + +#include +#include +#include + +#define CONST_PI 3.14159265359 +#define DBL_MIN 2.2250738585072014e-308 +#define DBL_MAX 1.7976931348623158e+308 + +#define RPG_PT_GNCP 0 //端点(放码非弧线点) +#define RPG_PT_NGCP 1 //不放码弧线点 +#define RPG_PT_NGNCP 2 //直线点(不放码非弧线点) +#define RPG_PT_GCP 3 //放码弧线点 +#define RPG_PT_GP 64 //放码值 +#define RPG_PT_INSPT 100 //插值点 +#define RPG_PT_SEAM 128 //份缝点 +#define RPG_PT_NODEF -1 //无定义点 + +#define CONST_MAXDISTANCE 0.05 //对于不在线上的点,默认在线上有对应点的最大距离,单位:mm. 考虑到旧系统中的分辨率为40,所以最小取值0.05mm +#define F_MAX_TANGENT_ERROR 0.1 //20131015 计算切线时的检索长度,单位:mm + +//带点类型的点,该类对点的类型没有指定其意义,使用者可根据自己的要求来使用 +class CTypePoint : public CObject +{ +public: + CPoint m_ptPoint; + int m_iType; + + CTypePoint(); + CTypePoint(CTypePoint &a); + CTypePoint(CPoint ptPoint,int iType); + ~CTypePoint(); + void operator=(const CTypePoint &a); + BOOL operator==(CTypePoint& a); + BOOL operator!=(CTypePoint& a); +}; + +class CTypePointListArray; // 声明 + +//带类型的点的链表 +class CTypePointList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CTypePointList& operator=(CTypePointList& rhs); //赋值 + BOOL operator==(CTypePointList& rhs); //等号 + BOOL operator!=(CTypePointList& rhs); //不等号 + CTypePoint& operator[](int iIndex); //根据索引值检索,不可越界 + + //以下查找都是从Head->GetNext->Tail遍历,遇到第一个满足条件者即返回 + + //查找给定点在链表中的索引值 + int FindIndexOfTypePoint(CTypePoint TypePoint); + + //查找给定点在链表中位置 + POSITION FindPositionOfPoint(CPoint ptPoint); + + //查找给定点在链表中的索引值 + int FindIndexOfPoint(CPoint ptPoint); + + //查找给定类型在链表中的位置 + POSITION FindPositionOfType(int iType); + + //查找给定类型在链表中的索引值 + int FindIndexOfType(int iType); + + //根据给定的类型与点链设置this + //特别说明: + // 设置完成后,this的长度等于listPoint,每个点一一对应,并且this的每一项的类型等于iType + void SetTypePointList(int iType, CList& listPoint); + + //将this中的点链提取至listPoint + void ExtractPointList(CList& listPoint); + + //将listPoint设置到this的m_ptPoint中 + void SetOnlyPointList(CList& listPoint); + + //根据指定的类型将this分段 + //特别说明: + // (1)应用举例,该函数可应用于根据放码点将控制点分段,iType实际上表示bGrade + // (2)alTypePoint[]至少有两个点,本函数会保证这一点 + // (3)bClose=true,那么至少要保证链表中有两个点等于iType,否则alTypePoint只有一条链表,并且等于this + //输入参数: + // bClose =true 闭合,头尾点不能相等,本函数不做判断,=false 开口 + // iType 类型 + //输出参数: + // alTypePoint 数组,遇到iType的点就要作为该段结束 + void DivideTypePointListEqualType(BOOL bClose, int iType, CTypePointListArray& alTypePoint); + + //只要类型不等于0就进行分段 + //特别说明: + // (1)应用举例,该函数可应用于根据缝份数据将实际的分段,m_iType实际上表示缝份数据的指针 + // (2)这样分段过后,每一段的头点与尾点带有缝份数据,而中间的点没有缝份数据,从而对整段计算缝份 + // (3)alTypePoint[]至少有两个点,本函数会保证这一点 + // (4)bClose=true,那么至少要保证链表中有两个点m_iType不为0,否则alTypePoint只有一条链表,并且等于this + //输入参数: + // bClose =true 闭合,头尾点不能相等,本函数不做判断,=false 开口 + //输出参数: + // alTypePoint 数组,如果bClose=true,那么每段的头点与尾点的m_iType都不为0 + void DivideTypePointListWhenTypeNoZero(BOOL bClose, CTypePointListArray& alTypePoint); + + //根据m_iType的数值排序 + //特别说明: + // (1)应用举例,m_ptPoint表示交点,m_iType表示该交点与曲线头点的距离(线上长度),那么,Sort之后的交点就是有序的 + //输入参数: + // bSmallToLarge =true 从小到大,=false 从大到小 + void SortByType(BOOL bSmallToLarge = TRUE); + + void MakeReverse(); //将this反向 + + POSITION FindPositionOfSmallestType(void); //查找m_iType最小的那个元素的位置 + int FindIndexOfSmallestType(void); // 查找m_iType最小的那个元素的索引值 + + POSITION FindPositionOfLargestType(void); //查找m_iType最大的那个元素的位置 + int FindIndexOfLargestType(void); // 查找m_iType最大的那个元素的索引值 + + //在折线插入点 + //输入参数: + // ptPoint 给定点 + // dMaxError 判断点在线上的最大误差值 + // iInsertType 插入点时的m_iType值 + //返回值: + // =true 给定点在this中(输入时已经在this中,或者在this插入),=false 给定点不在this中 + BOOL InsertPointAtPolyline(CPoint ptPoint, double dMaxError, int iInsertType = 0); + + //在多边形插入点 + //输入参数: + // ptPoint 给定点 + // dMaxError 判断点在线上的最大误差值 + // iInsertType 插入点时的m_iType值 + //返回值: + // =true 给定点在this中(输入时已经在this中,或者在this插入),=false 给定点不在this中 + BOOL InsertPointAtPolygon(CPoint ptPoint, double dMaxError, int iInsertType = 0); + + //查找最近点 + CPoint FindNearestPoint(CPoint ptPoint); + //查找最近点并输出最近距离 + CPoint FindNearestPoint(CPoint ptPoint, int& nDistance); + //根据最大误差值查找最近点 + BOOL FindNearestPoint(CPoint ptPoint, double dMaxError, CPoint& ptOutput); +}; + +//类型点链表的数组 +class CTypePointListArray : public CArray +{ +public: //扩展的变量 +public: //扩展的方法 + + CTypePointListArray& operator=(CTypePointListArray& rhs); //赋值 +}; + +class CRPGrade_Point : public CObject { +public: + CPoint m_ptPoint; + int m_nType; + long n_SerNo; + +public: + + CRPGrade_Point(); + CRPGrade_Point(CRPGrade_Point &a); + CRPGrade_Point(CPoint ptPoint,int nType,long nSerNo); + CRPGrade_Point(CPoint ptPoint,int nType); + ~CRPGrade_Point(); + void operator=(CRPGrade_Point &a); +}; + +class CRotateMove : public CObject { +public: + double m_dAngle; //旋转的角度 + double m_dSin,m_dCos; //旋转的角度正,余弦,引入此变量是为了不重复计算 + CPoint m_ptPointO; //旋转原点 + CPoint m_ptOffset; //偏移量 + +public: + CRotateMove(); + CRotateMove(CRotateMove& rhs); + CRotateMove(double dAngle,CPoint ptPointO,CPoint ptOffset); + ~CRotateMove(); + void operator=(CRotateMove &a); + + void Initial(); +}; + +class CRotateMoveList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CRotateMoveList& operator=(CRotateMoveList& rhs); //赋值 + CRotateMove& operator[](int iIndex); //根据索引值检索,不可越界 +}; + +class CDBLPoint : public CObject { +public: + double x,y; + +public: + CDBLPoint(); + CDBLPoint(double x1,double y1); + CDBLPoint(CDBLPoint &a); + ~CDBLPoint(); + void operator=(CDBLPoint &a); + BOOL operator==(CDBLPoint &a); + + //使用ptPoint设置this + void SetPoint(CPoint ptPoint); + + //返回CPoint点 + CPoint GetPoint(void); +}; + +class CDBLPointList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CDBLPointList& operator=(CDBLPointList& rhs); //赋值 + CDBLPoint& operator[](int iIndex); //根据索引值检索,不可越界 + + //使用listPoint设置this + void SetPoint(CList& listPoint); + + //将this中的点输出到listPoint + void GetPoint(CList& listPoint); +}; + +class CDBLPointListArray : public CArray +{ +public: //扩展的变量 +public: //扩展的方法 + + CDBLPointListArray& operator=(CDBLPointListArray& rhs); //赋值 +}; + +class C4PRgn : public CObject { +public: + CPoint m_ptLU,m_ptLD,m_ptRU,m_ptRD; //字符串显示时占用的区域m_ptLU→m_ptRU→m_ptRD→m_ptLD→m_ptLU + +public: + C4PRgn(); + C4PRgn(C4PRgn &a); + C4PRgn(CPoint ptLU,CPoint ptLD,CPoint ptRU,CPoint ptRD); + void operator=(C4PRgn &a); + BOOL operator==(C4PRgn& a); +}; + +//四舍五入取整 +//输入参数: +// x +//返回值: +// 四舍五入后的整数 +int IntRound(double x); + +//样点旋转 +//输入参数: +// (nPx,nPy)被旋转点,(x,y)旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦 +//输出参数: +// (nPxNew,nPyNew)旋转后的值 +void PointRotate(int nPx,int nPy,int x,int y,double dSinBeta,double dCosBeta,int& nPxNew,int& nPyNew); +void PointRotate(double dX,double dY,double dXO,double dYO,double dSinBeta,double dCosBeta,double& dXNew,double& dYNew); +//样点旋转 +//输入参数: +// ptPoint被旋转点,ptPointO旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦 +//输出参数: +// ptPoint旋转后的值 +void PointRotate(CPoint &ptPoint,CPoint ptPointO,double dSinBeta,double dCosBeta); + +//样点旋转 +//输入参数: +// listPoint1被旋转的点链,ptPointO旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦 +//输出参数: +// listPoint2旋转后的值 +void PointRotate(CList &listPoint1,CPoint ptPointO,double dSinBeta,double dCosBeta,CList &listPoint2); + +//样点平移 +//输入参数: +// listPoint1被平移的点链 +// nDx,nDy XY轴的平移量 +//输出参数: +// listPoint2平移后的值 +void PointMove(CList &listPoint1,int nDx,int nDy,CList &listPoint2); + +//将ptPoint坐标缩放 +//输入参数: +// ptPoint 给定点 +// dScale >1放大,<1缩小 +//返回值: +// 放大缩小后的点 +CPoint PointScale(CPoint ptPoint,double dScale); +//以ptPointO为坐标原点,将ptPoint缩放dScale +CPoint PointScale(CPoint ptPoint,CPoint ptPointO,double dScale); +//以ptPointO为坐标原点,沿ptPointO,ptPoint1为方向,将ptPoint缩放dScale +CPoint PointScale(CPoint ptPoint,CPoint ptPointO,CPoint ptPoint1,double dScale); + +//对给定点进行先平移后再缩放 +//输入参数: +// ptPoint 给定点 +// ptOffset 平移量 +// dScale 缩放 +//返回值: +// 平移缩放后的点 +CPoint PointMoveScale(CPoint ptPoint,CPoint ptOffset,double dScale); + +//20140603 对给定点平移旋转 +//输入参数: +// ptPoint 给定点 +// ptOrignalS 转圆心S +// ptOrignalE 旋转圆心E +// ptRotateS 旋转点S +// ptRotateE 旋转点E +//返回值: +// 平移旋转点 +CPoint PointMoveRotate(CPoint ptPoint, CPoint ptOrignalS, CPoint ptOrignalE, CPoint ptRotateS, CPoint ptRotateE); + +//20140603 对给定点平移旋转 +//输入参数: +// listPoint 给定点链 +// ptOrignalS 转圆心S +// ptOrignalE 旋转圆心E +// ptRotateS 旋转点S +// ptRotateE 旋转点E +//输出参数: +// listMoveRotatePoint平移旋转点链 +void PointMoveRotate(CList &listPoint, CPoint ptOrignalS, CPoint ptOrignalE, CPoint ptRotateS, CPoint ptRotateE, CList &listMoveRotatePoint); + +//解一元二次方程ax2+bx+c=0 +//返回值: +// =0,无解 +// =1,有一个解x1(x2=x1) +// =2,有两个解x1,x2 +// =3,有无穷解或无实根 +int Quadratic(double a,double b,double c,double& x1,double& x2); + +//求直线方程ax+by+c=0的系数 +//输入参数: +// (x1,y1),(x2_y2) 直线上两点的坐标 +//输出参数: +// a,b,c 直线方程ax+by+c=0的系数 +void LineEquationCoefficient(int x1,int y1,int x2,int y2,double& a,double& b,double& c); +void LineEquationCoefficient(double x1,double y1,double x2,double y2,double& a,double& b,double& c); + +//求直线方程ax+by+c=0的系数 +//输入参数: +// ptPoint1,ptPoint2 直线上两点的坐标 +//输出参数: +// a,b,c 直线方程ax+by+c=0的系数 +void LineEquationCoefficient(CPoint ptPoint1,CPoint ptPoint2,double& a,double& b,double& c); + +//求两直线的交点 +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// a2,b2,c2 直线a2*x+b2*y+c2=0 +//输出参数 +// (x,y) 交点坐标 +//返回值 +// =0,没有交点 +// =1,有交点(x,y) +// =2,两直线重合 +int IntOfTwoLine(double a1,double b1,double c1,double a2,double b2,double c2,double& x,double& y); + +//求两直线的交点 +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// a2,b2,c2 直线a2*x+b2*y+c2=0 +//输出参数 +// (nx,ny) 交点坐标 +//返回值 +// =0,没有交点 +// =1,有交点(nx,ny) +// =2,两直线重合 +int IntOfTwoLine(double a1,double b1,double c1,double a2,double b2,double c2,int& nx,int& ny); + +//求两直线的交点 +//输入参数 +// (nXS1,nYS1),(nXE1,nYE1) 直线1的起点和终点坐标 +// (nXS2,nYS2),(nXE2,nYE2) 直线2的起点和终点坐标 +//输出参数 +// (nx,ny) 交点坐标 +//返回值 +// =0,没有交点 +// =1,有交点(nx,ny) +// =2,两直线重合 +int IntOfTwoLine(int nXS1,int nYS1,int nXE1,int nYE1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求两直线的交点 +//输入参数 +// PointS1_PointE1 直线1的起点和终点 +// PointS2_PointE2 直线2的起点和终点 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,有交点ptIntersection +// =2,两直线重合 +int IntOfTwoLine(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//求两直线段的交点 +//输入参数 +// (nXS1,nYS1),(nXE1,nYE1) 直线段1的起点和终点坐标 +// (nXS2,nYS2),(nXE2,nYE2) 直线段2的起点和终点坐标 +//输出参数 +// (nx,ny) 交点坐标 +//返回值 +// =0,没有交点 +// =1,交点同时在两条线段内(包括两端点),交点(nx,ny) +// =2,交点不在线段内(包括两端点),交点(nx,ny) +// =3,没有共同端点的重叠线段,两线段在同一直线上(有一个以上的交点)且没有共同的端点 +// =4,有共同端点的不重叠线段,两线段在同一直线上且只有一个端点重叠(nx,ny) +// =5,有共同端点的重叠线段,其中(nx,ny)是重叠部分中非共同的端点 +int IntOfTwoLineSegment(int nXS1,int nYS1,int nXE1,int nYE1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求两直线段的交点 +//输入参数 +// PointS1_PointE1 直线段1的起点和终点 +// PointS2_PointE2 直线段2的起点和终点 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点同时在两条线段内(包括两端点),交点ptIntersection +// =2,交点不在线段内(包括两端点),交点ptIntersection +// =3,没有共同端点的重叠线段,两线段在同一直线上(有一个以上的交点)且没有共同的端点 +// =4,有共同端点的不重叠线段,两线段在同一直线上且只有一个端点重叠ptIntersection +// =5,有共同端点的重叠线段,其中ptIntersection是重叠部分中非共同的端点 +int IntOfTwoLineSegment(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// (nXS2,nYS2),(nXE2,nYE2) 线段的起点和终点坐标 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点(nx,ny) +// =2,交点不在线段内(包括两端点),交点(nx,ny) +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(double a1,double b1,double c1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// PointS2,PointE2 线段的起点和终点坐标 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点ptIntersection +// =2,交点不在线段内(包括两端点),交点ptIntersection +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(double a1,double b1,double c1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// (nXS1,nYS1),(nXE1,nYE1) 直线的起点和终点坐标 +// (nXS2,nYS2),(nXE2,nYE2) 线段的起点和终点坐标 +//输出参数 +// (nx,ny) 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点(nx,ny) +// =2,交点不在线段内(包括两端点),交点(nx,ny) +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(int nXS1,int nYS1,int nXE1,int nYE1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// PointS1_PointE1 直线的起点和终点 +// PointS2_PointE2 线段的起点和终点 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点ptIntersection +// =2,交点不在线段内(包括两端点),交点ptIntersection +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); +//求矢量ptPointS1→ptPointE1和矢量ptPointS2→ptPointE2的交点!!! +//输入参数 +// PointS1,PointE1 矢量ptPointS1→ptPointE1 +// PointS2,PointE2 矢量ptPointS2→ptPointE2 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,有交点ptIntersection +// =2,两直线重合 +int IntOfTwoVectorLine(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//直线和圆的交点 +//输入参数: +// a,b,c 直线:ax+by+c=0; +// (xc,yc) 圆心 +// nR 半径 +//输出参数: +// lpptIntersection1,lpptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点 +// =2,两个交点 +int IntOfLineCircle(double a,double b,double c,int xc,int yc,int nR,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//直线和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// lpptIntersection1,lpptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点 +// =2,两个交点 +int IntOfLineCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//直线和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// ptIntersection1,ptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点 +// =2,两个交点 +int IntOfLineCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,CPoint& ptIntersection1,CPoint& ptIntersection2); + +//直线段和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线段的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// lpptIntersection1,lpptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点(包括两端点) +// =2,两个交点(包括两端点) +int IntOfLineSegmentCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//直线段和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线段的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// ptIntersection1,ptIntersection2 直线段和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点(包括两端点) +// =2,两个交点(包括两端点) +int IntOfLineSegmentCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,CPoint& ptIntersection1,CPoint& ptIntersection2); + +//折线和圆的交点 +//输入参数: +// listPolyline 折线 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// listIntPoint 折线和圆的交点 +//返回值 +// 交点个数(=0,没有交点) +int IntOfPolylineCircle(CList &listPolyline,POINT ptCenter,int nRadius,CList &listIntPoint); + +//求两圆的交点 +//输入参数 +// x1,y1,r1 圆:(x-x1)*(x-x1) + (y-y1)*(y-y1) = r1*r1 +// x2,y2,r2 圆:(x-x2)*(x-x2) + (y-y2)*(y-y2) = r2*r2 +//输出参数 +// (nIntX1,nIntY1),(nIntX2,nIntY2) 两交点坐标 +//返回值 +// =0,没有交点 +// =1,有一个交点 +// =2,有两个交点 +int IntOfTwoCircle(int x1,int y1,int r1,int x2,int y2,int r2,int& nIntX1,int& nIntY1,int& nIntX2,int& nIntY2); + +//求两圆的交点 +//输入参数 +// ptCenter1,nRadius1 圆心和半径 +// ptCenter2,nRadius2 圆心和半径 +//输出参数 +// lpptIntersection1,lpptIntersection2 两交点 +//返回值 +// =0,没有交点 +// =1,有一个交点 +// =2,有两个交点 +int IntOfTwoCircle(POINT ptCenter1,int nRadius1,POINT ptCenter2,int nRadius2,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//求两圆的交点 +//输入参数 +// ptCenter1,nRadius1 圆心和半径 +// ptCenter2,nRadius2 圆心和半径 +//输出参数 +// ptIntersection1,ptIntersection2 两交点 +//返回值 +// =0,没有交点 +// =1,有一个交点 +// =2,有两个交点 +int IntOfTwoCircle(POINT ptCenter1,int nRadius1,POINT ptCenter2,int nRadius2,CPoint& ptIntersection1,CPoint& ptIntersection2); + +//求线段和折线的交点 +//特别所明: +// 该函数是求线段和折线中的各线段的交点,而不是求直线和折线中的各线段的交点!!! +// 参见IntOfLinePolyline(...). +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfLineSegmentPolyline(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); +//与IntOfLineSegmentPolyline(...)相比,IntOfLineSegmentPolyline_Old(...)有个错误(包括了一句"case 2:") +int IntOfLineSegmentPolyline_Old(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); + +//求矢量ptPointS→ptPointE和折线的交点!!! +//特别所明: +// 该函数是求矢量和折线中的各线段的交点,而不是求直线(或直线段)和折线中的各线段的交点!!! +// 要求交点在线段ptPointS_ptPointE上或在矢量ptPointS→ptPointE的延长线上 +// 参见IntOfLineSegmentPolyline(...)和IntOfLinePolyline(...). +//输入参数 +// ptPointS,ptPointE 矢量ptPointS→ptPointE +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfVectorLinePolyline(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); + +//求直线和折线的交点!!! +//特别所明: +// 该函数是求直线和折线中的各线段的交点,而不是求直线段和折线中的各线段的交点!!! +// 参见IntOfLineSegmentPolyline(...). +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfLinePolyline(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); + +//求直线和折线的交点!!! +//特别所明: +// 该函数是求直线和折线中的各线段的交点,而不是求直线段和折线中的各线段的交点!!! +// 参见IntOfLineSegmentPolyline(...). +//输入参数 +// a,b,c 直线方程ax+by+c=0 +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfLinePolyline(double a,double b,double c,CList& listPolyline,CList& listIntPoint); + +//求直线和折线链头的延长线的交点 +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +// dLength 用于计算延长线时的搜索长度 +//输出参数 +// ptIntPoint 交点 +//返回值 +// 交点个数 +int IntOfLinePolylineExtendHead(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,double dLength,CPoint &ptIntPoint); +int IntOfLinePolylineExtendHead(double a,double b,double c,CList& listPolyline,double dLength,CPoint &ptIntPoint); + +//求直线和折线链尾的延长线的交点 +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +// dLength 用于计算延长线时的搜索长度 +//输出参数 +// ptIntPoint 交点 +//返回值 +// 交点个数 +int IntOfLinePolylineExtendTail(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,double dLength,CPoint &ptIntPoint); +int IntOfLinePolylineExtendTail(double a,double b,double c,CList& listPolyline,double dLength,CPoint &ptIntPoint); + +//求折线和折线的交点 +//输入参数 +// listPolyline1 折线 +// listPolyline2 折线 +//输出参数 +// listIntPoint 交点链,交点以在listPolyline1的出现顺序从头到尾排列 +//返回值 +// 交点个数 +int IntOfTwoPolyline(CList& listPolyline1,CList& listPolyline2,CList& listIntPoint); + +//[20161229 syf]求折线和折线的交点 +//特别说明: +// (1)该函数拷贝IntOfTwoPolyline()代码,但是在判断IntOfTwoLineSegment()的返回值时,{1,4,5}都被采用,而IntOfTwoPolyline()仅仅采用=1的情况 +//输入参数 +// listPolyline1 折线 +// listPolyline2 折线 +//输出参数 +// listIntPoint 交点链,交点以在listPolyline1的出现顺序从头到尾排列 +//返回值 +// 交点个数 +int IntOfTwoPolyline_101(CList& listPolyline1,CList& listPolyline2,CList& listIntPoint); + +//匹配两直线段的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// ptPointS1_ptPointE1 直线段1的起点和终点 +// ptPointS2_ptPointE2 直线段2的起点和终点 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +//返回值 +// 若两直线段的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfTwoLineSegment(POINT ptPoint,double dMaxError,POINT ptPointS1,POINT ptPointE1, + POINT ptPointS2,POINT ptPointE2,POINT& ptIntersection,double& dDistance); + +//匹配线段和圆的交点 +//输入参数: +// ptPoint +// dMaxError 最大匹配距离 +// ptPointS,ptPointE 直线段的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +//返回值 +// 若线段和圆的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfLineSegmentCircle(POINT ptPoint,double dMaxError,POINT ptPointS,POINT ptPointE, + POINT ptCenter,int nRadius,POINT& ptIntersection,double& dDistance); + +//匹配两圆的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// ptCenter1,nRadius1 圆心和半径 +// ptCenter2,nRadius2 圆心和半径 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +//返回值 +// 若两圆的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfTwoCircle(POINT ptPoint,double dMaxError,POINT ptCenter1,int nRadius1, + POINT ptCenter2,int nRadius2,POINT& ptIntersection,double& dDistance); + +//匹配线段和折线的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// ptPointS,ptPointE 线段 +// listPolyline 折线 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +// nLocate 交点位置(第nLocate个交点) +//返回值 +// 若线段和折线的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfLineSegmentPolyline(POINT ptPoint,double dMaxError,POINT ptPointS, + POINT ptPointE,CList &listPolyline, + POINT &ptIntersection,double &dDistance,int& nLocate); + +//匹配两折线的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// listPolyline1 折线1 +// listPolyline2 折线2 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +// nLocate 交点位置(第nLocate个交点) +//返回值 +// 若折线的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfTwoPolyline(POINT ptPoint,double dMaxError,CList &listPolyline1, + CList &listPolyline2,POINT &ptIntersection,double &dDistance,int& nLocate); + +//滤点 +//将完全在(ptPoint.x-nMaxError,ptPoint.y-nMaxError)__(ptPoint.x+nMaxError,ptPoint.y-nMaxError) +//之外的线段点删除 +//输入参数: +// ptPoint 域的中心点 +// nMaxError 域的半径 +// listPoint1 滤点前的点链 +//输出参数: +// listPoint2 滤点后的点链 +void FilterPointOfListPoint(POINT ptPoint,int nMaxError,CList &listPoint1,CList &listPoint2); + +//求过点(nPx,nPy)和直线ax+by+c=0垂直的直线与直线ax+by+c=0的交点(nFixX,nFixY) +//输入参数 +// (nPx,nPy)给定点的坐标 +// a,b,c 给定直线的系数 +//输出参数 +// (nFixX,nFixY)交点坐标 +void IntOfLinePointVL(int nPx,int nPy,double a,double b,double c,int& nFixX,int& nFixY); +void IntOfLinePointVL(double dPx,double dPy,double a,double b,double c,double& dFixX,double& dFixY); + +//求过点ptPoint1和直线ax+by+c=0垂直的直线与直线ax+by+c=0的交点ptPoint2 +//输入参数 +// ptPoint1给定点的坐标 +// a,b,c 给定直线的系数 +//输出参数 +// ptPoint2交点坐标 +void IntOfLinePointVL(CPoint ptPoint1,double a,double b,double c,CPoint& ptPoint2); + +//求过点ptPoint1和直线ptPoint2_ptPoint3垂直的直线与直线ptPoint2_ptPoint3的交点ptPoint4 +//输入参数 +// ptPoint1给定点的坐标 +// ptPoint2,ptPoint3 给定直线的两点 +//输出参数 +// ptPoint4交点坐标 +void IntOfLinePointVL(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint& ptPoint4); + +//以(x2,y2)_(x3,y3)为对称轴的对称点 +//输入参数; +// (x1,y1) 给定点 +// (x2,y2)_(x3,y3) 给定对称轴 +//输出参数: +// (nPx,nPy) 对称点 +void SymmetryPoint(int x1,int y1,int x2,int y2,int x3,int y3,int& nPx,int& nPy); +//以ptPoint2_ptPoint3为对称轴的对称点 +//输入参数; +// ptPoint1 给定点 +// ptPoint2_ptPoint3 给定对称轴 +//输出参数: +// ptPoint4 对称点 +void SymmetryPoint(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint &ptPoint4); +//以ptPoint1_ptPoint2为对称轴的对称点 +//输入参数; +// listPoint1 给定点链 +// ptPoint1_ptPoint2 给定对称轴 +//输出参数: +// listPoint2 对称点链 +void SymmetryPoint(CList &listPoint1,CPoint ptPoint1,CPoint ptPoint2,CList &listPoint2); +//以直线ax+by+c=0为对称轴的对称点 +//输入参数; +// listPoint1 给定点链 +// a,b,c 给定对称轴的直线方程 +//输出参数: +// listPoint2 对称点链 +void SymmetryPoint(CList &listPoint1,double a,double b,double c,CList &listPoint2); +void SymmetryPoint(CList &listDBLPoint1,double a,double b,double c,CList &listDBLPoint2); +//以直线ax+by+c=0为对称轴的对称点 +//输入参数; +// (x1,y1) 给定点 +// a,b,c 给定对称轴的直线方程 +//输出参数: +// (nPx,nPy) 对称点 +void SymmetryPoint(int x1,int y1,double a,double b,double c,int& nPx,int& nPy); +void SymmetryPoint(double x1,double y1,double a,double b,double c,double& dPx,double& dPy); +//以直线ax+by+c=0为对称轴的对称点 +//输入参数; +// ptPoint1 给定点 +// a,b,c 给定对称轴的直线方程 +//输出参数: +// ptPoint2 对称点 +void SymmetryPoint(CPoint ptPoint1,double a,double b,double c,CPoint& ptPoint2); +void SymmetryPoint(CDBLPoint ptDBLPoint1,double a,double b,double c,CDBLPoint& ptDBLPoint2); + +//求两点确定的直线与X轴的夹角,在[0,2pi)之间 +//输入参数: +// (startx,starty) 起点 +// (endx,endy) 终点 +//返回值: +// 夹角 +double angle_2(int startx,int starty,int endx,int endy); +//[20170330 syf] +double angle_2(double startx,double starty,double endx,double endy); + +//求两点确定的直线与X轴的夹角,在[0,2pi)之间 +//输入参数: +// ptPointS 起点 +// ptPointE 终点 +//返回值: +// 夹角 +double angle_2(POINT ptPointS,POINT ptPointE); + +//[20170330 syf] +double angle_2(CDBLPoint ptPointS,CDBLPoint ptPointE); + +//求矢量ptPointS1→ptPointE1逆时针方向旋转到矢量ptPointS2→ptPointE2的方向所经过的夹角,在[0,2pi)之间 +//输入参数: +// ptPointS1,ptPointE1 矢量ptPointS1→ptPointE1 +// ptPointS2,ptPointE2 矢量ptPointS2→ptPointE2 +//返回值: +// 夹角 +double angle_2(POINT ptPointS1,POINT ptPointE1,POINT ptPointS2,POINT ptPointE2); + +//[20170330 syf] +double angle_2(CDBLPoint ptPointS1,CDBLPoint ptPointE1,CDBLPoint ptPointS2,CDBLPoint ptPointE2); + +//给定弧线上三点(x1,y1),(x2,y2)和(x3,y3),以及圆心(cx,cy), +//其中(x2,y2)在(x1,y1)和(x3,y3)中间,按逆时针方向画弧时, +//当(x1,y1)是起点,(x3,y3)是终点时返回true,否则返回false +//特别说明:此处所说的逆时针是指显示器而言,对X向右为正,Y向上为正的坐标系来说此处是顺时针 +BOOL IsAnticlockwise(long x1,long y1,long x2,long y2,long x3,long y3,long cx,long cy); + +//[20170330 syf] +BOOL IsAnticlockwise_Double(double x1,double y1,double x2,double y2,double x3,double y3,double cx,double cy); + +///////////////////////// 计算三点定圆时的圆心和半径 /////////////////////////// +// 输入参数:三个样点(x1,y1),(x2,y2),(x3,y3) +// 算法描述: +// 过(x1,y1),(x2,y2)的中点作垂线L1, +// 过(x2,y2),(x3,y3)的中点作垂线L2, +// 求L1,L2的交点. +// 输出参数: +// 如果不能形成圆返回false, +// 否则返回true其中圆心为(cx,cy),半径=cr. +// 按逆时针方向画弧时,如cr>0 则(x1,y1)是起点,(x3,y3)是终点, +// 如cr<0 则(x3,y3)是起点,(x1,y1)是终点. +// 特别说明:此处所说的逆时针是指显示器而言,如果对于对X向右为正, +// Y向上为正的坐标系来说此处是顺时针 +//////////////////////////////////////////////////////////////////////////////// +BOOL CircleCR(int x1,int y1,int x2,int y2,int x3,int y3,int& cx,int& cy,int& cr); + +//[20170330 syf] +BOOL CircleCR(double x1,double y1,double x2,double y2,double x3,double y3,double& cx,double& cy,double& cr); + +//求圆和一半径线(ptCenter和ptPoint的连线)的交点 +//输入参数 +// ptCenter 圆心 +// nRadius 半径 +// ptPoint 半径上的一点 +//返回值 +// 交点 +CPoint IntOfCircleRadial(CPoint ptCenter,int nRadius,CPoint ptPoint); + +//用追赶法求解三对角线方程组: AX=D +// ┌ ┐ ┌ ┐ ┌ ┐ +// │ a00 a01 │ │x0 │ │d0 │ +// │ a10 a11 a12 0 │ │x1 │ │d1 │ +// │ a21 a22 a23 │ │x2 │ │d2 │ +// │ . . . │ │. │ │. │ +// A=│ . . . │, X=│. │, D=│. │ +// │ . . . │ │. │ │. │ +// │ 0 an-2,n-3 an-2,n-2 an-2,n-1 │ │xn-2│ │dn-2│ +// │ an-1,n-2 an-1,n-1 │ │xn-1│ │dn-1│ +// └ ┘ └ ┘ └ ┘ +//输入参数: +// a[] 存放三对角线矩阵A的一维数组a00,a01,a10,a11,a12,a21,a22,a23,...,(an-1,n-2),(an-1,n-1) +// n 变量个数,方程组的阶数 +// d[] 方程组右端的常数向量 +//输出参数 +// 有唯一解时返回TRUE,其中d[]是方程组的解. +// 否则返回FALSE. +BOOL Cetrd1(double *a,int n,double *d); + +//求解带左下角右上角的三对角线方程组: AX=D +// ┌ ┐ ┌ ┐ ┌ ┐ +// │ a00 a01 a0n │ │x0 │ │d0 │ +// │ a10 a11 a12 0 │ │x1 │ │d1 │ +// │ a21 a22 a23 │ │x2 │ │d2 │ +// │ . . . │ │. │ │. │ +// A=│ . . . │, X=│. │, D=│. │ +// │ . . . │ │. │ │. │ +// │ 0 an-2,n-3 an-2,n-2 an-2,n-1 │ │xn-2│ │dn-2│ +// │ an-1,0 an-1,n-2 an-1,n-1 │ │xn-1│ │dn-1│ +// └ ┘ └ ┘ └ ┘ +//输入参数: +// a[] 存放矩阵A的一维数组a00,a01,a0n,a10,a11,a12,0,a21,a22,a23,0,...,(an-1,0),(an-1,n-2),(an-1,n-1) +// n 变量个数,方程组的阶数 +// d[] 方程组右端的常数向量 +//输出参数 +// 有唯一解时返回TRUE,其中d[]是方程组的解. +// 否则返回FALSE. +BOOL Cetrd2(double *a,int n,double *d); + +//对给定的型值点用二次Bezier曲线进行拟合,再用折线逼近. +// ┌ 1 -2 1 ┐┌P1 ┐ +// P(t)=[t2 t 1]│-2 2 0 ││p2 │ +// └ 1 0 0 ┘└p3 ┘ +//输入参数: +// listSP是型值点链. +// dMaxError 最大拟合误差(>=0.5) +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 否则返回false,listFitP中的数据和listSP相同 +BOOL BezierCurve(CList& listSP,double dMaxError,CList& listFitP); + +//说明: 根据参数求2次Bezier上的一个点 +//输入参数: +// (dX1,dY1),(dX2,dY2),(dX3,dY3) 2次Bezier的三个控制点 +// dT 参数T +//返回值: +// point 与dT对应的点 +CPoint BezierPoint(double dX1, double dY1, double dX2, double dY2, double dX3, double dY3, double dT); +//求与2次Bezier线上给定方向的切线的切点的参数值 +//输入参数: +// (dX1,dY1),(dX2,dY2),(dX3,dY3) 2次Bezier的三个控制点 +// pointS,pointE 切线方向(两点不能相同) +//返回值: +// 切点的参数 +double BezierPointParam(double dX1, double dY1, double dX2, double dY2, double dX3, double dY3, CPoint pointS,CPoint pointE); + +//对给定的型值点用参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL SplineCurve(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bNatural=true); + +//对给定的型值点用参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bTangentH =true 起点有切线条件 +// ptTangentH 起点有切线条件时切线上的点 +// bTangentT =true 终点有切线条件 +// ptTangentT 终点有切线条件时切线上的点 +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL SplineCurve(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bTangentH,CPoint ptTangentH,BOOL bTangentT,CPoint ptTangentT,BOOL bNatural); + +//对给定的型值点用Bezier曲线或参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//特别说明: +// 当型值点的个数是3且是开口线时使用Bezier曲线,否则使用样条曲线 +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL CurveFit(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bNatural=true); +//对给定的型值点用Bezier曲线或参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//特别说明: +// 当型值点的个数是3且起止点没有切线条件的开口线时使用Bezier曲线,否则使用样条曲线 +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bTangentH =true 起点有切线条件 +// ptTangentH 起点有切线条件时切线上的点 +// bTangentT =true 终点有切线条件 +// ptTangentT 终点有切线条件时切线上的点 +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL CurveFit(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bTangentH,CPoint ptTangentH,BOOL bTangentT,CPoint ptTangentT,BOOL bNatural); + +//计算NURBS曲线的实际点链(非均匀有理B样条) +//特别说明: +// 本函数调用API计算,不需要传入拟合误差 +//输入参数: +// listSP 型值点链,坐标系:既可以是纸样坐标系,又可以是设备坐标系 +// bClose =true 闭合,=false 开口 +//输出参数: +// listFitP 根据拟合曲线得到的逼近折线样点链,如果闭合,那么头尾点坐标不同!!! +//返回值: +// =true 计算成功,=false 计算失败 +BOOL CurveFit_NURBS(CList& listSP, CList& listFitP, BOOL bClose = FALSE); + +//反求开口曲线的控制点 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +//输出参数: +// listCtrlPoint 控制点链 +BOOL GetControlPointOfOpenCurve(int iDPMM,CList &listFitPoint,double dMaxError,CList &listCtrlPoint); + +//反求开口曲线的控制点 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +// listCtrlPoint 已有的控制点 +//输出参数: +// listCtrlPoint 控制点链,listCtrlPoint的起点和终点的坐标不相同 +BOOL GetControlPointOfOpenCurve(int iDPMM,CList &listFitPoint,double dMaxError,CList &listCtrlPoint); + +//反求闭合曲线的控制点,listFitPoint的起点和终点的坐标不相同 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +//输出参数: +// listCtrlPoint 控制点链,listCtrlPoint的起点和终点的坐标不相同 +BOOL GetControlPointOfCloseCurve(int iDPMM,CList &listFitPoint, + double dMaxError,CList &listCtrlPoint); + +//反求闭合曲线的控制点,listFitPoint的起点和终点的坐标不相同 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +// listCtrlPoint 已有的控制点 +//输出参数: +// listCtrlPoint 控制点链 +BOOL GetControlPointOfCloseCurve(int iDPMM,CList &listFitPoint,double dMaxError,CList &listCtrlPoint); + +//在点链listPointOld中的点与点链listPointNew的最小距离中的最大距离点 +//输入参数: +// listPointOld 点链 +// listPointNew 点链 +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +//输出参数: +// dMaxDistance 最大距离 +//返回值: +// 找到的最大距离点 +CPoint MaxDistancePoint(int iDPMM,CList &listPointOld,CList &listPointNew,double &dMaxDistance); + +//判断多边形点链从头到尾的方向 +//输入参数: +// listPolygon 多边形的点链. +//返回值: +// =true 逆时针(显示器坐标系),=false 顺时针(显示器坐标系) +BOOL IsAnticlockwise(CList& listPolygon); + +//使点链的方向变反,链头不变. +//输入参数: +// listPoint1 点链. +//输出参数: +// listPoint2 +void Reverse(CList& listPoint1,CList& listPoint2); +//使点链的方向变反,链尾变成链头. +//输入参数: +// listPoint1 点链. +//输出参数: +// listPoint2 +void ReverseT2H(CList& listPoint1,CList& listPoint2); + +//翻转 +//输入参数: +// listPoint1 待翻转的点链 +// x 水平翻转的对称轴 +// bHorizontal =true 水平翻转 +// y 垂直翻转的对称轴 +// bVertical =true 垂直翻转 +//输出参数: +// listPoint2 已翻转的点链 +void Flip(CList &listPoint1,int x,BOOL bHorizontal,int y,BOOL bVertical,CList &listPoint2); +//翻转 +//输入参数: +// ptPoint 待翻转的点链 +// x 水平翻转的对称轴 +// bHorizontal =true 水平翻转 +// y 垂直翻转的对称轴 +// bVertical =true 垂直翻转 +//输出参数: +// ptPoint 已翻转的点 +void Flip(CPoint &ptPoint,int x,BOOL bHorizontal,int y,BOOL bVertical); + +//点ptPoint到直线ax+by+c=0的距离 +double DistanceOfPL(CPoint ptPoint,double a,double b,double c); +//点ptPoint到直线ptPointL1_ptPointL2的距离 +double DistanceOfPL(CPoint ptPoint,CPoint ptPointL1,CPoint ptPointL2); +//点ptPoint到线段ptPointL1_ptPointL2的距离 +double DistanceOfPLineSegment(CPoint ptPoint,CPoint ptPointL1,CPoint ptPointL2); +//点ptPoint到折线listPolyline的最近距离 +double DistanceOfPPloyline(CPoint ptPoint,CList &listPolyline); + +//去掉点链中相同的点,若点链中有相同的点则只保留一个 +void RemoveSamePointOfPolygon(CList& listPoint); +//[20170330 syf] +void RemoveSamePointOfPolygon(CDBLPointList& listPoint); + +//去掉点链中相同的点,若点链中有相同的点则只保留一个 +//与RemoveSamePointOfPolygon不同的是首尾点相同时不再去掉一点 +void RemoveSamePointOfPolyline(CList& listPoint); + +//[20170330 syf] +void RemoveSamePointOfPolyline(CDBLPointList& listPoint); + +//删除距离<=dMinLength的点 +void Remove2NearPointOfPolygon(CList& listPoint,double dMinLength); +//删除距离<=dMinLength的点 +void Remove2NearPointOfPolyline(CList& listPoint,double dMinLength); + +//20160602 XQ 删除链中所有点距离<=dMinLength的点 +void RemoveAll2NearPointOfPolyline(CList& listPoint,double dMinLength); + +//求多边形中的一段折线. +//将多边形从点ptPointS顺时针(显示器坐标系)方向移动到点ptPointE所经过的区域. +//若ptPointS==ptPointE,则是从ptPointS到ptPointE的整条点链 +//特别说明: +// ptPointS,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL PolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointE,CList& listPolyline); + +//求多边形中的一段折线. +//将多边形从点ptPointS先经过ptPointM再到点ptPointE所经过的区域. +//特别说明: +// ptPointS,ptPointM,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的端点. +// ptPointM 中间点 +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL PolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointM,CPoint ptPointE,CList& listPolyline); + +//求多边形中的一段折线. +//将多边形从点ptPointS前向移动到点ptPointE所经过的区域.若ptPointS==ptPointE则是从ptPointS开始 +//到ptPointE结束的整条点链. +//特别说明: +// ptPointS,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL PrevPolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointE,CList& listPolyline); + +//求多边形中的一段折线. +//将多边形从点ptPointS后向移动到点ptPointE所经过的区域.若ptPointS==ptPointE则是从ptPointS开始 +//到ptPointE结束的整条点链. +//特别说明: +// ptPointS,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL NextPolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointE,CList& listPolyline); + +//求折线的点ptPointS与点ptPointE之间的一段折线. +//特别说明: +// ptPointS,ptPointE不一定是折线的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolyline(int iDPMM,CList& listPolyline1,CPoint ptPointS,CPoint ptPointE,CList& listPolyline2); + +//求折线的起点与点ptPointE之间的一段折线. +//特别说明: +// ptPointE不一定是折线的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointE折线段的终点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolylineS(int iDPMM,CList& listPolyline1,CPoint ptPointE,CList& listPolyline2); + +//求折线的点ptPointS与终点之间的一段折线. +//特别说明: +// ptPointS不一定是折线的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointE折线段的终点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolylineE(int iDPMM,CList& listPolyline1,CPoint ptPointS,CList& listPolyline2); + +//求折线的从点ptPointS开始,经过点ptPointM到端点(起点或终点)之间的一段折线. +//特别说明: +// ptPointS,ptPointM不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointS,ptPointM折线段的起止点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolylineSM(int iDPMM,CPoint ptPointS,CPoint ptPointM,CList& listPolyline1,CList& listPolyline2); + +//求依次经过ptArcPointS,ptArcPointM,ptArcPointE的圆的多边形表示 +//输入参数: +// ptCirclePointS,ptCirclePointM,ptCirclePointE 圆依次经过的点 +// dMaxError 最大逼近误差 +//输出参数: +// listPolygon 多边形点链 +//返回值: +// 成功true,否则false. +BOOL PolygonOfCircle(CPoint ptCirclePointS,CPoint ptCirclePointM,CPoint ptCirclePointE,CList& listPolygon,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolygonOfCircle(CDBLPoint ptCirclePointS,CDBLPoint ptCirclePointM,CDBLPoint ptCirclePointE,CDBLPointList& listPolygon,double dMaxError=0.5); + +//求圆逆时针方向(显示器坐标)的多边形表示. +//输入参数: +// ptCenter 圆心 +// ptCirclePointS 圆的起点 +// dMaxError 最大逼近误差 +//输出参数: +// listPolygon 多边形点链 +//返回值: +// 成功true,否则false. +BOOL PolygonOfCircle(CPoint ptCenter,CPoint ptCirclePointS,CList& listPolygon,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolygonOfCircle(CDBLPoint ptCenter,CDBLPoint ptCirclePointS,CDBLPointList& listPolygon,double dMaxError=0.5); + +//求依次经过ptArcPointS,ptArcPointM,ptArcPointE的弧线的折线表示. +//输入参数: +// ptArcPointS,ptArcPointM,ptArcPointE 弧线依次经过的点 +// dMaxError 最大逼近误差 +//输出参数: +// listPolyline 折线点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfArc(CPoint ptArcPointS,CPoint ptArcPointM,CPoint ptArcPointE,CList& listPolyline,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolylineOfArc(CDBLPoint ptArcPointS,CDBLPoint ptArcPointM,CDBLPoint ptArcPointE,CDBLPointList& listPolyline,double dMaxError=0.5); + +//求弧线的折线表示. +//输入参数: +// ptCenter 圆心 +// ptArcPointS 弧线起点 +// dAngle 扇形角度,>=0 逆时针(显示器坐标系),<0 顺时针(显示器坐标系),单位:弧度 +// dMaxError 最大逼近误差 +//输出参数: +// listPolyline 折线点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfArc(CPoint ptCenter,CPoint ptArcPointS,double dAngle,CList& listPolyline,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolylineOfArc(CDBLPoint ptCenter,CDBLPoint ptArcPointS,double dAngle,CDBLPointList& listPolyline,double dMaxError=0.5); + +//判断一点是否在多边形内 +//输入参数: +// point 给定点 +// lpPoints[0]...lpPoints[nCount-1] 多边形的顶点 +//返回值: +// =true 点在多边形内 +// =false 点不在多边形内 +BOOL PointInPolygon(POINT point,LPPOINT lpPoints,int nCount); + +//判断一点是否在多边形内 +//输入参数: +// point 给定点 +// listPolygon 多边形的点链 +//返回值: +// =true 点在多边形内 +// =false 点不在多边形内 +BOOL PointInPolygon(POINT point,CList& listPolygon); + +//求与直线P1P2相距nD的平行直线的方程,直线在矢量P1P2的左侧(显示器坐标系) +//重要说明: +// 在程序中是按X向右为正,Y向上为正的坐标系计算的,故所求直线是在矢量P1P2的右侧 +//输入参数: +// (nX1,nY1),(nX2,nY2) 直线P1P2的两点 +// nD 所求直线和给定直线P1P2的距离 +//输出参数: +// 当(nX1,nY1),(nX2,nY2)不是同一点时返回true, a,b,c 所求得的直线:ax+b*y+c=0; +// 当(nX1,nY1),(nX2,nY2)是同一点时返回fasle. +BOOL LineParallel(int nX1,int nY1,int nX2,int nY2,int nD,double& a,double& b,double& c); + +//求与直线P1P2相距nD的平行直线的方程,直线在矢量P1P2的左侧(显示器坐标系) +//重要说明: +// 在程序中是按X向右为正,Y向上为正的坐标系计算的,故所求直线是在矢量P1P2的右侧 +//输入参数: +// ptPoint1,ptPoint2 直线P1P2的两点 +// nD 所求直线和给定直线P1P2的距离 +//输出参数: +// 当ptPoint1,ptPoint2不是同一点时返回true, a,b,c 所求得的直线:ax+b*y+c=0 +// 当ptPoint1,ptPoint2是同一点时返回fasle. +BOOL LineParallel(CPoint ptPoint1,CPoint ptPoint2,int nD,double& a,double& b,double& c); + +//求一条点链的边界矩形 +CRect GetRectOfListPoint(CList& listPoint); + +//求两个整数的公约数 +//输入参数 +// nNum1,nNum2 两个需要求公约数的整数 +//返回值: +// nNum1,nNum2的公约数(若nNum1,nNum2中有0时返回1) +int CommomDivisor(int nNum1,int nNum2); + +//判断一点是否在两点之间 +//输入参数: +// ptPoint +// ptPointS +// ptPointE +//返回值: +// 若ptPoint在ptPointS_ptPointE之间返回true,否则false. +BOOL BetweenTwoPoint(CPoint ptPoint,CPoint ptPointS,CPoint ptPointE); + +//判断一点是否在折线的两点之间 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// ptPoint +// ptPointS +// ptPointE +// listPolyline1 +//输出参数: +// listPolyline2 ptPointS_ptPointE之间的折线. +//返回值: +// 若ptPoint在折线的ptPointS_ptPointE之间返回true,否则false. +BOOL BetweenTwoPointAtPolyline(int iDPMM,CPoint ptPoint,CPoint ptPointS,CPoint ptPointE,CList &listPolyline1,CList &listPolyline2); + +//求折线上两点间的长度 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// ptPointS,ptPointE 折线上的两点 +// listPolyline 折线 +//返回值: +// 两点间的长度 +int Get2PLengthOfPolyline(int iDPMM,CPoint ptPointS,CPoint ptPointE,CList &listPolyline); + +//求折线的长度 +//输入参数: +// listPolyline 折线 +//返回值: +// 折线长度 +int GetLengthOfPolyline(CList &listPolyline); + +//求折线的长度 +//输入参数: +// listPolyline 折线 +//输出参数: +// dLength 折线长度的双精度值 +//返回值: +// 折线长度 +int GetLengthOfPolyline(CList &listPolyline,double &dLength); + +//求多边形的长度 +//输入参数: +// listPolygon 多边形 +//返回值: +// 多边形长度 +int GetLengthOfPolygon(CList &listPolygon); + +//求多边形的长度 +//输入参数: +// listPolygon 多边形 +//输出参数: +// dLength 多边形长度的双精度值 +//返回值: +// 多边形长度 +int GetLengthOfPolygon(CList &listPolygon,double &dLength); + +//求两点距离 +//返回值: +// 两点间的距离 +int TwoPointLength(CPoint ptPoint1,CPoint ptPoint2); + +//求两点距离 +//输出参数: +// dLength 两点间距离的双精度值 +//返回值: +// 两点间的距离 +int TwoPointLength(CPoint ptPoint1,CPoint ptPoint2,double &dLength); + +//判断某点所处的象限 +//输入参数: +// ptPoint 给定点 +//返回值: +// 1:1象限,2:2象限,3:3象限,4:4象限 +int GetQuadrant(int x,int y); + +//将多边形中被折线截断的部分去掉 +//该函数用于计算衣片的填充轮廓线和切割轮廓线 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形 +// listPolyline 折线 +//输出参数: +// listPolygon 多边形 +//返回值: +// true 成功,否则false. +BOOL PolygonRemovePolyline(int iDPMM,CList &listPolygon,CList &listPolyline); + +//求点链listPoint中与ptPointS_ptPointE同向(从ptPointS到ptPointE),且距离ptPointE最近的点ptPoint +BOOL GetEquidireectionalPoint(CPoint ptPointS,CPoint ptPointE,CList &listPoint,CPoint &ptPoint); + +//判断两点(ptPoint1,ptPoint2)是否在直线ptPointLS_ptPointLE的同侧 +//输入参数: +// ptPoint1,ptPoint2 给定两点 +// ptPointLS,ptPointLE 直线的两点 +//返回值: +// true 同侧,false 异侧 +BOOL IsSameSide(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPointLS,CPoint ptPointLE); + +//判断点链listPoint是否在直线ptPointLS_ptPointLE的同侧 +//入口: +// listPoint 给定点链 +// ptPointLS,ptPointLE 直线的两点 +//返回值: +// true 同侧,false 异侧 +BOOL IsSameSide(CList &listPoint,CPoint ptPointLS,CPoint ptPointLE); + +//判断平行的直线ptPoint1_ptPoint2和ptPoint3_ptPoint4, +//其矢量方向ptPoint1→ptPoint2和ptPoint3→ptPoint4是否相同. +//特别说明:在2009年11月11日前要求ptPoint1_ptPoint2和ptPoint3_ptPoint4必须是平行线.之后改成矢量ptPoint1→ptPoint2和ptPoint3→ptPoint4的夹角不大于一个指定角度 +//输入参数: +// ptPoint1 +// ptPoint2 +// ptPoint3 +// ptPoint4 +// dCosMaxAngle 判断矢量ptPoint1→ptPoint2和ptPoint3→ptPoint4同向的最大允许夹角余弦,(原本默认值为1度的余弦,20130827之后要求传入余弦值) +//返回值: +// true 相同,false 相反. +BOOL IsSameDirection(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint ptPoint4,double dCosMaxAngle); + +//[20130827]恢复20091111之前的函数 +// 因为在绝大多数情况下,输入变量已经是平行的,只需要判断它们的方向是否相同,无需使用角度判断 +// 本次修改由杭州卓尚的<>文件引起,其中计算101版本缝份时,两条矢量的交点明明存在,但是使用该函数判断时(默认用1度的余弦值)判断失败,因为角度=1.83度 +BOOL IsSameDirection(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint ptPoint4); + +//判断点ptPoint是否在矩形(ptPoint1,ptPoint2)中 +//输入参数: +// ptPoint 给定点 +// ptPoint1,ptPoint2 矩形对角线 +//返回值: +// true 在矩形内,false 不在矩形内 +BOOL PointInRect(CPoint ptPoint,CPoint ptPoint1,CPoint ptPoint2); + +//将数字字符串小数点后面无用的0或小数点去掉 +void TrimAfterDot0(CString &strNum); +//将字符串第1个字符前的回车换行去掉 +CString TrimHeadCRLF(CString string); +//将字符串最后1个字符后的回车换行去掉 +CString TrimTailCRLF(CString string); + +//判断ptPoint是否在矢量ptPointS→ptPointE的左边(显示器坐标) +//返回值: +// =true 在左边(显示器坐标)或在矢量ptPointS→ptPointE上,=false 在右边(显示器坐标) +BOOL IsLeftPoint(CPoint ptPoint,CPoint ptPointS,CPoint ptPointE); +//判断ptPoint是否在多边形(矢量方向是多边形的起点到终点)的左边(显示器坐标) +//返回值: +// =true 在左边(显示器坐标)或在多边形上,=false 在右边(显示器坐标) +BOOL IsLeftPoint(CPoint ptPoint,CList &listPolyline); + +//包括两点的矩形 +//输入参数: +// ptPoint1 +// ptPoint2 +//返回值: +// 包括两点的矩形 +CRect RectOfContainTowPoint(CPoint ptPoint1,CPoint ptPoint2); + +//包括点链的矩形 +//输入参数: +// listPolyline 点链 +//返回值: +// 包括点链的矩形 +CRect RectOfPolyline(CList &listPolyline); + +//包括圆弧的矩形,圆弧是指按逆时针方向(显示器坐标,若X向右为正,Y向上为正,则是顺时针方向)由起点到终点所经过的部分 +//输入参数: +// ptLeftUp,ptRightDown 圆弧限定矩形的左上角和右下角(显示器坐标) +// ptPointS,ptPointE 圆弧的起点和终点 +//返回值: +// 包括圆弧的矩形 +CRect RectOfContainArc(CPoint ptLeftUp,CPoint ptRightDown,CPoint ptPointS,CPoint ptPointE); + +//文字占用的区域大小 +CSize StringSize(LOGFONT lfFont,CString string); +//文字占用的区域大小 +CSize StringSize(CDC *pDC,CString string); +//文字占用的区域大小及行数 +CSize StringSize(CDC *pDC,CString string,int &nLines); +//文字占用的区域 +//输入参数: +// lfFont 显示的字体 +// string 显示的文字 +// ptLU 显示的左上角位置 +// dScale 计算算时需要将字体的高度、宽度缩小的比例,主要是为了防止高度、宽度的值太大计算超界 +//输出参数: +// ptLD 左下角位置 +// ptRU 右上角位置 +// ptRD 右下角位置 +//返回值: +// 文字占用的区域大小 +CSize StringRgnLU(LOGFONT lfFont,CString string,CPoint &ptLU,CPoint &ptLD,CPoint &ptRU,CPoint &ptRD,double dScale=1.0); +//文字占用的区域 +//输入参数: +// lfFont 显示的字体 +// string 显示的文字 +// ptLD 显示的左下角位置 +// dScale 计算算时需要将字体的高度、宽度缩小的比例,主要是为了防止高度、宽度的值太大计算超界 +//输出参数: +// ptLU 左上角位置 +// ptRU 右上角位置 +// ptRD 右下角位置 +//返回值: +// 文字占用的区域大小 +CSize StringRgnLD(LOGFONT lfFont,CString string,CPoint &ptLU,CPoint &ptLD,CPoint &ptRU,CPoint &ptRD,double dScale=1.0); +//获取string的行数 +int StringLines(CString string); +//获取string第nLineIndex行的字符(起始行的nLineIndex为0) +CString GetSubString(CString string,int nLineIndex); + +//求多边形的面积 +//输入参数: +// listPolygon 多边形点链 +double AreaOfPloygon(CList &listPolygon); + +//判断线段和矩形是否相交 +//输入参数: +// rect 给定矩形 +// ptPointS_ptPointE 给定线段 +//输出参数: +// ptPointS,ptPointE 截取的线段(ptPointS_ptPointE) +//返回值: +// true 线段和矩形相交, false 线段和矩形不相交. +BOOL IntersectLineRect(CRect rect,CPoint &ptPointS,CPoint &ptPointE); + +//判断线段和矩形是否相交 +//输入参数: +// rect 给定矩形 +// ptPointS_ptPointE 给定线段 +//输出参数: +// ptPointS,ptPointE 截取的线段(ptPointS_ptPointE) +//返回值: +// true 线段和矩形相交, false 线段和矩形不相交. +BOOL IntersectLineRect(CRect rect,int &nXS,int &nYS,int &nXE,int &nYE); + +//判断折线和矩形是否相交 +//输入参数: +// rect 给定矩形 +// listPolyline 给定折线 +//返回值: +// true 折线和矩形相交, false 折线和矩形不相交. +BOOL IntersectPolylineRect(CList &listPolyline,CPoint ptPointS,CPoint ptPointE); + +//判断矩形是否可以框选到折线 +//输入参数: +// rect 框选的矩形 +// listPolyline 折线 +//返回值: +// true 可以框选到矩形 +// false 矩形框选不到折线 +BOOL IntersectPolylineRect(CRect rect,CList &listPolyline); + +//在点链listPoint中,从头到尾进行搜索,判断ptPoint1的最近点是否在ptPoint2的最近点前面(不一定是直接前趋) +//注意:如ptPoint1,ptPoint2不在点链中,则加入到点链中. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPoint +// ptPoint1 +// ptPoint2 +//返回值: +// true ptPoint1的最近点在ptPoint2的最近点前面, +// false ptPoint1的最近点在ptPoint2的最近点前面. +BOOL IsPrevPoint(int iDPMM,CList &listPoint,CPoint ptPoint1,CPoint ptPoint2); + +//20140504 XQ 以ptPointO原点,将ptExtend拉到ptExtendToPoint时,与ptPointOld对应的拉伸ptPointNew +//该函数同时对弦高和弦长两个方向进行拉伸 +void Extend(CPoint ptPointO,CPoint ptExtend,CPoint ptExtendToPoint,CPoint ptPointOld, CPoint &ptPointNew); + +//以ptPointO原点,将ptExtend拉到ptExtendToPoint时,与listPointOld对应的拉伸listPointNew +//该函数同时对弦高和弦长两个方向进行拉伸 +void Extend(CPoint ptPointO,CPoint ptExtend,CPoint ptExtendToPoint,CList &listPointOld,CList &listPointNew); +//以ptPointO原点,将ptExtend拉到ptExtendToPoint时,与listPointOld对应的拉伸listPointNew +//该函数仅对弦长方向进行拉伸 +void ExtendInWidth(CPoint ptPointO,CPoint ptExtend,CPoint ptExtendToPoint,CList &listPointOld,CList &listPointNew); + +//查找点链listPoint中与ptPoint距离最近的点 +CPoint NearestPoint(CPoint ptPoint,CList &listPoint,int &nDistance); + +//查找点链listPoint1的点与listPoint2的点距离最近的两点 +//输入参数: +// listPoint1 +// listPoint2 +//输出参数: +// ptPoint1 该点在listPoint1上 +// ptPoint2 该点在listPoint2上 +//返回值: +// ptPoint1与ptPoint2的距离 +int NearestPoint(CList &listPoint1,CList &listPoint2,CPoint &ptPoint1,CPoint &ptPoint2); + +//求折线中某一点的垂线ax+by+c=0 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline +// ptPoint +// dMinLength 确定切线的最短距离 +//输出参数: +// a,b,c 直线方程 +BOOL VerticalLineOfPloyline(int iDPMM,CList &listPolyline,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); +BOOL VerticalLineOfPloygon(int iDPMM,CList &listPolygon,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); + +//求折线中某一点的切线ax+by+c=0 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +BOOL TangentOfPloyline(int iDPMM,CList &listPolyline,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); +BOOL TangentOfPloygon(int iDPMM,CList &listPolyline,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); + +//切割时对矩形排序 +//输入参数: +// listRectOld 没有排序的矩形 +// nDistance 排序的冗余大小 +//输出参数: +// listRectNew 排好序的矩形 +void CuttingSort(CList &listRectOld,int nDistance,CList &listRectNew); + +//计算加入一个新点后形成的新矩形 +//输入参数: +// ptPoint 给定的新点 +// nLeft,nTop,nRight,nBottom 旧的矩形 +//输出参数: +// nLeft,nTop,nRight,nBottom 新的矩形 +void GetNewRect(CPoint ptPoint,int &nLeft,int &nTop,int &nRight,int &nBottom); + +//判断点链是否在一直线上 +//输入参数: +// listPoint 点链 +// dMaxError 高度误差 +//返回值: +// true 在一条直线上 +BOOL AllPointAtLine(CList &listPoint,double dMaxError); + +//找水平垂直线 +//如果直线ptPointS_ptPointE与水平垂直线的角度小于dMaxAngle,则计算ptPointE在水平垂直线上的最近距离点ptPointHV +//输入参数: +// ptPointS,ptPointE 直线点 +// dMaxAngle 最大角度误差,单位:度 +//输出参数: +// ptPointHV +//返回值: +// true 在给定的角度误差内有水平垂直线 +BOOL HVLine(CPoint ptPointS,CPoint ptPointE,double dMaxAngle,CPoint &ptPointHV); + +//反求样条曲线的控制点. +//参数: +// iDPMM [输入]长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPoint +// 点链 +// listCtrl +// [输入][输出]控制点链,如果反求控制点成功,那么可以使用该参数有效否则无效 +// dSplineError +// 计算样条曲线时的最大误差 +// dMaxError +// 反求控制点链时的最大误差 +// (bHeadTangent,ptHeadTangent) +// bHeadTangent=TRUE,有前切线点,此时ptHeadTangent有效;bHeadTangent=FALSE,没有前切线点,此时忽略ptHeadTangent的值 +// (bTailTangent,ptTailTangent) +// bTailTangent=TRUE,有后切线点,此时ptTailTangent有效;bTailTangent=FALSE,没有后切线点,此时忽略ptTailTangent的值 +// bNatrual +// =TRUE,自然样条;=FALSE,抛物线样条,20170406 syf,将默认值改为true +// bExactSolution +// =TRUE,求解精确解;=FALSE,如果不能求解精确解,那么尝试放大点阈值求解 +BOOL CalculateSplineCtrlPoint(int iDPMM,CList& listPoint, CList& listCtrl, double dSplineError, double dMaxError, + BOOL bHeadTangent = FALSE,CPoint ptHeadTangent = CPoint(0,0),BOOL bTailTangent = FALSE, + CPoint ptTailTangent = CPoint(0,0),BOOL bNatrual = TRUE, BOOL bExactSolution = TRUE); + +//对每一段等分反求样条曲线的控制点(segment divide) +//参数: +// listPoint +// 点链 +// listCtrl +// [输入][输出]控制点链,如果反求控制点成功,那么可以使用该参数有效否则无效 +// dSplineError +// 计算样条曲线时的最大误差 +// dMaxError +// 反求控制点链时的最大误差 +// (bHeadTangent,ptHeadTangent) +// bHeadTangent=TRUE,有前切线点,此时ptHeadTangent有效;bHeadTangent=FALSE,没有前切线点,此时忽略ptHeadTangent的值 +// (bTailTangent,ptTailTangent) +// bTailTangent=TRUE,有后切线点,此时ptTailTangent有效;bTailTangent=FALSE,没有后切线点,此时忽略ptTailTangent的值 +// bNatrual +// =TRUE,自然样条;=FALSE,抛物线样条,20170406 syf,将默认值改为true +// bExactSolution +// =TRUE,求解精确解;=FALSE,如果不能求解精确解,那么尝试放大点阈值求解 +// dMaxCtrlPointDistance +// 两个控制点间的最大距离 +BOOL CalculateSplineCtrlPoint_SD(CList& listPoint, CList& listCtrl, double dSplineError, double dMaxError, double dMaxCtrlPointDistance, + BOOL bHeadTangent = FALSE,CPoint ptHeadTangent = CPoint(0,0),BOOL bTailTangent = FALSE, + CPoint ptTailTangent = CPoint(0,0),BOOL bNatrual = TRUE, BOOL bExactSolution = TRUE); + +//计算两条链表的距离 +double DistanceOfTwoList(CList& listPoint1, CList& listPoint2); + +//计算一条链表到另一条链表的距离. +double DistanceFromListToList(CList& listPoint1, CList& listPoint2); + +//计算一个点到一条链表的距离. +double DistanceFromPointToList(CPoint point, CList& listPoint); +double DistanceFromPointToList(CPoint point, CPoint* pt, int nArray); + +//计算ptInt在线段ptS→ptE上的参数值 +double PointToParam(CPoint& ptInt, CPoint& ptS, CPoint& ptE); + +//求点一点到一条线段的垂足. +void GetVerticalPoint(CPoint& ptS, CPoint& ptE, CPoint& ptRes, CPoint& ptDes); + +//判断两条线段是否平行 +BOOL IsParallel(CPoint& ptS0, CPoint& ptE0, CPoint& ptS1, CPoint& ptE1); + +//添加一个控制点. +BOOL AddOneCtrlPoint(CList& listPoint, CList& listCtrl); + +//根据控制点分割点链. +void DivideListAccordingToCtrlList(CList& listPoint, CList& listCtrl, CArray,CList >& arrayList); + +//计算给定的元素在链表中的索引值 +//参数: +// type +// 元素 +// listType +// 链表 +//返回值: +// >=0 该元素在链表中,该索引值从0开始 +// =-1 该元素不在链表中 +template +int FindIndex(TYPE type, CList& listType) +{ + POSITION pos; + int iResult, i; + + iResult = -1; + i = 0; + pos = listType.GetHeadPosition(); + while (pos != NULL) + { + if (listType.GetAt(pos) == type) + { + iResult = i; + break; + } + else + { + listType.GetNext(pos); + i++; + } + } + + return iResult; +} + +//计算给定元素在数组中的索引值 +//参数: +// type +// 元素 +// (p,nArray) +// 数组及长度 +//返回值: +// >=0 该元素在数组中,该索引值从0开始 +// =-1 该元素不在数组中 +template +int FindIndex(TYPE type, TYPE* p, int nArray) +{ + int iResult, i; + + ASSERT(p != NULL); + iResult = -1; + for (i = 0; i < nArray; i++) + { + if (p[i] == type) + { + iResult = i; + break; + } + } + + return iResult; +} + +//求一条链表的最大偏移距离. +double MaxDistanceOfList(CList& listPoint, CPoint& point); + +//判断点和多边形的关系 +//输入: +// point 点. +// listPoint 点链. +//输出: +// 无. +//返回值: +// =1,点在多边形内部;=0,点在多边形上;=-1,点在多边形外部. +//说明: +// 此处应保证输入的点链是多边形,即:首尾点相同,面积大于0. +int PointInList(CPoint& point, CList& listPoint); +//判断点和多边形的关系. +//输入: +// point 点. +// pt 多边形数组的首指针. +// nArray 多边形的元素个数. +//输出: +// 无. +//返回值: +// =1,点在多边形内部;=0,点在多边形上;=-1,点在多边形外部. +//说明: +// 数组元素应多于2个. +int PointInList(CPoint& point, CPoint* pt, int nArray); + +//合并链表 +//输入: +// listPoint 链表. +//输出: +// listPoint 链表. +//返回值: +// 无. +//说明: +// 如果连续的3个点共线,那么去掉中间的那一个点. +// 此函数应该保证相邻的点不相同,此函数不作判断. +void ComboSegment(CList& listPoint); + +//在一条线段上查找一个纵坐标为给定值的点的横坐标. +//输入: +// 线段(ptS,ptE) +// dY 给定的纵坐标值. +//输出: +// dX 横坐标.点(dX,dY)一定在线段(ptS,ptE)上. +//返回值: +// 无. +//说明: +// 该函数在判断一点是否在多边形内部(PointInList)时调用,在调用此函数之前已经能够保证 +// 求出的结果点一定是落在线段上,而不是在线段的延长线. +void GetHorizonPoint(CPoint& ptS, CPoint& ptE, double& dY, double& dX); + +//计算外积符号 +//输入: +// 向量ptStart→ptEnd,ptStart→ptTemp +//输出: +// 无. +//返回值: +// = 1逆时针, = 0共线, = -1顺时针 +//说明: +// 此函数返回向量ptStart→ptEnd旋转到ptStart→ptTemp是顺时针还是逆时针. +// 如果逆时针旋转是大于180度,那说明是顺时针的. +// 此结果是基于世界坐标系,在屏幕坐标系中结果要取相反的符号. +// 此结果只返回外积的符号,外积在数值上等于这三个点形成三角形的面积的2倍,此面积为有向面积. +int CrossProduct(CPoint& ptStart, CPoint& ptEnd, CPoint& ptTemp); + +//由给定参数,计算线上的一个点. +//输入: +// 线段(ptS, ptE),有方向,原则上首尾点不相同. +// dParam 参数值.计算线上该参数值对应的点. +//输出: 无. +//返回值: +// CPoint点. +//说明: +// 此函数一定会有返回值,当输入的线段首位点相同的时候,直接返回头点坐标. +CPoint ParamToPoint(CPoint ptS, CPoint ptE, double dParam); + +//两多边形是否重叠 +BOOL IsOverlapOfTwoPolygon(CList &listPolygon1,CList &listPolygon2); + +//将一条点链生成一个数组. +//输入: +// listPoint 点链. +//输出: +// pt 数组头指针. +// nListCount 数组元素数目. +//返回值: +// =TRUE,操作成功.=FALSE,操作失败. +//说明: 无. +BOOL MallocFromList(CList &listPoint, CPoint *&pt, int &nListCount); + +//获取两点的中点. +//输入: +// ptS,ptE 两个点. +//输出: +// ptMiddle 中点. +//返回值: 无. +//说明: +// 调用此函数时,输出变量可以与某个输入变量相同. +void GetMiddlePoint(CPoint ptS, CPoint ptE, CPoint &ptMiddle); + +//计算点链的有向面积 +//特别说明: +// 此面积为有向面积,>0 点链为逆时针(在屏幕上看为顺时针) +//输入参数: +// listPoint 点链 +//返回值: +// 面积 +double Area(CList& listPoint); + +//根据给定长度延长(缩短)一条线段. +//输入: +// (ptS,ptE) 有向线段. +// dLen 给定的线段长度. +//输出: +// ptExtend 延长(缩短)后的线段尾点. +//返回值: 无. +//说明: +// 调用此函数时ptE与ptExtend可以是同一个变量. +// 计算完成时(ptS,ptExtend)的长度为给定长度. +void ExtendSegment(CPoint &ptS, CPoint &ptE, double dLen, CPoint &ptExtend); + +//计算两线段的交点. +//输入: +// 线段(ptS0,ptE0),(ptS1,ptE1) +//输出: +// ptInt 交点. +//返回值: +// 无. +//说明: +// 每条段的两端都都不应相同. +// 两条线段不应平行,此函数不作判断. +// 交点未必落在线段上.此为两线段所在直接的交点. +void IntPoint(CPoint& ptS0, CPoint& ptE0, CPoint& ptS1, CPoint& ptE1, CPoint& ptInt); + +//计算两条向量夹角的余弦值和正弦值. +//输入: +// (ptS0,ptE0),(ptS1,ptE1) 两条向量. +//输出: +// dCos 夹角的余弦值. +// dSin 夹角的正弦值. +//返回值: +// =TRUE,成功计算.=FALSE,计算失败. +//说明: +// 只有当向量的两个端点退化成同一个点的时候才会计算失败. +// 此夹角是在世界坐标系下计算的. +BOOL RotateAngle(CPoint &ptS0, CPoint &ptE0, CPoint &ptS1, CPoint &ptE1, double &dCos, double &dSin); + +//在给定的点链上找到距离给定点最近的点. +//输入: +// listPoint 点链. +// point 给定的点. +//输出: +// ptNearest 最近点.一定在折线上. +// dLen 最短的距离. +//返回值: +// TRUE,找到了这个最近点.FALSE,没有找到这个最近点.此时不可以使用输出变量. +//说明: +// 调用此函数时,输入变量和输出变量可以相同. +BOOL GetNearestPointOnList(CList &listPoint, CPoint &point, CPoint &ptNearest, double &dMinLen); + +//将源点链数组添加到目标点链数组的尾部. +//输入: +// alRsc 源点链数组. +//输出: +// alDes 目标点链数组. +//返回值: 无. +//说明: 无. +void AddArrayListTail(CArray,CList >& alRsc, CArray,CList >& alDes); + +//计算平行的线段. +//参数: +// (ptS,ptE) +// 线段.一般来说这2个点不能相同. +// (dStartHeight,dEndHeight) +// 两个点各自的平行距离.本函数使用其绝对值,输入时每个长度都可以是0,这两个数值可以不同. +// bClockwise +// 旋转方向.=TRUE,顺时针;=FALSE,逆时针.注意:此处的顺时针是在"世界坐标系"下,与屏幕坐标系方向相反. +// (ptParallelS,ptParallelE) +// [输出]平行之后的两个端点. +//说明: +// 调用本函数时输入变量与输出变量一定要两两不同. +void ParallelSegment(CPoint ptS, CPoint ptE, double dStartHeight, double dEndHeight, BOOL bClockwise, CPoint& ptParallelS, CPoint& ptParallelE); + +//计算平行曲线. +//参数: +// listPoint +// 点链. +// (dHeadHeight,dTailHeight) +// 头点和尾点处的距离.本函数使用其绝对值,并且这两个值可以不相同. +// bClockwise +// 方向.平行后的线在原线的哪一侧.=TRUE,顺时针;=FALSE,逆时针.注意:此处的顺时针是在"世界坐标系"下,与屏幕坐标系方向相反. +// listParallel +// [输出]平行之后的曲线. +// dMaxError +// 误差.判断输入的曲线是否为闭合的.如果判断出输入的曲线是闭合,那么将其按照多边形的情况来处理, +// 所以在处理多边形的时候要将其转化成点链传入. +// bRemoveIntersect +// =true 去自交,=false 不去自交 +//说明: +// 在调用本函数的时候,输入变量与输出变量可以相同. +void ParalllelCurve(CList& listPoint, double dHeadHeight, double dTailHeight, BOOL bClockwise, CList& listParallel, double dMaxError = 0.0, BOOL bRemoveIntersect = TRUE); + +//去除自交的折线. +//参数: +// listPoint +// [输入][输出]点链. +// bClose +// 标识点链是否为闭合的. +//说明: +// 如果是闭合的情形,那么按照多边形来求解,选择面积最大的那个.如果是折线的情形,那么则从头点到尾点的方向进行查找. +void RemoveIntersectPolyline(CList& listPoint, BOOL bClose); + +//获取边界内部的点链. +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPoint +// 点链. +// listBorder +// 边界.头尾点相同也可以,不相同也可以. +// arrayList +// [输出]点链数组.可能有多条曲线,因为输入的点链可能被分割成了多条. +void GetListInBorder(int iDPMM,CList& listPoint, CList& listBorder, CArray,CList >& arrayList); + +//计算等比例的控制点链 +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// (listPoint1,listCtrl1) +// 实际点链以及相对应的控制点链 +// listPoint2 +// 实际点链 +// listCtrl2 +// [输出]listPoint2对应的控制点链,其中的数目与listCtrl1相同,并且其中每个点的位置都是通过点在曲线上的比例来求得的 +void GetProportionCtrlList(int iDPMM,CList& listPoint1, CList& listCtrl1, CList& listPoint2, CList& listCtrl2); + +//从timeStart到timeFinish的时间差 +//输入参数: +// iMillisecondsStart 开始的毫秒数 +// iMillisecondsFinish 结束的毫秒数 +//返回值: +// 持续时间,单位:秒 +double Duration(int iMillisecondsStart,int iMillisecondsFinish); + +//查找给定的点链距离数组中的哪条曲线最近 +//参数: +// listPoint +// 点链,要保证该点链就是从数组中的某条曲线中提取出来的 +// alCurve +// 点链数组 +int FindListIndex(CList& listPoint, CArray,CList >& alCurve); + +//计算垂足在线段上的参数值 +//参数: +// (ptS,ptE) +// 线段,要求这两个点不相同,否则直接返回DBL_MAX +// point +// 点 +//返回值: +// 参数值,若[0,1]则在线段内部 +double GetVerticalParam(CPoint ptS, CPoint ptE, CPoint point); + +//根据给定的虚线长度与间距,定制虚线 +//参数: +// iDPMM +// 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listCurve +// 点链 +// (iDashedLength,iSpaceLength) +// 虚线长度(每一段可见部分的长度),间隙长度(每一段不可见部分的长度),使用其绝对值 +// alCurve +// [输出]点链数组,按照从头到尾的顺序,分段保存可见部分的点链 +void CustomizeDashedLine(int iDPMM, CList& listCurve, int iDashedLength, int iSpaceLength, CArray,CList >& alCurve); + +//计算渐变的自定义虚线 +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listCurve 点链 +// iDashedLength 画线长度 +// iSpaceLength 空白长度 +// iDashGradualType 画线长度的渐变类型, =0 无, =1 长度渐变, =2比例渐变 +// iDashGradualLength 画线长度的渐变长度,即:前一段的画线长度加上该值等于后一段的画线长度 +// dDashGradualScale 画线长度的渐变比例,即:前一段的画线长度乘以该值等于后一段的画线长度 +// iSpaceGradualType 空白长度的渐变类型, =0 无, =1 长度渐变, =2 比例渐变 +// iSpaceGradualLength 空白长度的渐变长度,即:前一段的空白长度加上该值等于后一段的空白长度 +// dSpaceGradualScale 空白长度的渐变比例,即:前一段的空白长度乘以该值等于后一段的空白长度 +// bAdaptiveStretch =TRUE 自适应拉伸, =FALSE 不拉伸 +// alCurve [输出]点链数组,按照从头到尾的顺序,分段保存可见部分的点链 +void CustomizeGradualDashedLine(int iDPMM, CList& listCurve, int iDashedLength, int iSpaceLength, + int iDashGradualType, int iDashGradualLength, double dDashGradualScale, + int iSpaceGradualType, int iSpaceGradualLength, double dSpaceGradualScale, + BOOL bAdaptiveStretch, CArray,CList >& alCurve); + +//根据给定的曲线,半径,间距计算圆形曲线 +//参数: +// listCurve +// 点链 +// (iRadius,iSpaceLength,dMaxError) +// 半径,圆心距(线上距离),计算圆形的最大逼近误差,若某一个值为0则输出变量为空 +// alPolygon +// [输出]多边形数组,按照从头到尾的顺序,分段保存圆形实际位置 +void CustomizeCircleCurve(CList& listCurve, int iRadius, int iSpaceLength, double dMaxError, CArray,CList >& alPolygon); + +//计算自定义曲线(开口线或者闭合线) +//输入: +// listCurve 开口线 +// alCustomCurveElement 自定义曲线元素 +// bClose =TRUE 闭合线, =FALSE 开口线 +// ptCustomBasePoint 基准点 +// iCustomCurveHeight 高度,若<=0则使用alCustomCurveElement本身的高度 +// iCustomCurveGap 相邻元素的间隔,若<0,则不能超过alCustomCurveElement本身的宽度 +// bAdaptiveStretch =TRUE 自定义拉伸(等比例改变元素的宽度和高度,使得曲线的结束恰好是一个元素的结束), =FALSE 不拉伸(只保留整数部分的元素) +//输出: +// alCurve 计算出的点链 +void CustomizeCurve(CList& listCurve, BOOL bClose, CArray,CList >& alCustomCurveElement, CPoint ptCustomBasePoint, + int iCustomCurveHeight, int iCustomCurveGap, BOOL bAdaptiveStretch, CArray,CList >& alCurve); + +//计算给定点链的最小矩形 +//输入参数: +// listPoint 点链 +//返回值: +// 点链的最小矩形 +//说明: +// 将点链进行旋转求出面积最小矩形,箱包系统中计算纸样规格时即为此种方式 +CRect GetBorderMinRect(CList &listPoint); + +//计算省山并修改边线形状 +//参数: +// listPoint1E,listPoint3E +// [输入]对应于V形省的1E边和3E边,如果是计算锥形省,则对应于14边和35边,计算褶山时也是同样的道理 +// 传入时要求这两条点链的头点是靠近边线的,否则需要将点链翻转,本函数不再判断 +// 同时,还要保证在边线上1->3点长度小于3->1点长度,本函数不再判断 +// [输出]如果计算成功,则根据它们的头点在边线上的最近点,将点链拉伸,并保证头点的坐标一定在边线中 +// listPoint2E +// 两条省腰的中心线,将使用该线头点的切线将对称后的省山截断,若该链表为空,那么将会使用两条省腰中间的直线做截取 +// listBorder +// [输入][输出]边线的实际点链,要求头尾点相同;输出时已经将省山的形状添加进去 +// bClockwise +// =TRUE 顺时针倒向(视觉上的顺时针),即倒向GetNext +// dMaxError +// 判断1点和3点是否在边线上的误差值,如果省腰长度小于该值同样返回FALSE +// ptDartHill +// [输出]省山的尖点位置,计算完成后省山被插入到边线中,但是不知道省山尖点的坐标,将其输出后可以修改褶中心线的形状(因为刀褶也是调用此函数计算褶山的) +BOOL CalculateDartHill(int iDPMM, CList& listPoint1E, CList& listPoint3E, CList& listPoint2E, CList& listBorder, BOOL bClockwise, double dMaxError, CPoint& ptDartHill); + +//计算工字褶褶山并修改边线形状 +//特别说明: +// 刀褶褶山的计算与省相同,调用CalculateDartHill函数即可,本函数按照工字褶的规则计算 +//参数: +// 详见CalculateDartHill函数的变量说明,注意:工字褶不涉及倒向 +BOOL CalculatePleatHill(int iDPMM, CList& listPoint12, CList& listPoint34, CList& listBorder, double dMaxError); + +//获得沿直线 p0p1方向,到p0距离为 dDistance 的点 +CPoint GetPointOnLine(CPoint p0,CPoint p1,double dDistance); + + +//20170222 获取两条曲线的交点 +//[输入] listPoint1,listPoint2 两条点链 +//[输出] ptInt交点 +//[输入] iIntIndex 交点索引, -1返回 GetIntPointOfTwoCurve( int iDPMM, CList& listPoint1, CList& listPoint2, CPoint& ptInt, int iCount)结果 +// 0, 1,2...求出listPoint1,listPoint2的所有交点(本身相交,延长相交),并且按照listPoint1的点连顺序排序, 按照排序顺序输出交点 +//[输入]iCount 迭代的次数,当迭代一次之后就不能再进行迭代了 +//返回值: +// =TRUE 成功求解出了交点 +// =FALSE 求解交点失败,不能使用输出变量中的数据 +//说明: +// 该函数是针对两个不同的平行交点,它们引用的两条曲线相同但是交点不同,新增加的函数 +// iIntIndex为-1表示保持原有的结果;为0, 1,2...时表示需要求所有交点排序输出 +BOOL GetIntPointOfTwoCurve( int iDPMM, CList& listPoint1, CList& listPoint2, CPoint& ptInt, int iIntIndex, int iCount); + +//20170222 获取两条曲线的交点(相交的, 延长相交的),并按照listPoint1排序 +//[输入] listPoint1,listPoint2 两条点链 +//[输出] listInt 两条点链所有的交点,交点按照listPoint1排序 +//返回值: +// =TRUE 成功求解出了交点 +// =FALSE 求解交点失败,不能使用输出变量中的数据 +//说明: +//该函数中分三种情况处理 +//1. listPoint1/listPoint2都是非闭合曲线,如果两线有交点,先求出交点,再按两条曲线头尾点分别延长 +//2. listPoint1/listPoint2一条非闭合,一条闭合; 先求两条线交点,再求非闭合线的延长线与闭合线交点 +//3. listPoint1/listPoint2都是闭合曲线,直接求两线有交点返回 +BOOL GetIntPointOfTwoCurve_All( int iDPMM, CList& listPoint1, CList& listPoint2, CList& listInt); + +//20130717 获取两条曲线的交点 +//[输入] listPoint1,listPoint2 两条点链 +//[输出] ptInt交点 +//[输入]iCount 迭代的次数,当迭代一次之后就不能再进行迭代了 +//返回值: +// =TRUE 成功求解出了交点 +// =FALSE 求解交点失败,不能使用输出变量中的数据 +//说明: +// 包含延长相交 +BOOL GetIntPointOfTwoCurve(int iDPMM, CList& listPoint1, CList& listPoint2, CPoint& ptInt, int iCount); + + +//20130717 求解延长后的交点 +//[输入] ptStart,ptEnd 向量,有方向 +//[输入] listPoint 点链,在这条点链上求解交点,如果没有则尝试延长头尾点来进行 +//[输出] ptInt 交点坐标,如果有多个交点那么只输入其中的任意一个 +//返回值: +// =TRUE 求解成功,可以使用输出变量中的数据 +// =FALSE 求解失败,不能使用输出变量中的数据 +BOOL GetExtendInt(int iDPMM, CPoint ptStart, CPoint ptEnd, CList& listPoint, CPoint& ptInt); + +//20170223求解延长后的交点 +//[输入] ptStart,ptEnd 向量,有方向 +//[输入] listPoint 点链,在这条点链上求解交点,如果没有则尝试延长头尾点来进行 +//[输出] listInt 交点坐标 +//返回值: +// =TRUE 求解成功,可以使用输出变量中的数据 +// =FALSE 求解失败,不能使用输出变量中的数据 +BOOL GetExtendInt(int iDPMM, CPoint ptStart, CPoint ptEnd, CList& listPoint, CList& listInt); + +//20130718 根据给定两点在给定的曲线上截取一段 20140427 增加一个输出值 +//[输入]ptPointS, ptPointE 截取曲线的头尾点 +//[输入][输出]listPoint 输入:原始曲线;输出:截取之后的曲线 +//[输出] listPointMax 最长点链 +//说明: +// ptPointS点可能为截取后的曲线的头点或者尾点 +//如果ptPointS和ptPointE相等返回原曲线 +//如果ptPointS或者ptPointE只有一个不在曲线上,根据在曲线上的将曲线分成两段,按另外一个点与曲线头尾点距离(按距离小的)得到需要段 +//如果ptPointS和ptPointE都不在曲线上,按加入点链处理 +//如果ptPointS和ptPointE都不在曲线上并且在曲线的同边,返回点链只有ptPointS和ptPointE两点 +//最长点链的计算listPointMax +//如果ptPointS, ptPointE都在点链上,返回listPoint; +//如果有一个在点链上,返回:listPoint加上那个不在点链上的点 +//如果两个都不在点链上, 两个在点链的异侧,返回:将两个点加到listPoint头尾,返回 +// 两个在点链的异侧,将两个点同时加入头部或者尾部,返回 +void GetCurveSegment(int iDPMM, CPoint ptPointS, CPoint ptPointE, CList& listPoint, CList& listPointMax); + +//20130815 XQ 计算展开的终点 +//参数: +// (ptUp,ptDown) +// 展开前的起止点 +// (iUpWidth,iDownWidth) +// 上下展开量,使用其绝对值,任何一个宽度都可以为0 +// bClockWise +// =TRUE,顺时针旋转;=FALSE,逆时针旋转.此旋转为世界坐标系下,与屏幕坐标系的方向相反 +// (ptSpreadUp,ptSpreadDown) +// [输出]展开后的起止点,调用本函数的时候这两个参数一定不能与输入的(ptUp,ptDown)使用相同的变量 +void CalculateSpreadEndPoint(CPoint ptUp, CPoint ptDown, int iUpWidth, int iDownWidth, BOOL bClockWise, CPoint& ptSpreadUp, CPoint& ptSpreadDown); + +//判断给定点是否在点链内(给定点是否在点链的某一线段上) +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// ptPoint 给定的点 +// listPoint 给定点链 +//返回值: +// =TRUE 点在点链内 +BOOL PointInPolyline(int iDPMM, CPoint ptPoint, CList& listPoint); + + +//20160718 XQ 根据listRefPoint对listSortPoint排序 +//[输入] iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +//[输入] listRefPoint 参考点链 +//[输入][输出] listSortPoint 需要排序的点链 +//说明: +// 将listSortPoint中的点链按照listRefPoint的顺序排放,listSortPoint的点可能不在listRefPoint上 +void SortIntPoint(int iDPMM, CList &listRefPoint, CList &listSortPoint); + +//交换两个TYPE +template +void Swap(TYPE& p1, TYPE& p2) +{ + TYPE p3; + + p3 = p1; + p1 = p2; + p2 = p3; +} + +//交换两条链表 +template +void Swap(CList& list1, CList& list2) +{ + CList list3; + + list3.RemoveAll(); + list3.AddTail(&list1); + list1.RemoveAll(); + list1.AddTail(&list2); + list2.RemoveAll(); + list2.AddTail(&list3); +} + +//设置数组值 +// [输入] Value 设置值 +// [输入][输出] arrayValue 数组 +// [输入] iCount 数据大小 +// 说明: +// 将数组中的每个值都设置位给定值 +template +void SetSameValue(TYPE Value, CArray &arrayValue, int iCount) +{ + int iIndex; + + arrayValue.RemoveAll(); + arrayValue.SetSize(iCount); + for (iIndex = 0; iIndex < iCount; iIndex++) + { + arrayValue[iIndex] = Value; + } +} +//判断数组中每个值是否都相等 +// [输入] arryValue 数组 +//返回值: +// =true 数组中每个值都相等; +// =false 至少存在一个值不相等 +//说明: +// 数组为空时返回False, 数组只有一个值返回True +template +BOOL IsSameValue(CArray &arryValue) +{ + BOOL bEqual; + int iIndex, iCount; + TYPE Value; + + bEqual = TRUE; + iCount = arryValue.GetSize(); + if (iCount == 0) + { + return FALSE; + } + if (iCount == 1) + { + return TRUE; + } + + Value = arryValue[0]; + for (iIndex = 1; (iIndex < iCount) && bEqual; iIndex++) + { + if (Value != arryValue[iIndex]) + { + bEqual = FALSE; + } + } + + return bEqual; +} + +//判断两个数组是否完全相等 +// [输入] arryValue1 数组 +// [输入] arryValue2 数组 +//返回值: +// =true 两个数组中对应的每个值都相等; +// =false 至少存在一个值不相等 +template +BOOL IsSameValue(CArray &arryValue1, CArray &arryValue2) +{ + BOOL bEqual; + int iIndex, iCount; + + bEqual = TRUE; + if (arryValue1.GetSize() != arryValue2.GetSize()) + { + return FALSE; + } + iCount = arryValue1.GetSize(); + if (iCount == 0) + { + return TRUE; + } + + for (iIndex = 0; (iIndex < iCount) && bEqual; iIndex++) + { + if (arryValue1[iIndex] != arryValue2[iIndex]) + { + bEqual = FALSE; + } + } + + return bEqual; +} +//拷贝数据,将原数组中数据拷贝到目标数组中 +// [输入] arryValueSrc 原数组 +// [输入][输出] arryValueDes 目标数组 +template +void CopyData(CArray &arryValueSrc, CArray &arryValueDes) +{ + int iIndex, iCount; + + arryValueDes.RemoveAll(); + iCount = arryValueSrc.GetSize(); + for (iIndex = 0; iIndex < iCount; iIndex++) + { + arryValueDes.Add(arryValueSrc[iIndex]); + } +} + +//在给定的数据中找一个最大值 +// [输入] arryValue 数组 +//返回值: +// 数组中最大值,如果数组中没有值返回0 +template +TYPE FindMaxCount(CArray &arryValue) +{ + int iIndex, iCount; + TYPE MaxValue; + + iCount = arryValue.GetSize(); + if (iCount == 0) + { + return 0; + } + MaxValue = arryValue[0]; + for (iIndex = 1; iIndex < iCount; iIndex++) + { + if (MaxValue < arryValue[iIndex]) + { + MaxValue = arryValue[iIndex]; + } + } + + return MaxValue; +} + +#endif diff --git a/datafile/dxf/dxflib/PDSMath/3BSpline.h b/datafile/dxf/dxflib/PDSMath/3BSpline.h new file mode 100644 index 0000000..a32bee6 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/3BSpline.h @@ -0,0 +1,439 @@ +///////////////////////////////////////////////////////////////////////////// +// +// 3BSpline.h - the class of B Spline +// +// 三次B样条曲线类 +// +///////////////////////////////////////////////////////////////////////////// + +#if !defined(_BSPLINE_H) +#define _BSPLINE_H + +#include +#include "Point3D.h" + +class C3BSpline; + +typedef class C3BSpline * LP3BSpline; + +class C3BSpline : public CObject +{ + // Attribute +private: + CArray m_arrayControlPoints; //Array of Control Points,控制点数组 + CArray m_arrayWeight; //Array of Weight 权重数组 + UINT m_nControlPointsCount; //Number of Control Points Array (also of Weight Array)控制点数组(权重数组)数目 + + CArray 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 m_arrayDisplayPoints; //Value Points to Display 需显示的取值点 + CArray m_arrayCurrentParameter; //Parameter Array of Display Points 显示点参数数组 + CArray 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 m_arrayInputPoints; //Input Points (may be Control Points or Value Points) + CArray 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 diff --git a/datafile/dxf/dxflib/PDSMath/PDSAlgorithm.h b/datafile/dxf/dxflib/PDSMath/PDSAlgorithm.h new file mode 100644 index 0000000..155913d --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSAlgorithm.h @@ -0,0 +1,196 @@ +/******************************************************************** + 创建日期: 2011年12月22日<13:51:21> + 文件名称: PDSAlgorithm.h + 原始作者: 孙宇飞 + 文件描述: 该文件中提供算法类的函数 + 所有的函数都将使用输入,输出变量完成数据交换,一定不使用全局变量中的数据 + 各函数的变量说明一定要明确,尤其是与数学库中功能相似又有区别的函数,一定要将区别写清楚 + + 修改记录: + 版本号码 修改日期 作者 修改内容 +*********************************************************************/ +#ifndef PDSALGORITHM_H +#define PDSALGORITHM_H + +#include + +//线段 +// 该类将会在计算最大多边形的过程中使用,每一条点链都会记录所在曲线的索引值和方向 +class CPDSSegment : public CObject +{ +public: + CList 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& 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 CPDSSegmentList; + +class CPDSSegmentList : public CList +{ +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 >& alCurve, CPDSSegmentList& listSegment); + +//计算切割区域 +//特别说明: +// 在切割模板的时候,众多的开槽线纵横交错,需要把它们形成的最大多边形找到,直接将中间部分镂空即可,既加快速度又延长激光寿命; +// 切角半径的作用是避免从一条模板切割到另一条模板时形成尖锐的夹角; +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// alCurve 点链数组,输入时要保证每条点链至少有2个点,如果是多边形还要求首尾点相同,并且相邻的点坐标不同 +// iRadius 切角半径,若=0表示不切角 +// dMaxError 计算圆弧时的拟合误差 +// alCutting [输出]点链数组,其中的每一条点链都是被切割的轨迹 +//返回值: +// alCutting.GetSize() +int CalculateCuttingRegion(int iDPMM, CArray,CList >& alCurve, int iRadius, double dMaxError, CArray,CList >& 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& 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& listPoint1, CList& listPoint2, int iRadius, double dMaxError, CList& 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& listCurve, CPoint ptFrom, BOOL bTangentPrev, double dLength, CPoint& ptFixPoint, CPoint& ptTangent); + +#endif //PDSALGORITHM_H \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/PDSBezier.h b/datafile/dxf/dxflib/PDSMath/PDSBezier.h new file mode 100644 index 0000000..f139969 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSBezier.h @@ -0,0 +1,139 @@ +/******************************************************************** +创建日期:2017年9月11日 +文 件 名:PDSBezier.h +原始作者:孙宇飞 +描 述:二次或者三次Bezier曲线 + +修改记录: + 版本号 修改日期 作者 修改内容 +*********************************************************************/ +#ifndef _PDS_BEZIER_H_ +#define _PDS_BEZIER_H_ + +#include +#include +#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 +{ +public: //扩展的变量 +public: //扩展的方法 + + CPDSBezierPointList& operator=(CPDSBezierPointList& rhs); //赋值 + CPDSBezierPoint& operator[](int iIndex); //根据索引值检索,不可越界 + + //根据listPoint设置this + void SetPoint(CList& listPoint); + + //将this的数据输出至listPoint + void GetPoint(CList& 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_ \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/PDSFormula.h b/datafile/dxf/dxflib/PDSMath/PDSFormula.h new file mode 100644 index 0000000..a5da787 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSFormula.h @@ -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保持一致,如此再计算3项2项1项0项常量的情况 + (3)公式中区分m_listLengthVariableName与m_listAngleVariableName,前者代表长度,后者代表角度,即常量,设置时一定要将不同类型的人体尺寸/尺寸变量字符串写入到相应的链表中 + (4)所有的成员变量都是public类型,方便获取数据,要按照上述的使用方法进行操作,没有列出的函数/变量不可设置 + +修改记录: + 版本号 修改日期 作者 修改内容 +*********************************************************************/ +#ifndef PDSFORMULA_H +#define PDSFORMULA_H + +#include +#include + +//将函数操作符作为单目运算符,运算级别在括号之后 +#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,详见<> + int m_iPrecision; //单位精度,用于转换成字符串时使用,默认-1,详见<> + + 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 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 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 >& 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 \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/PDSLocate.h b/datafile/dxf/dxflib/PDSMath/PDSLocate.h new file mode 100644 index 0000000..36f46cc --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSLocate.h @@ -0,0 +1,236 @@ +// PDSLocate.h + +#if !defined(PDSLocate_h) +#define PDSLocate_h + +#include +#include + +#define PDSLOCATE_SAMEPOINTERROR 5.0; // 判断两个点相等的最大误差值,<=该值的点认为是同一个 + +//查找点的位置 +//输入参数: +// listPoint 点链 +// ptPoint 给定的点 +//返回值: +// 在listPoint中与ptPoint坐标相同的点的位置, +// 如listPoint中没有与ptPoint的坐标相同的点则返回NULL. +POSITION FindPointAtPointList(CList& listPoint,CPoint ptPoint); +//查找点的位置 +//输入参数: +// listPoint 点链 +// ptPoint 给定的点 +// dMaxError 最大误差,若<0则根据CONST_SAME_POINT_ERROR进行查找 +//返回值: +// 在listPoint中与ptPoint的距离小于dMaxError的最近点的位置, +// 如listPoint中没有与ptPoint的距离小于dMaxError的点则返回NULL. +POSITION FindPointAtPointList(CList& 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& 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& 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& 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& 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& 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& 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& listPolyline,CPoint ptPointS,double dDistance,CPoint& ptPoint); +BOOL GetDistancePointOfPolyline(CList& 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& 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& 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& listPolyline,double dDistance,CPoint& ptPoint,POSITION &posPrev,POSITION &pos,POSITION &posNext); + +//确定一点在线上的位置. +//特别说明:该函数不检查点是否在线上!!! +//输入参数: +// listPoint 已有的点 +// ptPoint 需确定的点 +//输出参数: +// pos ptPoint的插入位置 +//返回值: +// ptPoint的插入序号 +int InsertPointAtLine(CList &listPoint,CPoint ptPoint,POSITION &pos); + +//计算切线点 +//输入参数: +// listPolygon +// ptPointS +// dDistance >=0 计算从ptPointS开始往后最短距离dDistance的切线点, +// <0 计算从ptPointS开始往前最短距离-dDistance的切线点. +//输出参数: +// ptPoint +//返回值: +// =true 成功计算出切线点,否则false +BOOL GetTangentPointOfPolygon(CList& listPolygon,CPoint ptPointS,double dDistance,CPoint& ptPoint); +//计算切线点 +//输入参数: +// listPolyline +// ptPointS +// dDistance >=0 计算从ptPointS开始往后最短距离dDistance的切线点, +// <0 计算从ptPointS开始往前最短距离-dDistance的切线点. +//输出参数: +// ptPoint +//返回值: +// =true 成功计算出切线点,否则false +BOOL GetTangentPointOfPolyline(CList& listPolyline,CPoint ptPointS,double dDistance,CPoint& ptPoint); + +#endif diff --git a/datafile/dxf/dxflib/PDSMath/PDSMath.h b/datafile/dxf/dxflib/PDSMath/PDSMath.h new file mode 100644 index 0000000..f68b340 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSMath.h @@ -0,0 +1,2705 @@ +// PDSMath.h + +#if !defined(PDSMath_h) +#define PDSMath_h + +#include +#include +#include + +#define CONST_PI 3.14159265359 +#define DBL_MIN 2.2250738585072014e-308 +#define DBL_MAX 1.7976931348623158e+308 + +#define RPG_PT_GNCP 0 //端点(放码非弧线点) +#define RPG_PT_NGCP 1 //不放码弧线点 +#define RPG_PT_NGNCP 2 //直线点(不放码非弧线点) +#define RPG_PT_GCP 3 //放码弧线点 +#define RPG_PT_GP 64 //放码值 +#define RPG_PT_INSPT 100 //插值点 +#define RPG_PT_SEAM 128 //份缝点 +#define RPG_PT_NODEF -1 //无定义点 + +#define CONST_MAXDISTANCE 0.05 //对于不在线上的点,默认在线上有对应点的最大距离,单位:mm. 考虑到旧系统中的分辨率为40,所以最小取值0.05mm +#define F_MAX_TANGENT_ERROR 0.1 //20131015 计算切线时的检索长度,单位:mm + +#define CONST_SAME_POINT_ERROR 5 // 判断了两个点相等的最大误差值,系统内部单位,距离<=该值的点认为是同一个 + // [20170830 syf]由于使用数据结构支持公式法,导致点链上的点可能相差1个或者2个内部单位,于是增加该宏定义判断相同的两个点 + // 如果相邻点的非常靠近,这种情况经常发生在边线,将会导致计算后的角平分线出错, + // 所以在边线上获取某点处的前后点时,一定要跨过非常靠近的点 + +//带点类型的点,该类对点的类型没有指定其意义,使用者可根据自己的要求来使用 +class CTypePoint : public CObject +{ +public: + CPoint m_ptPoint; + int m_iType; + + CTypePoint(); + CTypePoint(CTypePoint &a); + CTypePoint(CPoint ptPoint,int iType); + ~CTypePoint(); + void operator=(const CTypePoint &a); + BOOL operator==(CTypePoint& a); + BOOL operator!=(CTypePoint& a); +}; + +class CTypePointListArray; // 声明 + +//带类型的点的链表 +class CTypePointList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CTypePointList& operator=(CTypePointList& rhs); //赋值 + BOOL operator==(CTypePointList& rhs); //等号 + BOOL operator!=(CTypePointList& rhs); //不等号 + CTypePoint& operator[](int iIndex); //根据索引值检索,不可越界 + + //以下查找都是从Head->GetNext->Tail遍历,遇到第一个满足条件者即返回 + + //查找给定点在链表中的索引值 + int FindIndexOfTypePoint(CTypePoint TypePoint); + + //查找给定点在链表中位置 + POSITION FindPositionOfPoint(CPoint ptPoint); + + //查找给定点在链表中的索引值 + int FindIndexOfPoint(CPoint ptPoint); + + //查找给定类型在链表中的位置 + POSITION FindPositionOfType(int iType); + + //查找给定类型在链表中的索引值 + int FindIndexOfType(int iType); + + //根据给定的类型与点链设置this + //特别说明: + // 设置完成后,this的长度等于listPoint,每个点一一对应,并且this的每一项的类型等于iType + void SetTypePointList(int iType, CList& listPoint); + + //将this中的点链提取至listPoint + void ExtractPointList(CList& listPoint); + + //将listPoint设置到this的m_ptPoint中 + void SetOnlyPointList(CList& listPoint); + + //根据指定的类型将this分段 + //特别说明: + // (1)应用举例,该函数可应用于根据放码点将控制点分段,iType实际上表示bGrade + // (2)alTypePoint[]至少有两个点,本函数会保证这一点 + // (3)bClose=true,那么至少要保证链表中有两个点等于iType,否则alTypePoint只有一条链表,并且等于this + //输入参数: + // bClose =true 闭合,头尾点不能相等,本函数不做判断,=false 开口 + // iType 类型 + //输出参数: + // alTypePoint 数组,遇到iType的点就要作为该段结束 + void DivideTypePointListEqualType(BOOL bClose, int iType, CTypePointListArray& alTypePoint); + + //只要类型不等于0就进行分段 + //特别说明: + // (1)应用举例,该函数可应用于根据缝份数据将实际的分段,m_iType实际上表示缝份数据的指针 + // (2)这样分段过后,每一段的头点与尾点带有缝份数据,而中间的点没有缝份数据,从而对整段计算缝份 + // (3)alTypePoint[]至少有两个点,本函数会保证这一点 + // (4)bClose=true,那么至少要保证链表中有两个点m_iType不为0,否则alTypePoint只有一条链表,并且等于this + //输入参数: + // bClose =true 闭合,头尾点不能相等,本函数不做判断,=false 开口 + //输出参数: + // alTypePoint 数组,如果bClose=true,那么每段的头点与尾点的m_iType都不为0 + void DivideTypePointListWhenTypeNoZero(BOOL bClose, CTypePointListArray& alTypePoint); + + //根据m_iType的数值排序 + //特别说明: + // (1)应用举例,m_ptPoint表示交点,m_iType表示该交点与曲线头点的距离(线上长度),那么,Sort之后的交点就是有序的 + //输入参数: + // bSmallToLarge =true 从小到大,=false 从大到小 + void SortByType(BOOL bSmallToLarge = TRUE); + + void MakeReverse(); //将this反向 + + POSITION FindPositionOfSmallestType(void); //查找m_iType最小的那个元素的位置 + int FindIndexOfSmallestType(void); // 查找m_iType最小的那个元素的索引值 + + POSITION FindPositionOfLargestType(void); //查找m_iType最大的那个元素的位置 + int FindIndexOfLargestType(void); // 查找m_iType最大的那个元素的索引值 + + //在折线插入点 + //输入参数: + // ptPoint 给定点 + // dMaxError 判断点在线上的最大误差值 + // iInsertType 插入点时的m_iType值 + //返回值: + // =true 给定点在this中(输入时已经在this中,或者在this插入),=false 给定点不在this中 + BOOL InsertPointAtPolyline(CPoint ptPoint, double dMaxError, int iInsertType = 0); + + //在多边形插入点 + //输入参数: + // ptPoint 给定点 + // dMaxError 判断点在线上的最大误差值 + // iInsertType 插入点时的m_iType值 + //返回值: + // =true 给定点在this中(输入时已经在this中,或者在this插入),=false 给定点不在this中 + BOOL InsertPointAtPolygon(CPoint ptPoint, double dMaxError, int iInsertType = 0); + + //查找最近点 + CPoint FindNearestPoint(CPoint ptPoint); + //查找最近点并输出最近距离 + CPoint FindNearestPoint(CPoint ptPoint, int& nDistance); + //根据最大误差值查找最近点 + BOOL FindNearestPoint(CPoint ptPoint, double dMaxError, CPoint& ptOutput); +}; + +//类型点链表的数组 +class CTypePointListArray : public CArray +{ +public: //扩展的变量 +public: //扩展的方法 + + CTypePointListArray& operator=(CTypePointListArray& rhs); //赋值 +}; + +class CRPGrade_Point : public CObject { +public: + CPoint m_ptPoint; + int m_nType; + long n_SerNo; + +public: + + CRPGrade_Point(); + CRPGrade_Point(CRPGrade_Point &a); + CRPGrade_Point(CPoint ptPoint,int nType,long nSerNo); + CRPGrade_Point(CPoint ptPoint,int nType); + ~CRPGrade_Point(); + void operator=(CRPGrade_Point &a); +}; + +class CRotateMove : public CObject { +public: + double m_dAngle; //旋转的角度 + double m_dSin,m_dCos; //旋转的角度正,余弦,引入此变量是为了不重复计算 + CPoint m_ptPointO; //旋转原点 + CPoint m_ptOffset; //偏移量 + +public: + CRotateMove(); + CRotateMove(CRotateMove& rhs); + CRotateMove(double dAngle,CPoint ptPointO,CPoint ptOffset); + ~CRotateMove(); + void operator=(CRotateMove &a); + + void Initial(); +}; + +class CRotateMoveList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CRotateMoveList& operator=(CRotateMoveList& rhs); //赋值 + CRotateMove& operator[](int iIndex); //根据索引值检索,不可越界 +}; + +class CDBLPoint : public CObject { +public: + double x,y; + +public: + CDBLPoint(); + CDBLPoint(double x1,double y1); + CDBLPoint(CDBLPoint &a); + ~CDBLPoint(); + void operator=(CDBLPoint &a); + BOOL operator==(CDBLPoint &a); + + //使用ptPoint设置this + void SetPoint(CPoint ptPoint); + + //返回CPoint点 + CPoint GetPoint(void); +}; + +class CDBLPointList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CDBLPointList& operator=(CDBLPointList& rhs); //赋值 + CDBLPoint& operator[](int iIndex); //根据索引值检索,不可越界 + + //使用listPoint设置this + void SetPoint(CList& listPoint); + + //将this中的点输出到listPoint + void GetPoint(CList& listPoint); +}; + +class CDBLPointListArray : public CArray +{ +public: //扩展的变量 +public: //扩展的方法 + + CDBLPointListArray& operator=(CDBLPointListArray& rhs); //赋值 +}; + +class C4PRgn : public CObject { +public: + CPoint m_ptLU,m_ptLD,m_ptRU,m_ptRD; //字符串显示时占用的区域m_ptLU→m_ptRU→m_ptRD→m_ptLD→m_ptLU + +public: + C4PRgn(); + C4PRgn(C4PRgn &a); + C4PRgn(CPoint ptLU,CPoint ptLD,CPoint ptRU,CPoint ptRD); + void operator=(C4PRgn &a); + BOOL operator==(C4PRgn& a); +}; + +//线段 +class CLineSegment : public CObject +{ +public: + CPoint m_ptPointS; // 起点 + CPoint m_ptPointE; // 终点 + +public: + CLineSegment(); + CLineSegment(CPoint ptPointS, CPoint ptPointE); + CLineSegment(CLineSegment& rhs); + virtual ~CLineSegment(); + CLineSegment& operator=(CLineSegment& rhs); + BOOL operator==(CLineSegment& rhs); + + void Initial(); +}; + +//线段的链表 +class CLineSegmentList : public CList +{ +public: //扩展的变量 +public: //扩展的方法 + + CLineSegmentList& operator=(CLineSegmentList& rhs); //赋值 + CLineSegment& operator[](int iIndex); //根据索引值检索,不可越界 +}; + +//线段链表的数组 +class CLineSegmentListArray : public CArray +{ +public: //扩展的变量 +public: //扩展的方法 + + CLineSegmentListArray& operator=(CLineSegmentListArray& rhs); //赋值 +}; + +//四舍五入取整 +//输入参数: +// x +//返回值: +// 四舍五入后的整数 +int IntRound(double x); + +//样点旋转 +//输入参数: +// (nPx,nPy)被旋转点,(x,y)旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦 +//输出参数: +// (nPxNew,nPyNew)旋转后的值 +void PointRotate(int nPx,int nPy,int x,int y,double dSinBeta,double dCosBeta,int& nPxNew,int& nPyNew); +void PointRotate(double dX,double dY,double dXO,double dYO,double dSinBeta,double dCosBeta,double& dXNew,double& dYNew); +//样点旋转 +//输入参数: +// ptPoint被旋转点,ptPointO旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦 +//输出参数: +// ptPoint旋转后的值 +void PointRotate(CPoint &ptPoint,CPoint ptPointO,double dSinBeta,double dCosBeta); + +//样点旋转 +//输入参数: +// listPoint1被旋转的点链,ptPointO旋转原点,dSinBeta,dCosBeta逆时针旋转角度的正余弦 +//输出参数: +// listPoint2旋转后的值 +void PointRotate(CList &listPoint1,CPoint ptPointO,double dSinBeta,double dCosBeta,CList &listPoint2); + +//样点平移 +//输入参数: +// listPoint1被平移的点链 +// nDx,nDy XY轴的平移量 +//输出参数: +// listPoint2平移后的值 +void PointMove(CList &listPoint1,int nDx,int nDy,CList &listPoint2); + +//将ptPoint坐标缩放 +//输入参数: +// ptPoint 给定点 +// dScale >1放大,<1缩小 +//返回值: +// 放大缩小后的点 +CPoint PointScale(CPoint ptPoint,double dScale); +//以ptPointO为坐标原点,将ptPoint缩放dScale +CPoint PointScale(CPoint ptPoint,CPoint ptPointO,double dScale); +//以ptPointO为坐标原点,沿ptPointO,ptPoint1为方向,将ptPoint缩放dScale +CPoint PointScale(CPoint ptPoint,CPoint ptPointO,CPoint ptPoint1,double dScale); + +//对给定点进行先平移后再缩放 +//输入参数: +// ptPoint 给定点 +// ptOffset 平移量 +// dScale 缩放 +//返回值: +// 平移缩放后的点 +CPoint PointMoveScale(CPoint ptPoint,CPoint ptOffset,double dScale); + +//20140603 对给定点平移旋转 +//输入参数: +// ptPoint 给定点 +// ptOrignalS 转圆心S +// ptOrignalE 旋转圆心E +// ptRotateS 旋转点S +// ptRotateE 旋转点E +//返回值: +// 平移旋转点 +CPoint PointMoveRotate(CPoint ptPoint, CPoint ptOrignalS, CPoint ptOrignalE, CPoint ptRotateS, CPoint ptRotateE); + +//20140603 对给定点平移旋转 +//输入参数: +// listPoint 给定点链 +// ptOrignalS 转圆心S +// ptOrignalE 旋转圆心E +// ptRotateS 旋转点S +// ptRotateE 旋转点E +//输出参数: +// listMoveRotatePoint平移旋转点链 +void PointMoveRotate(CList &listPoint, CPoint ptOrignalS, CPoint ptOrignalE, CPoint ptRotateS, CPoint ptRotateE, CList &listMoveRotatePoint); + +//解一元二次方程ax2+bx+c=0 +//返回值: +// =0,无解 +// =1,有一个解x1(x2=x1) +// =2,有两个解x1,x2 +// =3,有无穷解或无实根 +int Quadratic(double a,double b,double c,double& x1,double& x2); + +//求直线方程ax+by+c=0的系数 +//输入参数: +// (x1,y1),(x2_y2) 直线上两点的坐标 +//输出参数: +// a,b,c 直线方程ax+by+c=0的系数 +void LineEquationCoefficient(int x1,int y1,int x2,int y2,double& a,double& b,double& c); +void LineEquationCoefficient(double x1,double y1,double x2,double y2,double& a,double& b,double& c); + +//求直线方程ax+by+c=0的系数 +//输入参数: +// ptPoint1,ptPoint2 直线上两点的坐标 +//输出参数: +// a,b,c 直线方程ax+by+c=0的系数 +void LineEquationCoefficient(CPoint ptPoint1,CPoint ptPoint2,double& a,double& b,double& c); + +//求两直线的交点 +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// a2,b2,c2 直线a2*x+b2*y+c2=0 +//输出参数 +// (x,y) 交点坐标 +//返回值 +// =0,没有交点 +// =1,有交点(x,y) +// =2,两直线重合 +int IntOfTwoLine(double a1,double b1,double c1,double a2,double b2,double c2,double& x,double& y); + +//求两直线的交点 +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// a2,b2,c2 直线a2*x+b2*y+c2=0 +//输出参数 +// (nx,ny) 交点坐标 +//返回值 +// =0,没有交点 +// =1,有交点(nx,ny) +// =2,两直线重合 +int IntOfTwoLine(double a1,double b1,double c1,double a2,double b2,double c2,int& nx,int& ny); + +//求两直线的交点 +//输入参数 +// (nXS1,nYS1),(nXE1,nYE1) 直线1的起点和终点坐标 +// (nXS2,nYS2),(nXE2,nYE2) 直线2的起点和终点坐标 +//输出参数 +// (nx,ny) 交点坐标 +//返回值 +// =0,没有交点 +// =1,有交点(nx,ny) +// =2,两直线重合 +int IntOfTwoLine(int nXS1,int nYS1,int nXE1,int nYE1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求两直线的交点 +//输入参数 +// PointS1_PointE1 直线1的起点和终点 +// PointS2_PointE2 直线2的起点和终点 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,有交点ptIntersection +// =2,两直线重合 +int IntOfTwoLine(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//求两直线段的交点 +//输入参数 +// (nXS1,nYS1),(nXE1,nYE1) 直线段1的起点和终点坐标 +// (nXS2,nYS2),(nXE2,nYE2) 直线段2的起点和终点坐标 +//输出参数 +// (nx,ny) 交点坐标 +//返回值 +// =0,没有交点 +// =1,交点同时在两条线段内(包括两端点),交点(nx,ny) +// =2,交点不在线段内(包括两端点),交点(nx,ny) +// =3,没有共同端点的重叠线段,两线段在同一直线上(有一个以上的交点)且没有共同的端点 +// =4,有共同端点的不重叠线段,两线段在同一直线上且只有一个端点重叠(nx,ny) +// =5,有共同端点的重叠线段,其中(nx,ny)是重叠部分中非共同的端点 +int IntOfTwoLineSegment(int nXS1,int nYS1,int nXE1,int nYE1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求两直线段的交点 +//输入参数 +// PointS1_PointE1 直线段1的起点和终点 +// PointS2_PointE2 直线段2的起点和终点 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点同时在两条线段内(包括两端点),交点ptIntersection +// =2,交点不在线段内(包括两端点),交点ptIntersection +// =3,没有共同端点的重叠线段,两线段在同一直线上(有一个以上的交点)且没有共同的端点 +// =4,有共同端点的不重叠线段,两线段在同一直线上且只有一个端点重叠ptIntersection +// =5,有共同端点的重叠线段,其中ptIntersection是重叠部分中非共同的端点 +int IntOfTwoLineSegment(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// (nXS2,nYS2),(nXE2,nYE2) 线段的起点和终点坐标 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点(nx,ny) +// =2,交点不在线段内(包括两端点),交点(nx,ny) +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(double a1,double b1,double c1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// a1,b1,c1 直线a1*x+b1*y+c1=0 +// PointS2,PointE2 线段的起点和终点坐标 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点ptIntersection +// =2,交点不在线段内(包括两端点),交点ptIntersection +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(double a1,double b1,double c1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// (nXS1,nYS1),(nXE1,nYE1) 直线的起点和终点坐标 +// (nXS2,nYS2),(nXE2,nYE2) 线段的起点和终点坐标 +//输出参数 +// (nx,ny) 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点(nx,ny) +// =2,交点不在线段内(包括两端点),交点(nx,ny) +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(int nXS1,int nYS1,int nXE1,int nYE1,int nXS2,int nYS2,int nXE2,int nYE2,int& nx,int& ny); + +//求直线和直线段的交点!!! +//特别说明: +// 该函数是求一条直线和一条线段的交点,而不是求两条线段或两条直线的交点!!! +// 参见IntOfTwoLineSegment(...),IntOfTwoLine(...). +//输入参数 +// PointS1_PointE1 直线的起点和终点 +// PointS2_PointE2 线段的起点和终点 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,交点在线段内(包括两端点),交点ptIntersection +// =2,交点不在线段内(包括两端点),交点ptIntersection +// =3,直线和线段在同一直线上 +int IntOfLineLineSegment(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); +//求矢量ptPointS1→ptPointE1和矢量ptPointS2→ptPointE2的交点!!! +//输入参数 +// PointS1,PointE1 矢量ptPointS1→ptPointE1 +// PointS2,PointE2 矢量ptPointS2→ptPointE2 +//输出参数 +// ptIntersection 交点 +//返回值 +// =0,没有交点 +// =1,有交点ptIntersection +// =2,两直线重合 +int IntOfTwoVectorLine(POINT PointS1,POINT PointE1,POINT PointS2,POINT PointE2,POINT& ptIntersection); + +//直线和圆的交点 +//输入参数: +// a,b,c 直线:ax+by+c=0; +// (xc,yc) 圆心 +// nR 半径 +//输出参数: +// lpptIntersection1,lpptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点 +// =2,两个交点 +int IntOfLineCircle(double a,double b,double c,int xc,int yc,int nR,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//直线和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// lpptIntersection1,lpptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点 +// =2,两个交点 +int IntOfLineCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//直线和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// ptIntersection1,ptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点 +// =2,两个交点 +int IntOfLineCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,CPoint& ptIntersection1,CPoint& ptIntersection2); + +//直线段和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线段的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// lpptIntersection1,lpptIntersection2 直线和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点(包括两端点) +// =2,两个交点(包括两端点) +int IntOfLineSegmentCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//直线段和圆的交点 +//输入参数: +// ptPointS,ptPointE 直线段的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// ptIntersection1,ptIntersection2 直线段和圆的两个交点 +//返回值 +// =0,没有交点 +// =1,一个交点(包括两端点) +// =2,两个交点(包括两端点) +int IntOfLineSegmentCircle(POINT ptPointS,POINT ptPointE,POINT ptCenter,int nRadius,CPoint& ptIntersection1,CPoint& ptIntersection2); + +//折线和圆的交点 +//输入参数: +// listPolyline 折线 +// ptCenter 圆心 +// nRadius 半径 +//输出参数: +// listIntPoint 折线和圆的交点 +//返回值 +// 交点个数(=0,没有交点) +int IntOfPolylineCircle(CList &listPolyline,POINT ptCenter,int nRadius,CList &listIntPoint); + +//求两圆的交点 +//输入参数 +// x1,y1,r1 圆:(x-x1)*(x-x1) + (y-y1)*(y-y1) = r1*r1 +// x2,y2,r2 圆:(x-x2)*(x-x2) + (y-y2)*(y-y2) = r2*r2 +//输出参数 +// (nIntX1,nIntY1),(nIntX2,nIntY2) 两交点坐标 +//返回值 +// =0,没有交点 +// =1,有一个交点 +// =2,有两个交点 +int IntOfTwoCircle(int x1,int y1,int r1,int x2,int y2,int r2,int& nIntX1,int& nIntY1,int& nIntX2,int& nIntY2); + +//求两圆的交点 +//输入参数 +// ptCenter1,nRadius1 圆心和半径 +// ptCenter2,nRadius2 圆心和半径 +//输出参数 +// lpptIntersection1,lpptIntersection2 两交点 +//返回值 +// =0,没有交点 +// =1,有一个交点 +// =2,有两个交点 +int IntOfTwoCircle(POINT ptCenter1,int nRadius1,POINT ptCenter2,int nRadius2,LPPOINT lpptIntersection1,LPPOINT lpptIntersection2); + +//求两圆的交点 +//输入参数 +// ptCenter1,nRadius1 圆心和半径 +// ptCenter2,nRadius2 圆心和半径 +//输出参数 +// ptIntersection1,ptIntersection2 两交点 +//返回值 +// =0,没有交点 +// =1,有一个交点 +// =2,有两个交点 +int IntOfTwoCircle(POINT ptCenter1,int nRadius1,POINT ptCenter2,int nRadius2,CPoint& ptIntersection1,CPoint& ptIntersection2); + +//求线段和折线的交点 +//特别所明: +// 该函数是求线段和折线中的各线段的交点,而不是求直线和折线中的各线段的交点!!! +// 参见IntOfLinePolyline(...). +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfLineSegmentPolyline(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); +//与IntOfLineSegmentPolyline(...)相比,IntOfLineSegmentPolyline_Old(...)有个错误(包括了一句"case 2:") +int IntOfLineSegmentPolyline_Old(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); + +//求矢量ptPointS→ptPointE和折线的交点!!! +//特别所明: +// 该函数是求矢量和折线中的各线段的交点,而不是求直线(或直线段)和折线中的各线段的交点!!! +// 要求交点在线段ptPointS_ptPointE上或在矢量ptPointS→ptPointE的延长线上 +// 参见IntOfLineSegmentPolyline(...)和IntOfLinePolyline(...). +//输入参数 +// ptPointS,ptPointE 矢量ptPointS→ptPointE +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfVectorLinePolyline(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); + +//求直线和折线的交点!!! +//特别所明: +// 该函数是求直线和折线中的各线段的交点,而不是求直线段和折线中的各线段的交点!!! +// 参见IntOfLineSegmentPolyline(...). +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfLinePolyline(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,CList& listIntPoint); + +//求直线和折线的交点!!! +//特别所明: +// 该函数是求直线和折线中的各线段的交点,而不是求直线段和折线中的各线段的交点!!! +// 参见IntOfLineSegmentPolyline(...). +//输入参数 +// a,b,c 直线方程ax+by+c=0 +// listPolyline 折线 +//输出参数 +// listIntPoint 交点链 +//返回值 +// 交点个数 +int IntOfLinePolyline(double a,double b,double c,CList& listPolyline,CList& listIntPoint); + +//求直线和折线链头的延长线的交点 +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +// dLength 用于计算延长线时的搜索长度 +//输出参数 +// ptIntPoint 交点 +//返回值 +// 交点个数 +int IntOfLinePolylineExtendHead(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,double dLength,CPoint &ptIntPoint); +int IntOfLinePolylineExtendHead(double a,double b,double c,CList& listPolyline,double dLength,CPoint &ptIntPoint); + +//求直线和折线链尾的延长线的交点 +//输入参数 +// ptPointS,ptPointE 直线的两点 +// listPolyline 折线 +// dLength 用于计算延长线时的搜索长度 +//输出参数 +// ptIntPoint 交点 +//返回值 +// 交点个数 +int IntOfLinePolylineExtendTail(CPoint ptPointS,CPoint ptPointE,CList& listPolyline,double dLength,CPoint &ptIntPoint); +int IntOfLinePolylineExtendTail(double a,double b,double c,CList& listPolyline,double dLength,CPoint &ptIntPoint); + +//求折线和折线的交点 +//输入参数 +// listPolyline1 折线 +// listPolyline2 折线 +//输出参数 +// listIntPoint 交点链,交点以在listPolyline1的出现顺序从头到尾排列 +//返回值 +// 交点个数 +int IntOfTwoPolyline(CList& listPolyline1,CList& listPolyline2,CList& listIntPoint); + +//[20161229 syf]求折线和折线的交点 +//特别说明: +// (1)该函数拷贝IntOfTwoPolyline()代码,但是在判断IntOfTwoLineSegment()的返回值时,{1,4,5}都被采用,而IntOfTwoPolyline()仅仅采用=1的情况 +//输入参数 +// listPolyline1 折线 +// listPolyline2 折线 +//输出参数 +// listIntPoint 交点链,交点以在listPolyline1的出现顺序从头到尾排列 +//返回值 +// 交点个数 +int IntOfTwoPolyline_101(CList& listPolyline1,CList& listPolyline2,CList& listIntPoint); + +//匹配两直线段的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// ptPointS1_ptPointE1 直线段1的起点和终点 +// ptPointS2_ptPointE2 直线段2的起点和终点 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +//返回值 +// 若两直线段的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfTwoLineSegment(POINT ptPoint,double dMaxError,POINT ptPointS1,POINT ptPointE1, + POINT ptPointS2,POINT ptPointE2,POINT& ptIntersection,double& dDistance); + +//匹配线段和圆的交点 +//输入参数: +// ptPoint +// dMaxError 最大匹配距离 +// ptPointS,ptPointE 直线段的起止点 +// ptCenter 圆心 +// nRadius 半径 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +//返回值 +// 若线段和圆的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfLineSegmentCircle(POINT ptPoint,double dMaxError,POINT ptPointS,POINT ptPointE, + POINT ptCenter,int nRadius,POINT& ptIntersection,double& dDistance); + +//匹配两圆的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// ptCenter1,nRadius1 圆心和半径 +// ptCenter2,nRadius2 圆心和半径 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +//返回值 +// 若两圆的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfTwoCircle(POINT ptPoint,double dMaxError,POINT ptCenter1,int nRadius1, + POINT ptCenter2,int nRadius2,POINT& ptIntersection,double& dDistance); + +//匹配线段和折线的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// ptPointS,ptPointE 线段 +// listPolyline 折线 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +// nLocate 交点位置(第nLocate个交点) +//返回值 +// 若线段和折线的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfLineSegmentPolyline(POINT ptPoint,double dMaxError,POINT ptPointS, + POINT ptPointE,CList &listPolyline, + POINT &ptIntersection,double &dDistance,int& nLocate); + +//匹配两折线的交点 +//输入参数 +// ptPoint +// dMaxError 最大匹配距离 +// listPolyline1 折线1 +// listPolyline2 折线2 +//输出参数 +// ptIntersection 交点 +// dDistance 实际距离 +// nLocate 交点位置(第nLocate个交点) +//返回值 +// 若折线的交点ptIntersection与ptPoint的距离<=dMaxError,则返回true.否则false. +BOOL FixPointIntOfTwoPolyline(POINT ptPoint,double dMaxError,CList &listPolyline1, + CList &listPolyline2,POINT &ptIntersection,double &dDistance,int& nLocate); + +//滤点 +//将完全在(ptPoint.x-nMaxError,ptPoint.y-nMaxError)__(ptPoint.x+nMaxError,ptPoint.y-nMaxError) +//之外的线段点删除 +//输入参数: +// ptPoint 域的中心点 +// nMaxError 域的半径 +// listPoint1 滤点前的点链 +//输出参数: +// listPoint2 滤点后的点链 +void FilterPointOfListPoint(POINT ptPoint,int nMaxError,CList &listPoint1,CList &listPoint2); + +//求过点(nPx,nPy)和直线ax+by+c=0垂直的直线与直线ax+by+c=0的交点(nFixX,nFixY) +//输入参数 +// (nPx,nPy)给定点的坐标 +// a,b,c 给定直线的系数 +//输出参数 +// (nFixX,nFixY)交点坐标 +void IntOfLinePointVL(int nPx,int nPy,double a,double b,double c,int& nFixX,int& nFixY); +void IntOfLinePointVL(double dPx,double dPy,double a,double b,double c,double& dFixX,double& dFixY); + +//求过点ptPoint1和直线ax+by+c=0垂直的直线与直线ax+by+c=0的交点ptPoint2 +//输入参数 +// ptPoint1给定点的坐标 +// a,b,c 给定直线的系数 +//输出参数 +// ptPoint2交点坐标 +void IntOfLinePointVL(CPoint ptPoint1,double a,double b,double c,CPoint& ptPoint2); + +//求过点ptPoint1和直线ptPoint2_ptPoint3垂直的直线与直线ptPoint2_ptPoint3的交点ptPoint4 +//输入参数 +// ptPoint1给定点的坐标 +// ptPoint2,ptPoint3 给定直线的两点 +//输出参数 +// ptPoint4交点坐标 +void IntOfLinePointVL(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint& ptPoint4); + +//以(x2,y2)_(x3,y3)为对称轴的对称点 +//输入参数; +// (x1,y1) 给定点 +// (x2,y2)_(x3,y3) 给定对称轴 +//输出参数: +// (nPx,nPy) 对称点 +void SymmetryPoint(int x1,int y1,int x2,int y2,int x3,int y3,int& nPx,int& nPy); +//以ptPoint2_ptPoint3为对称轴的对称点 +//输入参数; +// ptPoint1 给定点 +// ptPoint2_ptPoint3 给定对称轴 +//输出参数: +// ptPoint4 对称点 +void SymmetryPoint(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint &ptPoint4); +//以ptPoint1_ptPoint2为对称轴的对称点 +//输入参数; +// listPoint1 给定点链 +// ptPoint1_ptPoint2 给定对称轴 +//输出参数: +// listPoint2 对称点链 +void SymmetryPoint(CList &listPoint1,CPoint ptPoint1,CPoint ptPoint2,CList &listPoint2); +//以直线ax+by+c=0为对称轴的对称点 +//输入参数; +// listPoint1 给定点链 +// a,b,c 给定对称轴的直线方程 +//输出参数: +// listPoint2 对称点链 +void SymmetryPoint(CList &listPoint1,double a,double b,double c,CList &listPoint2); +void SymmetryPoint(CList &listDBLPoint1,double a,double b,double c,CList &listDBLPoint2); +//以直线ax+by+c=0为对称轴的对称点 +//输入参数; +// (x1,y1) 给定点 +// a,b,c 给定对称轴的直线方程 +//输出参数: +// (nPx,nPy) 对称点 +void SymmetryPoint(int x1,int y1,double a,double b,double c,int& nPx,int& nPy); +void SymmetryPoint(double x1,double y1,double a,double b,double c,double& dPx,double& dPy); +//以直线ax+by+c=0为对称轴的对称点 +//输入参数; +// ptPoint1 给定点 +// a,b,c 给定对称轴的直线方程 +//输出参数: +// ptPoint2 对称点 +void SymmetryPoint(CPoint ptPoint1,double a,double b,double c,CPoint& ptPoint2); +void SymmetryPoint(CDBLPoint ptDBLPoint1,double a,double b,double c,CDBLPoint& ptDBLPoint2); + +//求两点确定的直线与X轴的夹角,在[0,2pi)之间 +//输入参数: +// (startx,starty) 起点 +// (endx,endy) 终点 +//返回值: +// 夹角 +double angle_2(int startx,int starty,int endx,int endy); +//[20170330 syf] +double angle_2(double startx,double starty,double endx,double endy); + +//求两点确定的直线与X轴的夹角,在[0,2pi)之间 +//输入参数: +// ptPointS 起点 +// ptPointE 终点 +//返回值: +// 夹角 +double angle_2(POINT ptPointS,POINT ptPointE); + +//[20170330 syf] +double angle_2(CDBLPoint ptPointS,CDBLPoint ptPointE); + +//求矢量ptPointS1→ptPointE1逆时针方向旋转到矢量ptPointS2→ptPointE2的方向所经过的夹角,在[0,2pi)之间 +//输入参数: +// ptPointS1,ptPointE1 矢量ptPointS1→ptPointE1 +// ptPointS2,ptPointE2 矢量ptPointS2→ptPointE2 +//返回值: +// 夹角 +double angle_2(POINT ptPointS1,POINT ptPointE1,POINT ptPointS2,POINT ptPointE2); + +//[20170330 syf] +double angle_2(CDBLPoint ptPointS1,CDBLPoint ptPointE1,CDBLPoint ptPointS2,CDBLPoint ptPointE2); + +//给定弧线上三点(x1,y1),(x2,y2)和(x3,y3),以及圆心(cx,cy), +//其中(x2,y2)在(x1,y1)和(x3,y3)中间,按逆时针方向画弧时, +//当(x1,y1)是起点,(x3,y3)是终点时返回true,否则返回false +//特别说明:此处所说的逆时针是指显示器而言,对X向右为正,Y向上为正的坐标系来说此处是顺时针 +BOOL IsAnticlockwise(long x1,long y1,long x2,long y2,long x3,long y3,long cx,long cy); + +//[20170330 syf] +BOOL IsAnticlockwise_Double(double x1,double y1,double x2,double y2,double x3,double y3,double cx,double cy); + +///////////////////////// 计算三点定圆时的圆心和半径 /////////////////////////// +// 输入参数:三个样点(x1,y1),(x2,y2),(x3,y3) +// 算法描述: +// 过(x1,y1),(x2,y2)的中点作垂线L1, +// 过(x2,y2),(x3,y3)的中点作垂线L2, +// 求L1,L2的交点. +// 输出参数: +// 如果不能形成圆返回false, +// 否则返回true其中圆心为(cx,cy),半径=cr. +// 按逆时针方向画弧时,如cr>0 则(x1,y1)是起点,(x3,y3)是终点, +// 如cr<0 则(x3,y3)是起点,(x1,y1)是终点. +// 特别说明:此处所说的逆时针是指显示器而言,如果对于对X向右为正, +// Y向上为正的坐标系来说此处是顺时针 +//////////////////////////////////////////////////////////////////////////////// +BOOL CircleCR(int x1,int y1,int x2,int y2,int x3,int y3,int& cx,int& cy,int& cr); + +//[20170330 syf] +BOOL CircleCR(double x1,double y1,double x2,double y2,double x3,double y3,double& cx,double& cy,double& cr); + +//求圆和一半径线(ptCenter和ptPoint的连线)的交点 +//输入参数 +// ptCenter 圆心 +// nRadius 半径 +// ptPoint 半径上的一点 +//返回值 +// 交点 +CPoint IntOfCircleRadial(CPoint ptCenter,int nRadius,CPoint ptPoint); + +//用追赶法求解三对角线方程组: AX=D +// ┌ ┐ ┌ ┐ ┌ ┐ +// │ a00 a01 │ │x0 │ │d0 │ +// │ a10 a11 a12 0 │ │x1 │ │d1 │ +// │ a21 a22 a23 │ │x2 │ │d2 │ +// │ . . . │ │. │ │. │ +// A=│ . . . │, X=│. │, D=│. │ +// │ . . . │ │. │ │. │ +// │ 0 an-2,n-3 an-2,n-2 an-2,n-1 │ │xn-2│ │dn-2│ +// │ an-1,n-2 an-1,n-1 │ │xn-1│ │dn-1│ +// └ ┘ └ ┘ └ ┘ +//输入参数: +// a[] 存放三对角线矩阵A的一维数组a00,a01,a10,a11,a12,a21,a22,a23,...,(an-1,n-2),(an-1,n-1) +// n 变量个数,方程组的阶数 +// d[] 方程组右端的常数向量 +//输出参数 +// 有唯一解时返回TRUE,其中d[]是方程组的解. +// 否则返回FALSE. +BOOL Cetrd1(double *a,int n,double *d); + +//求解带左下角右上角的三对角线方程组: AX=D +// ┌ ┐ ┌ ┐ ┌ ┐ +// │ a00 a01 a0n │ │x0 │ │d0 │ +// │ a10 a11 a12 0 │ │x1 │ │d1 │ +// │ a21 a22 a23 │ │x2 │ │d2 │ +// │ . . . │ │. │ │. │ +// A=│ . . . │, X=│. │, D=│. │ +// │ . . . │ │. │ │. │ +// │ 0 an-2,n-3 an-2,n-2 an-2,n-1 │ │xn-2│ │dn-2│ +// │ an-1,0 an-1,n-2 an-1,n-1 │ │xn-1│ │dn-1│ +// └ ┘ └ ┘ └ ┘ +//输入参数: +// a[] 存放矩阵A的一维数组a00,a01,a0n,a10,a11,a12,0,a21,a22,a23,0,...,(an-1,0),(an-1,n-2),(an-1,n-1) +// n 变量个数,方程组的阶数 +// d[] 方程组右端的常数向量 +//输出参数 +// 有唯一解时返回TRUE,其中d[]是方程组的解. +// 否则返回FALSE. +BOOL Cetrd2(double *a,int n,double *d); + +//对给定的型值点用二次Bezier曲线进行拟合,再用折线逼近. +// ┌ 1 -2 1 ┐┌P1 ┐ +// P(t)=[t2 t 1]│-2 2 0 ││p2 │ +// └ 1 0 0 ┘└p3 ┘ +//输入参数: +// listSP是型值点链. +// dMaxError 最大拟合误差(>=0.5) +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 否则返回false,listFitP中的数据和listSP相同 +BOOL BezierCurve(CList& listSP,double dMaxError,CList& listFitP); + +//说明: 根据参数求2次Bezier上的一个点 +//输入参数: +// (dX1,dY1),(dX2,dY2),(dX3,dY3) 2次Bezier的三个控制点 +// dT 参数T +//返回值: +// point 与dT对应的点 +CPoint BezierPoint(double dX1, double dY1, double dX2, double dY2, double dX3, double dY3, double dT); +//求与2次Bezier线上给定方向的切线的切点的参数值 +//输入参数: +// (dX1,dY1),(dX2,dY2),(dX3,dY3) 2次Bezier的三个控制点 +// pointS,pointE 切线方向(两点不能相同) +//返回值: +// 切点的参数 +double BezierPointParam(double dX1, double dY1, double dX2, double dY2, double dX3, double dY3, CPoint pointS,CPoint pointE); + +//对给定的型值点用参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL SplineCurve(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bNatural=true); + +//对给定的型值点用参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bTangentH =true 起点有切线条件 +// ptTangentH 起点有切线条件时切线上的点 +// bTangentT =true 终点有切线条件 +// ptTangentT 终点有切线条件时切线上的点 +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL SplineCurve(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bTangentH,CPoint ptTangentH,BOOL bTangentT,CPoint ptTangentT,BOOL bNatural); + +//对给定的型值点用Bezier曲线或参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//特别说明: +// 当型值点的个数是3且是开口线时使用Bezier曲线,否则使用样条曲线 +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL CurveFit(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bNatural=true); +//对给定的型值点用Bezier曲线或参数(弦长)三次样条曲线进行拟合,再用折线逼近. +//特别说明: +// 当型值点的个数是3且起止点没有切线条件的开口线时使用Bezier曲线,否则使用样条曲线 +//输入参数: +// listSP是型值点链. +// bClose =fasle,开口曲线, =true 闭合周期曲线(此时要求型值点链的头和尾表示的是同一点). +// dMaxError 最大拟合误差(>=0.5) +// bTangentH =true 起点有切线条件 +// ptTangentH 起点有切线条件时切线上的点 +// bTangentT =true 终点有切线条件 +// ptTangentT 终点有切线条件时切线上的点 +// bNatural =true 自由端边界条件,=false 抛物线边界条件 +//输出参数: +// 拟合成功返回true, +// listFitP是根据拟合曲线得到的逼近折线样点链. +// 特别说明:闭合周期曲线的逼近折线listFitP的头和尾两点坐标不相同!!! +// 否则返回false. +BOOL CurveFit(CList& listSP,BOOL bClose,double dMaxError,CList& listFitP,BOOL bTangentH,CPoint ptTangentH,BOOL bTangentT,CPoint ptTangentT,BOOL bNatural); + +//计算NURBS曲线的实际点链(非均匀有理B样条) +//特别说明: +// 本函数调用API计算,不需要传入拟合误差 +//输入参数: +// listSP 型值点链,坐标系:既可以是纸样坐标系,又可以是设备坐标系 +// bClose =true 闭合,=false 开口 +//输出参数: +// listFitP 根据拟合曲线得到的逼近折线样点链,如果闭合,那么头尾点坐标不同!!! +//返回值: +// =true 计算成功,=false 计算失败 +BOOL CurveFit_NURBS(CList& listSP, CList& listFitP, BOOL bClose = FALSE); + +//反求开口曲线的控制点 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +//输出参数: +// listCtrlPoint 控制点链 +BOOL GetControlPointOfOpenCurve(int iDPMM,CList &listFitPoint,double dMaxError,CList &listCtrlPoint); + +//反求开口曲线的控制点 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +// listCtrlPoint 已有的控制点 +//输出参数: +// listCtrlPoint 控制点链,listCtrlPoint的起点和终点的坐标不相同 +BOOL GetControlPointOfOpenCurve(int iDPMM,CList &listFitPoint,double dMaxError,CList &listCtrlPoint); + +//反求闭合曲线的控制点,listFitPoint的起点和终点的坐标不相同 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +//输出参数: +// listCtrlPoint 控制点链,listCtrlPoint的起点和终点的坐标不相同 +BOOL GetControlPointOfCloseCurve(int iDPMM,CList &listFitPoint, + double dMaxError,CList &listCtrlPoint); + +//反求闭合曲线的控制点,listFitPoint的起点和终点的坐标不相同 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listFitPoint 原始点链 +// dMaxError 最大误差 +// listCtrlPoint 已有的控制点 +//输出参数: +// listCtrlPoint 控制点链 +BOOL GetControlPointOfCloseCurve(int iDPMM,CList &listFitPoint,double dMaxError,CList &listCtrlPoint); + +//在点链listPointOld中的点与点链listPointNew的最小距离中的最大距离点 +//输入参数: +// listPointOld 点链 +// listPointNew 点链 +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +//输出参数: +// dMaxDistance 最大距离 +//返回值: +// 找到的最大距离点 +CPoint MaxDistancePoint(int iDPMM,CList &listPointOld,CList &listPointNew,double &dMaxDistance); + +//判断多边形点链从头到尾的方向 +//输入参数: +// listPolygon 多边形的点链. +//返回值: +// =true 逆时针(显示器坐标系),=false 顺时针(显示器坐标系) +BOOL IsAnticlockwise(CList& listPolygon); + +//使点链的方向变反,链头不变. +//输入参数: +// listPoint1 点链. +//输出参数: +// listPoint2 +void Reverse(CList& listPoint1,CList& listPoint2); +//使点链的方向变反,链尾变成链头. +//输入参数: +// listPoint1 点链. +//输出参数: +// listPoint2 +void ReverseT2H(CList& listPoint1,CList& listPoint2); + +//翻转 +//输入参数: +// listPoint1 待翻转的点链 +// x 水平翻转的对称轴 +// bHorizontal =true 水平翻转 +// y 垂直翻转的对称轴 +// bVertical =true 垂直翻转 +//输出参数: +// listPoint2 已翻转的点链 +void Flip(CList &listPoint1,int x,BOOL bHorizontal,int y,BOOL bVertical,CList &listPoint2); +//翻转 +//输入参数: +// ptPoint 待翻转的点链 +// x 水平翻转的对称轴 +// bHorizontal =true 水平翻转 +// y 垂直翻转的对称轴 +// bVertical =true 垂直翻转 +//输出参数: +// ptPoint 已翻转的点 +void Flip(CPoint &ptPoint,int x,BOOL bHorizontal,int y,BOOL bVertical); + +//点ptPoint到直线ax+by+c=0的距离 +double DistanceOfPL(CPoint ptPoint,double a,double b,double c); +//点ptPoint到直线ptPointL1_ptPointL2的距离 +double DistanceOfPL(CPoint ptPoint,CPoint ptPointL1,CPoint ptPointL2); +//点ptPoint到线段ptPointL1_ptPointL2的距离 +double DistanceOfPLineSegment(CPoint ptPoint,CPoint ptPointL1,CPoint ptPointL2); +//点ptPoint到折线listPolyline的最近距离 +double DistanceOfPPloyline(CPoint ptPoint,CList &listPolyline); + +//去掉点链中相同的点,若点链中有相同的点则只保留一个 +void RemoveSamePointOfPolygon(CList& listPoint); +//[20170330 syf] +void RemoveSamePointOfPolygon(CDBLPointList& listPoint); + +//去掉点链中相同的点,若点链中有相同的点则只保留一个 +//与RemoveSamePointOfPolygon不同的是首尾点相同时不再去掉一点 +void RemoveSamePointOfPolyline(CList& listPoint); + +//[20170330 syf] +void RemoveSamePointOfPolyline(CDBLPointList& listPoint); + +//删除距离<=dMinLength的点 +void Remove2NearPointOfPolygon(CList& listPoint,double dMinLength); +//删除距离<=dMinLength的点 +void Remove2NearPointOfPolyline(CList& listPoint,double dMinLength); + +//20160602 XQ 删除链中所有点距离<=dMinLength的点 +void RemoveAll2NearPointOfPolyline(CList& listPoint,double dMinLength); + +//求多边形中的一段折线. +//将多边形从点ptPointS顺时针(显示器坐标系)方向移动到点ptPointE所经过的区域. +//若ptPointS==ptPointE,则是从ptPointS到ptPointE的整条点链 +//特别说明: +// ptPointS,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL PolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointE,CList& listPolyline); + +//求多边形中的一段折线. +//将多边形从点ptPointS先经过ptPointM再到点ptPointE所经过的区域. +//特别说明: +// ptPointS,ptPointM,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的端点. +// ptPointM 中间点 +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL PolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointM,CPoint ptPointE,CList& listPolyline); + +//求多边形中的一段折线. +//将多边形从点ptPointS前向移动到点ptPointE所经过的区域.若ptPointS==ptPointE则是从ptPointS开始 +//到ptPointE结束的整条点链. +//特别说明: +// ptPointS,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL PrevPolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointE,CList& listPolyline); + +//求多边形中的一段折线. +//将多边形从点ptPointS后向移动到点ptPointE所经过的区域.若ptPointS==ptPointE则是从ptPointS开始 +//到ptPointE结束的整条点链. +//特别说明: +// ptPointS,ptPointE不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline 折线的点链 +//返回值: +// true 成功,否则false. +BOOL NextPolylineOfPolygon(int iDPMM,CList& listPolygon,CPoint ptPointS,CPoint ptPointE,CList& listPolyline); + +//求折线的点ptPointS与点ptPointE之间的一段折线. +//特别说明: +// ptPointS,ptPointE不一定是折线的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointS,ptPointE折线段的起止点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolyline(int iDPMM,CList& listPolyline1,CPoint ptPointS,CPoint ptPointE,CList& listPolyline2); + +//求折线的起点与点ptPointE之间的一段折线. +//特别说明: +// ptPointE不一定是折线的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointE折线段的终点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolylineS(int iDPMM,CList& listPolyline1,CPoint ptPointE,CList& listPolyline2); + +//求折线的点ptPointS与终点之间的一段折线. +//特别说明: +// ptPointS不一定是折线的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointE折线段的终点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolylineE(int iDPMM,CList& listPolyline1,CPoint ptPointS,CList& listPolyline2); + +//求折线的从点ptPointS开始,经过点ptPointM到端点(起点或终点)之间的一段折线. +//特别说明: +// ptPointS,ptPointM不一定是多边形的顶点. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline1 原折线的点链. +// ptPointS,ptPointM折线段的起止点. +//输出参数: +// listPolyline2 新折线的点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfPolylineSM(int iDPMM,CPoint ptPointS,CPoint ptPointM,CList& listPolyline1,CList& listPolyline2); + +//求依次经过ptArcPointS,ptArcPointM,ptArcPointE的圆的多边形表示 +//输入参数: +// ptCirclePointS,ptCirclePointM,ptCirclePointE 圆依次经过的点 +// dMaxError 最大逼近误差 +//输出参数: +// listPolygon 多边形点链 +//返回值: +// 成功true,否则false. +BOOL PolygonOfCircle(CPoint ptCirclePointS,CPoint ptCirclePointM,CPoint ptCirclePointE,CList& listPolygon,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolygonOfCircle(CDBLPoint ptCirclePointS,CDBLPoint ptCirclePointM,CDBLPoint ptCirclePointE,CDBLPointList& listPolygon,double dMaxError=0.5); + +//求圆逆时针方向(显示器坐标)的多边形表示. +//输入参数: +// ptCenter 圆心 +// ptCirclePointS 圆的起点 +// dMaxError 最大逼近误差 +//输出参数: +// listPolygon 多边形点链 +//返回值: +// 成功true,否则false. +BOOL PolygonOfCircle(CPoint ptCenter,CPoint ptCirclePointS,CList& listPolygon,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolygonOfCircle(CDBLPoint ptCenter,CDBLPoint ptCirclePointS,CDBLPointList& listPolygon,double dMaxError=0.5); + +//求依次经过ptArcPointS,ptArcPointM,ptArcPointE的弧线的折线表示. +//输入参数: +// ptArcPointS,ptArcPointM,ptArcPointE 弧线依次经过的点 +// dMaxError 最大逼近误差 +//输出参数: +// listPolyline 折线点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfArc(CPoint ptArcPointS,CPoint ptArcPointM,CPoint ptArcPointE,CList& listPolyline,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolylineOfArc(CDBLPoint ptArcPointS,CDBLPoint ptArcPointM,CDBLPoint ptArcPointE,CDBLPointList& listPolyline,double dMaxError=0.5); + +//求弧线的折线表示. +//输入参数: +// ptCenter 圆心 +// ptArcPointS 弧线起点 +// dAngle 扇形角度,>=0 逆时针(显示器坐标系),<0 顺时针(显示器坐标系),单位:弧度 +// dMaxError 最大逼近误差 +//输出参数: +// listPolyline 折线点链 +//返回值: +// 成功true,否则false. +BOOL PolylineOfArc(CPoint ptCenter,CPoint ptArcPointS,double dAngle,CList& listPolyline,double dMaxError=0.5); + +//[20170330 syf] +BOOL PolylineOfArc(CDBLPoint ptCenter,CDBLPoint ptArcPointS,double dAngle,CDBLPointList& listPolyline,double dMaxError=0.5); + +//判断一点是否在多边形内 +//输入参数: +// point 给定点 +// lpPoints[0]...lpPoints[nCount-1] 多边形的顶点 +//返回值: +// =true 点在多边形内 +// =false 点不在多边形内 +BOOL PointInPolygon(POINT point,LPPOINT lpPoints,int nCount); + +//判断一点是否在多边形内 +//输入参数: +// point 给定点 +// listPolygon 多边形的点链 +//返回值: +// =true 点在多边形内 +// =false 点不在多边形内 +BOOL PointInPolygon(POINT point,CList& listPolygon); + +//求与直线P1P2相距nD的平行直线的方程,直线在矢量P1P2的左侧(显示器坐标系) +//重要说明: +// 在程序中是按X向右为正,Y向上为正的坐标系计算的,故所求直线是在矢量P1P2的右侧 +//输入参数: +// (nX1,nY1),(nX2,nY2) 直线P1P2的两点 +// nD 所求直线和给定直线P1P2的距离 +//输出参数: +// 当(nX1,nY1),(nX2,nY2)不是同一点时返回true, a,b,c 所求得的直线:ax+b*y+c=0; +// 当(nX1,nY1),(nX2,nY2)是同一点时返回fasle. +BOOL LineParallel(int nX1,int nY1,int nX2,int nY2,int nD,double& a,double& b,double& c); + +//求与直线P1P2相距nD的平行直线的方程,直线在矢量P1P2的左侧(显示器坐标系) +//重要说明: +// 在程序中是按X向右为正,Y向上为正的坐标系计算的,故所求直线是在矢量P1P2的右侧 +//输入参数: +// ptPoint1,ptPoint2 直线P1P2的两点 +// nD 所求直线和给定直线P1P2的距离 +//输出参数: +// 当ptPoint1,ptPoint2不是同一点时返回true, a,b,c 所求得的直线:ax+b*y+c=0 +// 当ptPoint1,ptPoint2是同一点时返回fasle. +BOOL LineParallel(CPoint ptPoint1,CPoint ptPoint2,int nD,double& a,double& b,double& c); + +//求一条点链的边界矩形 +CRect GetRectOfListPoint(CList& listPoint); + +//求两个整数的公约数 +//输入参数 +// nNum1,nNum2 两个需要求公约数的整数 +//返回值: +// nNum1,nNum2的公约数(若nNum1,nNum2中有0时返回1) +int CommomDivisor(int nNum1,int nNum2); + +//判断一点是否在两点之间 +//输入参数: +// ptPoint +// ptPointS +// ptPointE +//返回值: +// 若ptPoint在ptPointS_ptPointE之间返回true,否则false. +BOOL BetweenTwoPoint(CPoint ptPoint,CPoint ptPointS,CPoint ptPointE); + +//判断一点是否在折线的两点之间 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// ptPoint +// ptPointS +// ptPointE +// listPolyline1 +//输出参数: +// listPolyline2 ptPointS_ptPointE之间的折线. +//返回值: +// 若ptPoint在折线的ptPointS_ptPointE之间返回true,否则false. +BOOL BetweenTwoPointAtPolyline(int iDPMM,CPoint ptPoint,CPoint ptPointS,CPoint ptPointE,CList &listPolyline1,CList &listPolyline2); + +//求折线上两点间的长度 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// ptPointS,ptPointE 折线上的两点 +// listPolyline 折线 +//返回值: +// 两点间的长度 +int Get2PLengthOfPolyline(int iDPMM,CPoint ptPointS,CPoint ptPointE,CList &listPolyline); + +//求折线的长度 +//输入参数: +// listPolyline 折线 +//返回值: +// 折线长度 +int GetLengthOfPolyline(CList &listPolyline); + +//求折线的长度 +//输入参数: +// listPolyline 折线 +//输出参数: +// dLength 折线长度的双精度值 +//返回值: +// 折线长度 +int GetLengthOfPolyline(CList &listPolyline,double &dLength); + +//求多边形的长度 +//输入参数: +// listPolygon 多边形 +//返回值: +// 多边形长度 +int GetLengthOfPolygon(CList &listPolygon); + +//求多边形的长度 +//输入参数: +// listPolygon 多边形 +//输出参数: +// dLength 多边形长度的双精度值 +//返回值: +// 多边形长度 +int GetLengthOfPolygon(CList &listPolygon,double &dLength); + +//求两点距离 +//返回值: +// 两点间的距离 +int TwoPointLength(CPoint ptPoint1,CPoint ptPoint2); + +//求两点距离 +//输出参数: +// dLength 两点间距离的双精度值 +//返回值: +// 两点间的距离 +int TwoPointLength(CPoint ptPoint1,CPoint ptPoint2,double &dLength); + +//求两点距离 +double TwoPointLength(CDBLPoint pDBLPoint1,CDBLPoint pDBLPoint2); + +//判断某点所处的象限 +//输入参数: +// ptPoint 给定点 +//返回值: +// 1:1象限,2:2象限,3:3象限,4:4象限 +int GetQuadrant(int x,int y); + +//将多边形中被折线截断的部分去掉 +//该函数用于计算衣片的填充轮廓线和切割轮廓线 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolygon 多边形 +// listPolyline 折线 +//输出参数: +// listPolygon 多边形 +//返回值: +// true 成功,否则false. +BOOL PolygonRemovePolyline(int iDPMM,CList &listPolygon,CList &listPolyline); + +//求点链listPoint中与ptPointS_ptPointE同向(从ptPointS到ptPointE),且距离ptPointE最近的点ptPoint +BOOL GetEquidireectionalPoint(CPoint ptPointS,CPoint ptPointE,CList &listPoint,CPoint &ptPoint); + +//判断两点(ptPoint1,ptPoint2)是否在直线ptPointLS_ptPointLE的同侧 +//输入参数: +// ptPoint1,ptPoint2 给定两点 +// ptPointLS,ptPointLE 直线的两点 +//返回值: +// true 同侧,false 异侧 +BOOL IsSameSide(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPointLS,CPoint ptPointLE); + +//判断点链listPoint是否在直线ptPointLS_ptPointLE的同侧 +//入口: +// listPoint 给定点链 +// ptPointLS,ptPointLE 直线的两点 +//返回值: +// true 同侧,false 异侧 +BOOL IsSameSide(CList &listPoint,CPoint ptPointLS,CPoint ptPointLE); + +//判断平行的直线ptPoint1_ptPoint2和ptPoint3_ptPoint4, +//其矢量方向ptPoint1→ptPoint2和ptPoint3→ptPoint4是否相同. +//特别说明:在2009年11月11日前要求ptPoint1_ptPoint2和ptPoint3_ptPoint4必须是平行线.之后改成矢量ptPoint1→ptPoint2和ptPoint3→ptPoint4的夹角不大于一个指定角度 +//输入参数: +// ptPoint1 +// ptPoint2 +// ptPoint3 +// ptPoint4 +// dCosMaxAngle 判断矢量ptPoint1→ptPoint2和ptPoint3→ptPoint4同向的最大允许夹角余弦,(原本默认值为1度的余弦,20130827之后要求传入余弦值) +//返回值: +// true 相同,false 相反. +BOOL IsSameDirection(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint ptPoint4,double dCosMaxAngle); + +//[20130827]恢复20091111之前的函数 +// 因为在绝大多数情况下,输入变量已经是平行的,只需要判断它们的方向是否相同,无需使用角度判断 +// 本次修改由杭州卓尚的<>文件引起,其中计算101版本缝份时,两条矢量的交点明明存在,但是使用该函数判断时(默认用1度的余弦值)判断失败,因为角度=1.83度 +BOOL IsSameDirection(CPoint ptPoint1,CPoint ptPoint2,CPoint ptPoint3,CPoint ptPoint4); + +//判断点ptPoint是否在矩形(ptPoint1,ptPoint2)中 +//输入参数: +// ptPoint 给定点 +// ptPoint1,ptPoint2 矩形对角线 +//返回值: +// true 在矩形内,false 不在矩形内 +BOOL PointInRect(CPoint ptPoint,CPoint ptPoint1,CPoint ptPoint2); + +//将数字字符串小数点后面无用的0或小数点去掉 +void TrimAfterDot0(CString &strNum); +//将字符串第1个字符前的回车换行去掉 +CString TrimHeadCRLF(CString string); +//将字符串最后1个字符后的回车换行去掉 +CString TrimTailCRLF(CString string); + +//判断ptPoint是否在矢量ptPointS→ptPointE的左边(显示器坐标) +//返回值: +// =true 在左边(显示器坐标)或在矢量ptPointS→ptPointE上,=false 在右边(显示器坐标) +BOOL IsLeftPoint(CPoint ptPoint,CPoint ptPointS,CPoint ptPointE); +//判断ptPoint是否在多边形(矢量方向是多边形的起点到终点)的左边(显示器坐标) +//返回值: +// =true 在左边(显示器坐标)或在多边形上,=false 在右边(显示器坐标) +BOOL IsLeftPoint(CPoint ptPoint,CList &listPolyline); + +//包括两点的矩形 +//输入参数: +// ptPoint1 +// ptPoint2 +//返回值: +// 包括两点的矩形 +CRect RectOfContainTowPoint(CPoint ptPoint1,CPoint ptPoint2); + +//包括点链的矩形 +//输入参数: +// listPolyline 点链 +//返回值: +// 包括点链的矩形 +CRect RectOfPolyline(CList &listPolyline); + +//包括圆弧的矩形,圆弧是指按逆时针方向(显示器坐标,若X向右为正,Y向上为正,则是顺时针方向)由起点到终点所经过的部分 +//输入参数: +// ptLeftUp,ptRightDown 圆弧限定矩形的左上角和右下角(显示器坐标) +// ptPointS,ptPointE 圆弧的起点和终点 +//返回值: +// 包括圆弧的矩形 +CRect RectOfContainArc(CPoint ptLeftUp,CPoint ptRightDown,CPoint ptPointS,CPoint ptPointE); + +//文字占用的区域大小 +CSize StringSize(LOGFONT lfFont,CString string); +//文字占用的区域大小 +CSize StringSize(CDC *pDC,CString string); +//文字占用的区域大小及行数 +CSize StringSize(CDC *pDC,CString string,int &nLines); +//文字占用的区域 +//输入参数: +// lfFont 显示的字体 +// string 显示的文字 +// ptLU 显示的左上角位置 +// dScale 计算算时需要将字体的高度、宽度缩小的比例,主要是为了防止高度、宽度的值太大计算超界 +//输出参数: +// ptLD 左下角位置 +// ptRU 右上角位置 +// ptRD 右下角位置 +//返回值: +// 文字占用的区域大小 +CSize StringRgnLU(LOGFONT lfFont,CString string,CPoint &ptLU,CPoint &ptLD,CPoint &ptRU,CPoint &ptRD,double dScale=1.0); +//文字占用的区域 +//输入参数: +// lfFont 显示的字体 +// string 显示的文字 +// ptLD 显示的左下角位置 +// dScale 计算算时需要将字体的高度、宽度缩小的比例,主要是为了防止高度、宽度的值太大计算超界 +//输出参数: +// ptLU 左上角位置 +// ptRU 右上角位置 +// ptRD 右下角位置 +//返回值: +// 文字占用的区域大小 +CSize StringRgnLD(LOGFONT lfFont,CString string,CPoint &ptLU,CPoint &ptLD,CPoint &ptRU,CPoint &ptRD,double dScale=1.0); +//获取string的行数 +int StringLines(CString string); +//获取string第nLineIndex行的字符(起始行的nLineIndex为0) +CString GetSubString(CString string,int nLineIndex); + +//求多边形的面积 +//输入参数: +// listPolygon 多边形点链 +double AreaOfPloygon(CList &listPolygon); + +//判断线段和矩形是否相交 +//输入参数: +// rect 给定矩形 +// ptPointS_ptPointE 给定线段 +//输出参数: +// ptPointS,ptPointE 截取的线段(ptPointS_ptPointE) +//返回值: +// true 线段和矩形相交, false 线段和矩形不相交. +BOOL IntersectLineRect(CRect rect,CPoint &ptPointS,CPoint &ptPointE); + +//判断线段和矩形是否相交 +//输入参数: +// rect 给定矩形 +// ptPointS_ptPointE 给定线段 +//输出参数: +// ptPointS,ptPointE 截取的线段(ptPointS_ptPointE) +//返回值: +// true 线段和矩形相交, false 线段和矩形不相交. +BOOL IntersectLineRect(CRect rect,int &nXS,int &nYS,int &nXE,int &nYE); + +//判断折线和矩形是否相交 +//输入参数: +// rect 给定矩形 +// listPolyline 给定折线 +//返回值: +// true 折线和矩形相交, false 折线和矩形不相交. +BOOL IntersectPolylineRect(CList &listPolyline,CPoint ptPointS,CPoint ptPointE); + +//判断矩形是否可以框选到折线 +//输入参数: +// rect 框选的矩形 +// listPolyline 折线 +//返回值: +// true 可以框选到矩形 +// false 矩形框选不到折线 +BOOL IntersectPolylineRect(CRect rect,CList &listPolyline); + +//在点链listPoint中,从头到尾进行搜索,判断ptPoint1的最近点是否在ptPoint2的最近点前面(不一定是直接前趋) +//注意:如ptPoint1,ptPoint2不在点链中,则加入到点链中. +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPoint +// ptPoint1 +// ptPoint2 +//返回值: +// true ptPoint1的最近点在ptPoint2的最近点前面, +// false ptPoint1的最近点在ptPoint2的最近点前面. +BOOL IsPrevPoint(int iDPMM,CList &listPoint,CPoint ptPoint1,CPoint ptPoint2); + +//20140504 XQ 以ptPointO原点,将ptExtend拉到ptExtendToPoint时,与ptPointOld对应的拉伸ptPointNew +//该函数同时对弦高和弦长两个方向进行拉伸 +void Extend(CPoint ptPointO,CPoint ptExtend,CPoint ptExtendToPoint,CPoint ptPointOld, CPoint &ptPointNew); + +//以ptPointO原点,将ptExtend拉到ptExtendToPoint时,与listPointOld对应的拉伸listPointNew +//该函数同时对弦高和弦长两个方向进行拉伸 +void Extend(CPoint ptPointO,CPoint ptExtend,CPoint ptExtendToPoint,CList &listPointOld,CList &listPointNew); +//以ptPointO原点,将ptExtend拉到ptExtendToPoint时,与listPointOld对应的拉伸listPointNew +//该函数仅对弦长方向进行拉伸 +void ExtendInWidth(CPoint ptPointO,CPoint ptExtend,CPoint ptExtendToPoint,CList &listPointOld,CList &listPointNew); + +//查找点链listPoint中与ptPoint距离最近的点 +CPoint NearestPoint(CPoint ptPoint,CList &listPoint,int &nDistance); + +//查找点链listPoint1的点与listPoint2的点距离最近的两点 +//输入参数: +// listPoint1 +// listPoint2 +//输出参数: +// ptPoint1 该点在listPoint1上 +// ptPoint2 该点在listPoint2上 +//返回值: +// ptPoint1与ptPoint2的距离 +int NearestPoint(CList &listPoint1,CList &listPoint2,CPoint &ptPoint1,CPoint &ptPoint2); + +//求折线中某一点的垂线ax+by+c=0 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPolyline +// ptPoint +// dMinLength 确定切线的最短距离 +//输出参数: +// a,b,c 直线方程 +BOOL VerticalLineOfPloyline(int iDPMM,CList &listPolyline,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); +BOOL VerticalLineOfPloygon(int iDPMM,CList &listPolygon,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); + +//求折线中某一点的切线ax+by+c=0 +//输入参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +BOOL TangentOfPloyline(int iDPMM,CList &listPolyline,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); +BOOL TangentOfPloygon(int iDPMM,CList &listPolyline,CPoint ptPoint,double dMinLength,double &a,double &b,double &c); + +//切割时对矩形排序 +//输入参数: +// listRectOld 没有排序的矩形 +// nDistance 排序的冗余大小 +//输出参数: +// listRectNew 排好序的矩形 +void CuttingSort(CList &listRectOld,int nDistance,CList &listRectNew); + +//计算加入一个新点后形成的新矩形 +//输入参数: +// ptPoint 给定的新点 +// nLeft,nTop,nRight,nBottom 旧的矩形 +//输出参数: +// nLeft,nTop,nRight,nBottom 新的矩形 +void GetNewRect(CPoint ptPoint,int &nLeft,int &nTop,int &nRight,int &nBottom); + +//判断点链是否在一直线上 +//输入参数: +// listPoint 点链 +// dMaxError 高度误差 +//返回值: +// true 在一条直线上 +BOOL AllPointAtLine(CList &listPoint,double dMaxError); + +//找水平垂直线 +//如果直线ptPointS_ptPointE与水平垂直线的角度小于dMaxAngle,则计算ptPointE在水平垂直线上的最近距离点ptPointHV +//输入参数: +// ptPointS,ptPointE 直线点 +// dMaxAngle 最大角度误差,单位:度 +//输出参数: +// ptPointHV +//返回值: +// true 在给定的角度误差内有水平垂直线 +BOOL HVLine(CPoint ptPointS,CPoint ptPointE,double dMaxAngle,CPoint &ptPointHV); + +//反求样条曲线的控制点. +//参数: +// iDPMM [输入]长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPoint +// 点链 +// listCtrl +// [输入][输出]控制点链,如果反求控制点成功,那么可以使用该参数有效否则无效 +// dSplineError +// 计算样条曲线时的最大误差 +// dMaxError +// 反求控制点链时的最大误差 +// (bHeadTangent,ptHeadTangent) +// bHeadTangent=TRUE,有前切线点,此时ptHeadTangent有效;bHeadTangent=FALSE,没有前切线点,此时忽略ptHeadTangent的值 +// (bTailTangent,ptTailTangent) +// bTailTangent=TRUE,有后切线点,此时ptTailTangent有效;bTailTangent=FALSE,没有后切线点,此时忽略ptTailTangent的值 +// bNatrual +// =TRUE,自然样条;=FALSE,抛物线样条,20170406 syf,将默认值改为true +// bExactSolution +// =TRUE,求解精确解;=FALSE,如果不能求解精确解,那么尝试放大点阈值求解 +BOOL CalculateSplineCtrlPoint(int iDPMM,CList& listPoint, CList& listCtrl, double dSplineError, double dMaxError, + BOOL bHeadTangent = FALSE,CPoint ptHeadTangent = CPoint(0,0),BOOL bTailTangent = FALSE, + CPoint ptTailTangent = CPoint(0,0),BOOL bNatrual = TRUE, BOOL bExactSolution = TRUE); + +//对每一段等分反求样条曲线的控制点(segment divide) +//参数: +// listPoint +// 点链 +// listCtrl +// [输入][输出]控制点链,如果反求控制点成功,那么可以使用该参数有效否则无效 +// dSplineError +// 计算样条曲线时的最大误差 +// dMaxError +// 反求控制点链时的最大误差 +// (bHeadTangent,ptHeadTangent) +// bHeadTangent=TRUE,有前切线点,此时ptHeadTangent有效;bHeadTangent=FALSE,没有前切线点,此时忽略ptHeadTangent的值 +// (bTailTangent,ptTailTangent) +// bTailTangent=TRUE,有后切线点,此时ptTailTangent有效;bTailTangent=FALSE,没有后切线点,此时忽略ptTailTangent的值 +// bNatrual +// =TRUE,自然样条;=FALSE,抛物线样条,20170406 syf,将默认值改为true +// bExactSolution +// =TRUE,求解精确解;=FALSE,如果不能求解精确解,那么尝试放大点阈值求解 +// dMaxCtrlPointDistance +// 两个控制点间的最大距离 +BOOL CalculateSplineCtrlPoint_SD(CList& listPoint, CList& listCtrl, double dSplineError, double dMaxError, double dMaxCtrlPointDistance, + BOOL bHeadTangent = FALSE,CPoint ptHeadTangent = CPoint(0,0),BOOL bTailTangent = FALSE, + CPoint ptTailTangent = CPoint(0,0),BOOL bNatrual = TRUE, BOOL bExactSolution = TRUE); + +//计算两条链表的距离 +double DistanceOfTwoList(CList& listPoint1, CList& listPoint2); + +//计算一条链表到另一条链表的距离. +double DistanceFromListToList(CList& listPoint1, CList& listPoint2); + +//计算一个点到一条链表的距离. +double DistanceFromPointToList(CPoint point, CList& listPoint); +double DistanceFromPointToList(CPoint point, CPoint* pt, int nArray); + +//计算ptInt在线段ptS→ptE上的参数值 +double PointToParam(CPoint& ptInt, CPoint& ptS, CPoint& ptE); + +//求点到一条线段的垂足. +void GetVerticalPoint(CPoint& ptS, CPoint& ptE, CPoint& ptRes, CPoint& ptDes); + +//求点到一条线段的垂足. +void GetVerticalPoint(CDBLPoint ptDBLPointS, CDBLPoint ptDBLPointE, CDBLPoint ptInput, CDBLPoint& ptOutput); + +//判断两条线段是否平行 +BOOL IsParallel(CPoint& ptS0, CPoint& ptE0, CPoint& ptS1, CPoint& ptE1); + +//添加一个控制点. +BOOL AddOneCtrlPoint(CList& listPoint, CList& listCtrl); + +//根据控制点分割点链. +void DivideListAccordingToCtrlList(CList& listPoint, CList& listCtrl, CArray,CList >& arrayList); + +//计算给定的元素在链表中的索引值 +//参数: +// type +// 元素 +// listType +// 链表 +//返回值: +// >=0 该元素在链表中,该索引值从0开始 +// =-1 该元素不在链表中 +template +int FindIndex(TYPE type, CList& listType) +{ + POSITION pos; + int iResult, i; + + iResult = -1; + i = 0; + pos = listType.GetHeadPosition(); + while (pos != NULL) + { + if (listType.GetAt(pos) == type) + { + iResult = i; + break; + } + else + { + listType.GetNext(pos); + i++; + } + } + + return iResult; +} + +//计算给定元素在数组中的索引值 +//参数: +// type +// 元素 +// (p,nArray) +// 数组及长度 +//返回值: +// >=0 该元素在数组中,该索引值从0开始 +// =-1 该元素不在数组中 +template +int FindIndex(TYPE type, TYPE* p, int nArray) +{ + int iResult, i; + + ASSERT(p != NULL); + iResult = -1; + for (i = 0; i < nArray; i++) + { + if (p[i] == type) + { + iResult = i; + break; + } + } + + return iResult; +} + +//求一条链表的最大偏移距离. +double MaxDistanceOfList(CList& listPoint, CPoint& point); + +//判断点和多边形的关系 +//输入: +// point 点. +// listPoint 点链. +//输出: +// 无. +//返回值: +// =1,点在多边形内部;=0,点在多边形上;=-1,点在多边形外部. +//说明: +// 此处应保证输入的点链是多边形,即:首尾点相同,面积大于0. +int PointInList(CPoint& point, CList& listPoint); +//判断点和多边形的关系. +//输入: +// point 点. +// pt 多边形数组的首指针. +// nArray 多边形的元素个数. +//输出: +// 无. +//返回值: +// =1,点在多边形内部;=0,点在多边形上;=-1,点在多边形外部. +//说明: +// 数组元素应多于2个. +int PointInList(CPoint& point, CPoint* pt, int nArray); + +//合并链表 +//输入: +// listPoint 链表. +//输出: +// listPoint 链表. +//返回值: +// 无. +//说明: +// 如果连续的3个点共线,那么去掉中间的那一个点. +// 此函数应该保证相邻的点不相同,此函数不作判断. +void ComboSegment(CList& listPoint); + +//在一条线段上查找一个纵坐标为给定值的点的横坐标. +//输入: +// 线段(ptS,ptE) +// dY 给定的纵坐标值. +//输出: +// dX 横坐标.点(dX,dY)一定在线段(ptS,ptE)上. +//返回值: +// 无. +//说明: +// 该函数在判断一点是否在多边形内部(PointInList)时调用,在调用此函数之前已经能够保证 +// 求出的结果点一定是落在线段上,而不是在线段的延长线. +void GetHorizonPoint(CPoint& ptS, CPoint& ptE, double& dY, double& dX); + +//计算外积符号 +//输入: +// 向量ptStart→ptEnd,ptStart→ptTemp +//输出: +// 无. +//返回值: +// = 1逆时针, = 0共线, = -1顺时针 +//说明: +// 此函数返回向量ptStart→ptEnd旋转到ptStart→ptTemp是顺时针还是逆时针. +// 如果逆时针旋转是大于180度,那说明是顺时针的. +// 此结果是基于世界坐标系,在屏幕坐标系中结果要取相反的符号. +// 此结果只返回外积的符号,外积在数值上等于这三个点形成三角形的面积的2倍,此面积为有向面积. +int CrossProduct(CPoint& ptStart, CPoint& ptEnd, CPoint& ptTemp); + +//由给定参数,计算线上的一个点. +//输入: +// 线段(ptS, ptE),有方向,原则上首尾点不相同. +// dParam 参数值.计算线上该参数值对应的点. +//输出: 无. +//返回值: +// CPoint点. +//说明: +// 此函数一定会有返回值,当输入的线段首位点相同的时候,直接返回头点坐标. +CPoint ParamToPoint(CPoint ptS, CPoint ptE, double dParam); + +//两多边形是否重叠 +BOOL IsOverlapOfTwoPolygon(CList &listPolygon1,CList &listPolygon2); + +//将一条点链生成一个数组. +//输入: +// listPoint 点链. +//输出: +// pt 数组头指针. +// nListCount 数组元素数目. +//返回值: +// =TRUE,操作成功.=FALSE,操作失败. +//说明: 无. +BOOL MallocFromList(CList &listPoint, CPoint *&pt, int &nListCount); + +//获取两点的中点. +//输入: +// ptS,ptE 两个点. +//输出: +// ptMiddle 中点. +//返回值: 无. +//说明: +// 调用此函数时,输出变量可以与某个输入变量相同. +void GetMiddlePoint(CPoint ptS, CPoint ptE, CPoint &ptMiddle); +CPoint GetMiddlePoint(CPoint ptS, CPoint ptE); +//获取点链的中点 +CPoint GetMiddlePoint(CList& listPoint); + +//计算点链的有向面积 +//特别说明: +// 此面积为有向面积,>0 点链为逆时针(在屏幕上看为顺时针) +//输入参数: +// listPoint 点链 +//返回值: +// 面积 +double Area(CList& listPoint); + +//根据给定长度延长(缩短)一条线段. +//输入: +// (ptS,ptE) 有向线段. +// dLen 给定的线段长度. +//输出: +// ptExtend 延长(缩短)后的线段尾点. +//返回值: 无. +//说明: +// 调用此函数时ptE与ptExtend可以是同一个变量. +// 计算完成时(ptS,ptExtend)的长度为给定长度. +void ExtendSegment(CPoint &ptS, CPoint &ptE, double dLen, CPoint &ptExtend); +CPoint ExtendSegment(CPoint ptS, CPoint ptE, double dLen); + +//计算两线段的交点. +//输入: +// 线段(ptS0,ptE0),(ptS1,ptE1) +//输出: +// ptInt 交点. +//返回值: +// 无. +//说明: +// 每条段的两端都都不应相同. +// 两条线段不应平行,此函数不作判断. +// 交点未必落在线段上.此为两线段所在直接的交点. +void IntPoint(CPoint& ptS0, CPoint& ptE0, CPoint& ptS1, CPoint& ptE1, CPoint& ptInt); + +//计算两条向量夹角的余弦值和正弦值. +//输入: +// (ptS0,ptE0),(ptS1,ptE1) 两条向量. +//输出: +// dCos 夹角的余弦值. +// dSin 夹角的正弦值. +//返回值: +// =TRUE,成功计算.=FALSE,计算失败. +//说明: +// 只有当向量的两个端点退化成同一个点的时候才会计算失败. +// 此夹角是在世界坐标系下计算的. +BOOL RotateAngle(CPoint &ptS0, CPoint &ptE0, CPoint &ptS1, CPoint &ptE1, double &dCos, double &dSin); + +//在给定的点链上找到距离给定点最近的点. +//输入: +// listPoint 点链. +// point 给定的点. +//输出: +// ptNearest 最近点.一定在折线上. +// dLen 最短的距离. +//返回值: +// TRUE,找到了这个最近点.FALSE,没有找到这个最近点.此时不可以使用输出变量. +//说明: +// 调用此函数时,输入变量和输出变量可以相同. +BOOL GetNearestPointOnList(CList &listPoint, CPoint &point, CPoint &ptNearest, double &dMinLen); + +//将源点链数组添加到目标点链数组的尾部. +//输入: +// alRsc 源点链数组. +//输出: +// alDes 目标点链数组. +//返回值: 无. +//说明: 无. +void AddArrayListTail(CArray,CList >& alRsc, CArray,CList >& alDes); + +//计算平行的线段. +//参数: +// (ptS,ptE) +// 线段.一般来说这2个点不能相同. +// (dStartHeight,dEndHeight) +// 两个点各自的平行距离.本函数使用其绝对值,输入时每个长度都可以是0,这两个数值可以不同. +// bClockwise +// 旋转方向.=TRUE,顺时针;=FALSE,逆时针.注意:此处的顺时针是在"世界坐标系"下,与屏幕坐标系方向相反. +// (ptParallelS,ptParallelE) +// [输出]平行之后的两个端点. +//说明: +// 调用本函数时输入变量与输出变量一定要两两不同. +void ParallelSegment(CPoint ptS, CPoint ptE, double dStartHeight, double dEndHeight, BOOL bClockwise, CPoint& ptParallelS, CPoint& ptParallelE); + +//计算平行曲线. +//参数: +// listPoint +// 点链. +// (dHeadHeight,dTailHeight) +// 头点和尾点处的距离.本函数使用其绝对值,并且这两个值可以不相同. +// bClockwise +// 方向.平行后的线在原线的哪一侧.=TRUE,顺时针(也就是屏幕上的左侧);=FALSE,逆时针(也就是屏幕上的右侧).注意:此处的顺时针是在"世界坐标系"下,与屏幕坐标系方向相反. +// listParallel +// [输出]平行之后的曲线. +// dMaxError +// 误差.判断输入的曲线是否为闭合的.如果判断出输入的曲线是闭合,那么将其按照多边形的情况来处理, +// 所以在处理多边形的时候要将其转化成点链传入. +// bRemoveIntersect +// =true 去自交,=false 不去自交 +//说明: +// 在调用本函数的时候,输入变量与输出变量可以相同. +void ParalllelCurve(CList& listPoint, double dHeadHeight, double dTailHeight, BOOL bClockwise, CList& listParallel, double dMaxError = 0.0, BOOL bRemoveIntersect = TRUE); + +//去除自交的折线. +//参数: +// listPoint +// [输入][输出]点链. +// bClose +// 标识点链是否为闭合的. +//说明: +// 如果是闭合的情形,那么按照多边形来求解,选择面积最大的那个.如果是折线的情形,那么则从头点到尾点的方向进行查找. +void RemoveIntersectPolyline(CList& listPoint, BOOL bClose); + +//获取边界内部的点链. +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listPoint +// 点链. +// listBorder +// 边界.头尾点相同也可以,不相同也可以. +// arrayList +// [输出]点链数组.可能有多条曲线,因为输入的点链可能被分割成了多条. +void GetListInBorder(int iDPMM,CList& listPoint, CList& listBorder, CArray,CList >& arrayList); + +//计算等比例的控制点链 +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// (listPoint1,listCtrl1) +// 实际点链以及相对应的控制点链 +// listPoint2 +// 实际点链 +// listCtrl2 +// [输出]listPoint2对应的控制点链,其中的数目与listCtrl1相同,并且其中每个点的位置都是通过点在曲线上的比例来求得的 +void GetProportionCtrlList(int iDPMM,CList& listPoint1, CList& listCtrl1, CList& listPoint2, CList& listCtrl2); + +//从timeStart到timeFinish的时间差 +//输入参数: +// iMillisecondsStart 开始的毫秒数 +// iMillisecondsFinish 结束的毫秒数 +//返回值: +// 持续时间,单位:秒 +double Duration(int iMillisecondsStart,int iMillisecondsFinish); + +//查找给定的点链距离数组中的哪条曲线最近 +//参数: +// listPoint +// 点链,要保证该点链就是从数组中的某条曲线中提取出来的 +// alCurve +// 点链数组 +int FindListIndex(CList& listPoint, CArray,CList >& alCurve); + +//计算垂足在线段上的参数值 +//参数: +// (ptS,ptE) +// 线段,要求这两个点不相同,否则直接返回DBL_MAX +// point +// 点 +//返回值: +// 参数值,若[0,1]则在线段内部 +double GetVerticalParam(CPoint ptS, CPoint ptE, CPoint point); + +//根据给定的虚线长度与间距,定制虚线 +//参数: +// iDPMM +// 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listCurve +// 点链 +// (iDashedLength,iSpaceLength) +// 虚线长度(每一段可见部分的长度),间隙长度(每一段不可见部分的长度),使用其绝对值 +// alCurve +// [输出]点链数组,按照从头到尾的顺序,分段保存可见部分的点链 +void CustomizeDashedLine(int iDPMM, CList& listCurve, int iDashedLength, int iSpaceLength, CArray,CList >& alCurve); + +//计算渐变的自定义虚线 +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// listCurve 点链 +// iDashedLength 画线长度 +// iSpaceLength 空白长度 +// iDashGradualType 画线长度的渐变类型, =0 无, =1 长度渐变, =2比例渐变 +// iDashGradualLength 画线长度的渐变长度,即:前一段的画线长度加上该值等于后一段的画线长度 +// dDashGradualScale 画线长度的渐变比例,即:前一段的画线长度乘以该值等于后一段的画线长度 +// iSpaceGradualType 空白长度的渐变类型, =0 无, =1 长度渐变, =2 比例渐变 +// iSpaceGradualLength 空白长度的渐变长度,即:前一段的空白长度加上该值等于后一段的空白长度 +// dSpaceGradualScale 空白长度的渐变比例,即:前一段的空白长度乘以该值等于后一段的空白长度 +// bAdaptiveStretch =TRUE 自适应拉伸, =FALSE 不拉伸 +// alCurve [输出]点链数组,按照从头到尾的顺序,分段保存可见部分的点链 +void CustomizeGradualDashedLine(int iDPMM, CList& listCurve, int iDashedLength, int iSpaceLength, + int iDashGradualType, int iDashGradualLength, double dDashGradualScale, + int iSpaceGradualType, int iSpaceGradualLength, double dSpaceGradualScale, + BOOL bAdaptiveStretch, CArray,CList >& alCurve); + +//根据给定的曲线,半径,间距计算圆形曲线 +//参数: +// listCurve +// 点链 +// (iRadius,iSpaceLength,dMaxError) +// 半径,圆心距(线上距离),计算圆形的最大逼近误差,若某一个值为0则输出变量为空 +// alPolygon +// [输出]多边形数组,按照从头到尾的顺序,分段保存圆形实际位置 +void CustomizeCircleCurve(CList& listCurve, int iRadius, int iSpaceLength, double dMaxError, CArray,CList >& alPolygon); + +//计算自定义曲线(开口线或者闭合线) +//输入: +// listCurve 开口线 +// alCustomCurveElement 自定义曲线元素 +// bClose =TRUE 闭合线, =FALSE 开口线 +// ptCustomBasePoint 基准点 +// iCustomCurveHeight 高度,若<=0则使用alCustomCurveElement本身的高度 +// iCustomCurveGap 相邻元素的间隔,若<0,则不能超过alCustomCurveElement本身的宽度 +// bAdaptiveStretch =TRUE 自定义拉伸(等比例改变元素的宽度和高度,使得曲线的结束恰好是一个元素的结束), =FALSE 不拉伸(只保留整数部分的元素) +//输出: +// alCurve 计算出的点链 +void CustomizeCurve(CList& listCurve, BOOL bClose, CArray,CList >& alCustomCurveElement, CPoint ptCustomBasePoint, + int iCustomCurveHeight, int iCustomCurveGap, BOOL bAdaptiveStretch, CArray,CList >& alCurve); + +//计算给定点链的最小矩形 +//输入参数: +// listPoint 点链 +//返回值: +// 点链的最小矩形 +//说明: +// 将点链进行旋转求出面积最小矩形,箱包系统中计算纸样规格时即为此种方式 +CRect GetBorderMinRect(CList &listPoint); + +//计算省山并修改边线形状 +//参数: +// listPoint1E,listPoint3E +// [输入]对应于V形省的1E边和3E边,如果是计算锥形省,则对应于14边和35边,计算褶山时也是同样的道理 +// 传入时要求这两条点链的头点是靠近边线的,否则需要将点链翻转,本函数不再判断 +// 同时,还要保证在边线上1->3点长度小于3->1点长度,本函数不再判断 +// [输出]如果计算成功,则根据它们的头点在边线上的最近点,将点链拉伸,并保证头点的坐标一定在边线中 +// listPoint2E +// 两条省腰的中心线,将使用该线头点的切线将对称后的省山截断,若该链表为空,那么将会使用两条省腰中间的直线做截取 +// listBorder +// [输入][输出]边线的实际点链,要求头尾点相同;输出时已经将省山的形状添加进去 +// bClockwise +// =TRUE 顺时针倒向(视觉上的顺时针),即倒向GetNext +// dMaxError +// 判断1点和3点是否在边线上的误差值,如果省腰长度小于该值同样返回FALSE +// ptDartHill +// [输出]省山的尖点位置,计算完成后省山被插入到边线中,但是不知道省山尖点的坐标,将其输出后可以修改褶中心线的形状(因为刀褶也是调用此函数计算褶山的) +BOOL CalculateDartHill(int iDPMM, CList& listPoint1E, CList& listPoint3E, CList& listPoint2E, CList& listBorder, BOOL bClockwise, double dMaxError, CPoint& ptDartHill); + +//计算工字褶褶山并修改边线形状 +//特别说明: +// 刀褶褶山的计算与省相同,调用CalculateDartHill函数即可,本函数按照工字褶的规则计算 +//参数: +// 详见CalculateDartHill函数的变量说明,注意:工字褶不涉及倒向 +BOOL CalculatePleatHill(int iDPMM, CList& listPoint12, CList& listPoint34, CList& listBorder, double dMaxError); + +//获得沿直线 p0p1方向,到p0距离为 dDistance 的点 +CPoint GetPointOnLine(CPoint p0,CPoint p1,double dDistance); + + +//20170222 获取两条曲线的交点 +//[输入] listPoint1,listPoint2 两条点链 +//[输出] ptInt交点 +//[输入] iIntIndex 交点索引, -1返回 GetIntPointOfTwoCurve( int iDPMM, CList& listPoint1, CList& listPoint2, CPoint& ptInt, int iCount)结果 +// 0, 1,2...求出listPoint1,listPoint2的所有交点(本身相交,延长相交),并且按照listPoint1的点连顺序排序, 按照排序顺序输出交点 +//[输入]iCount 迭代的次数,当迭代一次之后就不能再进行迭代了 +//返回值: +// =TRUE 成功求解出了交点 +// =FALSE 求解交点失败,不能使用输出变量中的数据 +//说明: +// 该函数是针对两个不同的平行交点,它们引用的两条曲线相同但是交点不同,新增加的函数 +// iIntIndex为-1表示保持原有的结果;为0, 1,2...时表示需要求所有交点排序输出 +BOOL GetIntPointOfTwoCurve( int iDPMM, CList& listPoint1, CList& listPoint2, CPoint& ptInt, int iIntIndex, int iCount); + +//20170222 获取两条曲线的交点(相交的, 延长相交的),并按照listPoint1排序 +//[20170911 syf]如果两条实际点链的交点>=2个,那么不再延长计算 +//[输入] listPoint1,listPoint2 两条点链 +//[输出] listInt 两条点链所有的交点,交点按照listPoint1排序 +//返回值: +// =TRUE 成功求解出了交点 +// =FALSE 求解交点失败,不能使用输出变量中的数据 +//说明: +//该函数中分三种情况处理 +//1. listPoint1/listPoint2都是非闭合曲线,如果两线有交点,先求出交点,再按两条曲线头尾点分别延长(20170911 syf如果实际点链的交点>=2个,那么不再延长计算) +//2. listPoint1/listPoint2一条非闭合,一条闭合; 先求两条线交点,再求非闭合线的延长线与闭合线交点 +//3. listPoint1/listPoint2都是闭合曲线,直接求两线有交点返回 +BOOL GetIntPointOfTwoCurve_All( int iDPMM, CList& listPoint1, CList& listPoint2, CList& listInt); + +//20130717 获取两条曲线的交点 +//[输入] listPoint1,listPoint2 两条点链 +//[输出] ptInt交点 +//[输入]iCount 迭代的次数,当迭代一次之后就不能再进行迭代了 +//返回值: +// =TRUE 成功求解出了交点 +// =FALSE 求解交点失败,不能使用输出变量中的数据 +//说明: +// 包含延长相交 +BOOL GetIntPointOfTwoCurve(int iDPMM, CList& listPoint1, CList& listPoint2, CPoint& ptInt, int iCount); + + +//20130717 求解延长后的交点 +//[输入] ptStart,ptEnd 向量,有方向 +//[输入] listPoint 点链,在这条点链上求解交点,如果没有则尝试延长头尾点来进行 +//[输出] ptInt 交点坐标,如果有多个交点那么只输入其中的任意一个 +//返回值: +// =TRUE 求解成功,可以使用输出变量中的数据 +// =FALSE 求解失败,不能使用输出变量中的数据 +BOOL GetExtendInt(int iDPMM, CPoint ptStart, CPoint ptEnd, CList& listPoint, CPoint& ptInt); + +//20170223求解延长后的交点 +//[输入] ptStart,ptEnd 向量,有方向 +//[输入] listPoint 点链,在这条点链上求解交点,如果没有则尝试延长头尾点来进行 +//[输出] listInt 交点坐标 +//返回值: +// =TRUE 求解成功,可以使用输出变量中的数据 +// =FALSE 求解失败,不能使用输出变量中的数据 +BOOL GetExtendInt(int iDPMM, CPoint ptStart, CPoint ptEnd, CList& listPoint, CList& listInt); + +//20130718 根据给定两点在给定的曲线上截取一段 20140427 增加一个输出值 +//[输入]ptPointS, ptPointE 截取曲线的头尾点 +//[输入][输出]listPoint 输入:原始曲线;输出:截取之后的曲线 +//[输出] listPointMax 最长点链 +//说明: +// ptPointS点可能为截取后的曲线的头点或者尾点 +//如果ptPointS和ptPointE相等返回原曲线 +//如果ptPointS或者ptPointE只有一个不在曲线上,根据在曲线上的将曲线分成两段,按另外一个点与曲线头尾点距离(按距离小的)得到需要段 +//如果ptPointS和ptPointE都不在曲线上,按加入点链处理 +//如果ptPointS和ptPointE都不在曲线上并且在曲线的同边,返回点链只有ptPointS和ptPointE两点 +//最长点链的计算listPointMax +//如果ptPointS, ptPointE都在点链上,返回listPoint; +//如果有一个在点链上,返回:listPoint加上那个不在点链上的点 +//如果两个都不在点链上, 两个在点链的异侧,返回:将两个点加到listPoint头尾,返回 +// 两个在点链的异侧,将两个点同时加入头部或者尾部,返回 +void GetCurveSegment(int iDPMM, CPoint ptPointS, CPoint ptPointE, CList& listPoint, CList& listPointMax); + +//20130815 XQ 计算展开的终点 +//参数: +// (ptUp,ptDown) +// 展开前的起止点 +// (iUpWidth,iDownWidth) +// 上下展开量,使用其绝对值,任何一个宽度都可以为0 +// bClockWise +// =TRUE,顺时针旋转;=FALSE,逆时针旋转.此旋转为世界坐标系下,与屏幕坐标系的方向相反 +// 该方向表示,如果宽度为正数,那么展开的结果应该出现在ptUp->ptDown的bClockWise那一侧,如果宽度为负数,则要反向 +// (ptSpreadUp,ptSpreadDown) +// [输出]展开后的起止点,调用本函数的时候这两个参数一定不能与输入的(ptUp,ptDown)使用相同的变量 +// bAllowNegativeWidth +// =true 允许宽度为负数,=false 不允许,强制按照正数计算(数据结构中计算褶展开就是强制展开,所以该变量的默认值是false,20180123 syf添加此变量) +void CalculateSpreadEndPoint(CPoint ptUp, CPoint ptDown, int iUpWidth, int iDownWidth, BOOL bClockWise, CPoint& ptSpreadUp, CPoint& ptSpreadDown, BOOL bAllowNegativeWidth = FALSE); + +//判断给定点是否在点链内(给定点是否在点链的某一线段上) +//参数: +// iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +// ptPoint 给定的点 +// listPoint 给定点链 +//返回值: +// =TRUE 点在点链内 +BOOL PointInPolyline(int iDPMM, CPoint ptPoint, CList& listPoint); + + +//20160718 XQ 根据listRefPoint对listSortPoint排序 +//[输入] iDPMM 长度分辨率(一个内部单位即为1/iDPMM毫米) +//[输入] listRefPoint 参考点链 +//[输入][输出] listSortPoint 需要排序的点链 +//说明: +// 将listSortPoint中的点链按照listRefPoint的顺序排放,listSortPoint的点可能不在listRefPoint上 +void SortIntPoint(int iDPMM, CList &listRefPoint, CList &listSortPoint); + +//交换两个TYPE +template +void Swap(TYPE& p1, TYPE& p2) +{ + TYPE p3; + + p3 = p1; + p1 = p2; + p2 = p3; +} + +//交换两条链表 +template +void Swap(CList& list1, CList& list2) +{ + CList list3; + + list3.RemoveAll(); + list3.AddTail(&list1); + list1.RemoveAll(); + list1.AddTail(&list2); + list2.RemoveAll(); + list2.AddTail(&list3); +} + +//设置数组值 +// [输入] Value 设置值 +// [输入][输出] arrayValue 数组 +// [输入] iCount 数据大小 +// 说明: +// 将数组中的每个值都设置位给定值 +template +void SetSameValue(TYPE Value, CArray &arrayValue, int iCount) +{ + int iIndex; + + arrayValue.RemoveAll(); + arrayValue.SetSize(iCount); + for (iIndex = 0; iIndex < iCount; iIndex++) + { + arrayValue[iIndex] = Value; + } +} +//判断数组中每个值是否都相等 +// [输入] arryValue 数组 +//返回值: +// =true 数组中每个值都相等; +// =false 至少存在一个值不相等 +//说明: +// 数组为空时返回False, 数组只有一个值返回True +template +BOOL IsSameValue(CArray &arryValue) +{ + BOOL bEqual; + int iIndex, iCount; + TYPE Value; + + bEqual = TRUE; + iCount = arryValue.GetSize(); + if (iCount == 0) + { + return FALSE; + } + if (iCount == 1) + { + return TRUE; + } + + Value = arryValue[0]; + for (iIndex = 1; (iIndex < iCount) && bEqual; iIndex++) + { + if (Value != arryValue[iIndex]) + { + bEqual = FALSE; + } + } + + return bEqual; +} + +//判断两个数组是否完全相等 +// [输入] arryValue1 数组 +// [输入] arryValue2 数组 +//返回值: +// =true 两个数组中对应的每个值都相等; +// =false 至少存在一个值不相等 +template +BOOL IsSameValue(CArray &arryValue1, CArray &arryValue2) +{ + BOOL bEqual; + int iIndex, iCount; + + bEqual = TRUE; + if (arryValue1.GetSize() != arryValue2.GetSize()) + { + return FALSE; + } + iCount = arryValue1.GetSize(); + if (iCount == 0) + { + return TRUE; + } + + for (iIndex = 0; (iIndex < iCount) && bEqual; iIndex++) + { + if (arryValue1[iIndex] != arryValue2[iIndex]) + { + bEqual = FALSE; + } + } + + return bEqual; +} +//拷贝数据,将原数组中数据拷贝到目标数组中 +// [输入] arryValueSrc 原数组 +// [输入][输出] arryValueDes 目标数组 +template +void CopyData(CArray &arryValueSrc, CArray &arryValueDes) +{ + int iIndex, iCount; + + arryValueDes.RemoveAll(); + iCount = arryValueSrc.GetSize(); + for (iIndex = 0; iIndex < iCount; iIndex++) + { + arryValueDes.Add(arryValueSrc[iIndex]); + } +} + +//在给定的数据中找一个最大值 +// [输入] arryValue 数组 +//返回值: +// 数组中最大值,如果数组中没有值返回0 +template +TYPE FindMaxCount(CArray &arryValue) +{ + int iIndex, iCount; + TYPE MaxValue; + + iCount = arryValue.GetSize(); + if (iCount == 0) + { + return 0; + } + MaxValue = arryValue[0]; + for (iIndex = 1; iIndex < iCount; iIndex++) + { + if (MaxValue < arryValue[iIndex]) + { + MaxValue = arryValue[iIndex]; + } + } + + return MaxValue; +} + +//计算扣眼位置 +//特别说明: +// 该函数也可以用来计算钻孔 +//输入参数: +// ptPoint 给定点 +// dAngle 扣眼与X轴的角度(显示器坐标,逆时针方向为正),单位:度 +// ptButtonHoleS 旋转角度为0时的扣眼S点 +// ptButtonHoleE 旋转角度为0时的扣眼E点,SE点构成了默认的扣眼方向(一般来说这是一条水平线) +//返回值: +// 线段,m_ptPointS表示扣眼的定位位置,m_ptPointE表示扣眼的方向 +CLineSegment CalculateButtonHolePosition(CPoint ptPoint, double dAngle, CPoint ptButtonHoleS, CPoint ptButtonHoleE); + +//计算扣眼位置 +//输入参数: +// iDPMM 分辨率 +// listCurve 曲线实际点链 +// bClose =true 闭合线,=false 开口线 +// iLocateType 定位类型,=0 等距,=1 不等距 +// bNext =true 从ptPointH往GetNext的方向加扣眼,=false 从ptPointH往GetPrev的方向加扣眼 +// iGroupCount 扣眼组数 +// ptPointH 头点:等距时,从ptPointH~ptPointT加扣眼,不等距时,从ptPointH沿着bNext方向加扣眼 +// iDistanceH 第一个扣眼与ptPointH的距离 +// ptPointT 尾点:仅等距时有效 +// iDistanceT 最后一个扣眼与ptPointT的距离,仅等距时有效 +// bOnFirst =true 包括ptPointH往后iDistanceH处的扣眼,=false 不包括 +// bOnLast =true 包括ptPointT往前iDistanceT处的扣眼,=false 不包括 +// iSubCount 每小组的钻孔个数 +// iSubGap 每个小组相邻两个间的间距 +// listGap 各码扣眼间的间距,间距必须 > 0 !!! +// [i]是该码第i个与第i-1个间的距离,故各码扣眼间距个数比各码的扣眼数少1个 !!! +// 非等距,且个数>1时有效 +// bFixAngle =true 与后向切线成固定角度 +// dAngle 扣眼与X轴的角度(显示器坐标,逆时针方向为正),单位:度 +// ptButtonHoleS 旋转角度为0时的扣眼S点 +// ptButtonHoleE 旋转角度为0时的扣眼E点,SE点构成了默认的扣眼方向(一般来说这是一条水平线) +//输出参数: +// listLineSegment 线段链表,m_ptPointS表示扣眼的定位位置,m_ptPointE表示扣眼的方向 +void CalculateButtonHolePosition( + int iDPMM, CList& listCurve, BOOL bClose, int iLocateType, BOOL bNext, int iGroupCount, + CPoint ptPointH, int iDistanceH, CPoint ptPointT, int iDistanceT, BOOL bOnFirst, BOOL bOnLast, + int iSubCount, int iSubGap, CList& listGap, BOOL bFixAngle, double dAngle, + CPoint ptButtonHoleS, CPoint ptButtonHoleE, CLineSegmentList& listLineSegment); + +//计算扣眼位置(带有偏移量) +//输入参数: +// iDPMM 分辨率 +// listCurve 曲线实际点链,这是主线 +// bClose =true 闭合线,=false 开口线 +// iOffsetCount 扣眼的排数,表示一共有几排扣眼 +// bOffsetLeft =true 扣眼位于主线的左侧(显示器坐标系),=false 右侧 +// iOffsetDistance 第一排扣眼与主线的间距,若<0则位于bOffsetLeft的反方向 +// iOffsetGapS 第二排扣眼与第一排扣眼的间距,若<0则位于bOffsetLeft的反方向 +// iOffsetGapE 最后一排扣眼与倒数第二排扣眼的间距,若不等于iOffsetGapS则成为渐变效果 +// iLocateType 定位类型,=0 等距,=1 不等距 +// bNext =true 从ptPointH往GetNext的方向加扣眼,=false 从ptPointH往GetPrev的方向加扣眼 +// iGroupCount 扣眼组数 +// ptPointH 头点:等距时,从ptPointH~ptPointT加扣眼,不等距时,从ptPointH沿着bNext方向加扣眼 +// iDistanceH 第一个扣眼与ptPointH的距离 +// ptPointT 尾点:仅等距时有效 +// iDistanceT 最后一个扣眼与ptPointT的距离,仅等距时有效 +// bOnFirst =true 包括ptPointH往后iDistanceH处的扣眼,=false 不包括 +// bOnLast =true 包括ptPointT往前iDistanceT处的扣眼,=false 不包括 +// iSubCount 每小组的钻孔个数 +// iSubGap 每个小组相邻两个间的间距 +// listGap 各码扣眼间的间距,间距必须 > 0 !!! +// [i]是该码第i个与第i-1个间的距离,故各码扣眼间距个数比各码的扣眼数少1个 !!! +// 非等距,且个数>1时有效 +// bFixAngle =true 与后向切线成固定角度 +// dAngle 扣眼与X轴的角度(显示器坐标,逆时针方向为正),单位:度 +// ptButtonHoleS 旋转角度为0时的扣眼S点 +// ptButtonHoleE 旋转角度为0时的扣眼E点,SE点构成了默认的扣眼方向(一般来说这是一条水平线) +//输出参数: +// alLineSegment 线段链表的数组,其长度等于iOffsetCount,m_ptPointS表示扣眼的定位位置,m_ptPointE表示扣眼的方向 +void CalculateButtonHolePosition( + int iDPMM, CList& listCurve, BOOL bClose, int iOffsetCount, BOOL bOffsetLeft, int iOffsetDistance, int iOffsetGapS, int iOffsetGapE, + int iLocateType, BOOL bNext, int iGroupCount, CPoint ptPointH, int iDistanceH, CPoint ptPointT, int iDistanceT, BOOL bOnFirst, BOOL bOnLast, + int iSubCount, int iSubGap, CList& listGap, BOOL bFixAngle, double dAngle, CPoint ptButtonHoleS, CPoint ptButtonHoleE, CLineSegmentListArray& alLineSegment); + +//计算平行线上的对应点 +//输入参数: +// iDPMM 分辨率 +// listCurve 曲线的实际点链 +// bClose =true 闭合线,=false 开口线 +// ptPoint 曲线listCurve上的一个点,未必在链表内 +// 如果等于开口线listCurve的头点,那么直接返回listParallel的头点,同理返回尾点 +// listParallel 曲线listCurve的平行线 +//输出参数: +// ptParallel 与ptPoint对应的点,根据角平分线计算交点而得来 +//返回值: +// =true 计算成功,=false 计算失败 +BOOL CalculateParallelPoint(int iDPMM, CList& listCurve, BOOL bClose, CPoint ptPoint, CList& listParallel, CPoint& ptParallel); + +//判断两个点是否为同一点 +//特别说明: +// (1)由于舍入误差导致的两个点坐标不同,它们应该被视为同一个点,dxdy通常不会超过1 +// (2)判断标准为CONST_SAME_POINT_ERROR,详见该宏定义的说明文字 +// (3)本函数默认使用CONST_SAME_POINT_ERROR做判断,也可以传入误差值 +//输入参数: +// ptPoint1 点1 +// ptPoint2 点2 +// dSamePointError 判断两个点相等的误差值,<=该值的点认为是同一个 +// >0 直接使用该值做判断 +// =0 坐标完全相等的点才是同一个,否则不是 +// <0 本函数自动使用 CONST_SAME_POINT_ERROR 做判断 +//返回值: +// =true 两个点视为同一个点,=false 不是 +BOOL PDSIsSamePoint(CPoint ptPoint1, CPoint ptPoint2, double dSamePointError = -1.0); + +//判断两个数组是否形状相同 +//特别说明: +// (1)形状,指的是屏幕上的显示效果,与数组的长度或者链表的长度无关 +// (2)本函数将会把每个数组都转换成线段CLineSegment,然后比较两个输入变量的线段是否完全重合 +// (3)本函数可以判断自定义曲线/花稿元素/钻孔元素是否为同一个 +//输入参数: +// alCurve1 链表数组1 +// alCurve2 链表数组2 +//返回值: +// =true 形状相同,=false 形状不同 +BOOL PDSIsSameShape(CArray,CList >& alCurve1, CArray,CList >& alCurve2); + +//生成全球唯一ID +//特别说明: +// https://blog.csdn.net/dpsying/article/details/21415811 +//返回值: +// 唯一ID,字符串长度=38,例如{77046E66-C274-42CE-85AD-5DCFA5B4D2A5} +CString PDSCreateGUID(void); + +#endif diff --git a/datafile/dxf/dxflib/PDSMath/PDSMathExtern.h b/datafile/dxf/dxflib/PDSMath/PDSMathExtern.h new file mode 100644 index 0000000..78e9e00 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSMathExtern.h @@ -0,0 +1,8 @@ +// PDSMathExtern.h + +#if !defined(PDSMathExtern_h) +#define PDSMathExtern_h + +extern CRect g_rectView; //显示窗口的客户区大小,加入该变量的原因是因为显示字符串时需要确定窗口大小,该大小不能用wglGetCurrentDC(),CDC::GetWindow(),CWnd::GetClientRect(...) + +#endif diff --git a/datafile/dxf/dxflib/PDSMath/PDSMathGlobal.h b/datafile/dxf/dxflib/PDSMath/PDSMathGlobal.h new file mode 100644 index 0000000..bce31fb --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSMathGlobal.h @@ -0,0 +1,8 @@ +// PDSMathGlobal.h + +#if !defined(PDSMathGlobal_h) +#define PDSMathGlobal_h + +CRect g_rectView; //显示窗口的客户区大小,加入该变量的原因是因为显示字符串时需要确定窗口大小,该大小不能用wglGetCurrentDC(),CDC::GetWindow(),CWnd::GetClientRect(...) + +#endif diff --git a/datafile/dxf/dxflib/PDSMath/PDSNurbs.h b/datafile/dxf/dxflib/PDSMath/PDSNurbs.h new file mode 100644 index 0000000..eec8241 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSNurbs.h @@ -0,0 +1,503 @@ +/******************************************************************** +创建日期:2017年3月17日 +文 件 名:PDSNurbs.h +原始作者:孙宇飞 +描 述:非均匀有理B样条 + +修改记录: + 版本号 修改日期 作者 修改内容 +*********************************************************************/ +#ifndef _PDS_NURBS_H_ +#define _PDS_NURBS_H_ + +#include +#include +#include + +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 +{ +public: //扩展的变量 +public: //扩展的方法 + + CPDSNurbsPointList& operator=(CPDSNurbsPointList& rhs); //赋值 + CPDSNurbsPoint& operator[](int iIndex); //根据索引值检索,不可越界 + + //根据listPoint设置this + //特别说明: + // (1)this中每个点z=0,weight=1 + void SetPoint(CList& listPoint); + + //将this的数据输出至listPoint + void GetPoint(CList& 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 +{ +public: //扩展的变量 +public: //扩展的方法 + + CPDSNurbsKnotList& operator=(CPDSNurbsKnotList& rhs); //赋值 + double& operator[](int iIndex); //根据索引值检索,不可越界 + + //根据listKnot设置this + void SetKnot(CList& listKnot); + + //将this的数据输出至listKnot + void GetKnot(CList& 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& listDataPoint, double dMaxError, CList& 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& listDataPoint, double dMaxError, CList& listOutputPoint); + + //根据实际点链反求型值点 + //输入参数: + // listOldPoint 旧的实际点链 + // listDataPoint 型值点,如果输入时不为空,表示必须经过这些点 + // dSplineError 计算样条曲线的最大误差值 + // dMaxError 反求之后的曲线,与listOldPoint的最大误差值 + // bTangentH =true 头点有切线,=false 头点没有切线 + // ptTangentPointH 头点的切线方向,指的是实际点链GetPrev的方向 + // bTangentT =true 尾点有切线,=false 尾点没有切线 + // ptTangentPointT 尾点的切线方向,指的是实际点链GetNext的方向 + //输出参数: + // listDataPoint 型值点,如果输入时不为空,表示必须经过这些点 + //返回值: + // =true 计算成功,=false 计算失败 + BOOL ReCalculate_DataPoint( + CList& listOldPoint, CList& 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& 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& listOldPoint, CList& 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& listOldPoint); +}; + +#endif // _PDS_NURBS_H_ \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/PDSReadWriteFile.h b/datafile/dxf/dxflib/PDSMath/PDSReadWriteFile.h new file mode 100644 index 0000000..27621d2 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSReadWriteFile.h @@ -0,0 +1,87 @@ +/******************************************************************** +创建日期:2015年11月5日 +文 件 名: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& listData, CString strFileName); +void PDSWriteArrayInt(CString strAppName, CString strKeyName, CArray& arryData, CString strFileName); + +//写入双精度链表 +void PDSWriteListDouble(CString strAppName, CString strKeyName, CList& listData, CString strFileName); +//写入双精度数组 +void PDSWriteArrayDouble(CString strAppName, CString strKeyName, CArray& arryData, CString strFileName); +//写入点链 +void PDSWriteListPoint(CString strAppName, CString strKeyName, CList& listPoint, CString strFileName); + +//写入颜色链表 +void PDSWriteListColor(CString strAppName, CString strKeyName, CList& 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& listData, CString strFileName); +void PDSReadArrayInt(CString strAppName, CString strKeyName, CArray& arryData, CString strFileName); + +//读取双精度链表 +void PDSReadListDouble(CString strAppName, CString strKeyName, CList& listData, CString strFileName); +//读取双精度数组 +void PDSReadArrayDouble(CString strAppName, CString strKeyName, CArray& arryData, CString strFileName); +//读取点链 +void PDSReadListPoint(CString strAppName, CString strKeyName, CList& listPoint, CString strFileName); + +//读取字符串链表 +void PDSReadListString(CString strAppName, CString strKeyName, CList& listString, CString strFileName); +//写入字符串链表 +void PDSWriteListString(CString strAppName, CString strKeyName, CList& 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& listColor, CString strFileName); + +#endif \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/PDSUID.h b/datafile/dxf/dxflib/PDSMath/PDSUID.h new file mode 100644 index 0000000..490d995 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSUID.h @@ -0,0 +1,106 @@ +/******************************************************************** +创建日期:2018年6月9日 +文 件 名:PDSUID.h +原始作者:孙宇飞 +描 述:唯一ID类 + +修改记录: + 版本号 修改日期 作者 修改内容 +*********************************************************************/ +#ifndef _PDS_UID_H_ +#define _PDS_UID_H_ + +#include + +//唯一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 +{ +public: //扩展的变量 +public: //扩展的方法 +}; + +//唯一ID的链表 +class CPDSUIDList : public CList +{ +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 +{ +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_ diff --git a/datafile/dxf/dxflib/PDSMath/PDSUnit.h b/datafile/dxf/dxflib/PDSMath/PDSUnit.h new file mode 100644 index 0000000..722fbe2 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/PDSUnit.h @@ -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 diff --git a/datafile/dxf/dxflib/PDSMath/Point3D.h b/datafile/dxf/dxflib/PDSMath/Point3D.h new file mode 100644 index 0000000..9bb550f --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/Point3D.h @@ -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 diff --git a/datafile/dxf/dxflib/PDSMath/StdAfx.h b/datafile/dxf/dxflib/PDSMath/StdAfx.h new file mode 100644 index 0000000..d0a0e42 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/StdAfx.h @@ -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 // MFC core and standard components +//#include // MFC extensions +//#include // MFC Automation classes +//#include // 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_) diff --git a/datafile/dxf/dxflib/PDSMath/UnzipFile.h b/datafile/dxf/dxflib/PDSMath/UnzipFile.h new file mode 100644 index 0000000..c6bc11b --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/UnzipFile.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/UnzipFile_Memory.h b/datafile/dxf/dxflib/PDSMath/UnzipFile_Memory.h new file mode 100644 index 0000000..29def36 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/UnzipFile_Memory.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/ZUBaseFile.h b/datafile/dxf/dxflib/PDSMath/ZUBaseFile.h new file mode 100644 index 0000000..7564623 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZUBaseFile.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/ZUBaseFile_Memory.h b/datafile/dxf/dxflib/PDSMath/ZUBaseFile_Memory.h new file mode 100644 index 0000000..1b2ac9b --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZUBaseFile_Memory.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/ZipCompress.h b/datafile/dxf/dxflib/PDSMath/ZipCompress.h new file mode 100644 index 0000000..3c47041 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZipCompress.h @@ -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 \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/ZipException.h b/datafile/dxf/dxflib/PDSMath/ZipException.h new file mode 100644 index 0000000..3b23692 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZipException.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/ZipFile.h b/datafile/dxf/dxflib/PDSMath/ZipFile.h new file mode 100644 index 0000000..43c31f6 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZipFile.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/ZipFile_Memory.h b/datafile/dxf/dxflib/PDSMath/ZipFile_Memory.h new file mode 100644 index 0000000..f6cdb73 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZipFile_Memory.h @@ -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_) diff --git a/datafile/dxf/dxflib/PDSMath/ZipStruct.h b/datafile/dxf/dxflib/PDSMath/ZipStruct.h new file mode 100644 index 0000000..0d4316b --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/ZipStruct.h @@ -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 \ No newline at end of file diff --git a/datafile/dxf/dxflib/PDSMath/zconf.h b/datafile/dxf/dxflib/PDSMath/zconf.h new file mode 100644 index 0000000..6d450fc --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/zconf.h @@ -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 +# 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 +# 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 /* for off_t */ +# include /* 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 */ diff --git a/datafile/dxf/dxflib/PDSMath/zlib.h b/datafile/dxf/dxflib/PDSMath/zlib.h new file mode 100644 index 0000000..49f56b4 --- /dev/null +++ b/datafile/dxf/dxflib/PDSMath/zlib.h @@ -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 */ diff --git a/datafile/dxf/dxflib/ReadASTM.h b/datafile/dxf/dxflib/ReadASTM.h new file mode 100644 index 0000000..5df09b7 --- /dev/null +++ b/datafile/dxf/dxflib/ReadASTM.h @@ -0,0 +1,448 @@ +#if !defined (READASTM_H) +#define READASTM_H +#pragma once + +#include "PDSMath/StdAfx.h" +#include +//#include +#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: + CUIntArray m_arrLQuantity; //左片布料份数 Quantity: + //m_arrQuantity, m_arrLQuantity大小保持一致 + + BOOL m_bFlip; //翻转信息 =true 允许翻转 + double m_dRotation; //最大倾斜角 Rotation<0...360> + BOOL m_bFold; //折叠 Fold: =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 +{ +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 METRIC:mm;= CONST_INCH ENGLISH : 英寸; 默认mm + + int m_iSizeCount; //号型个数 + CString m_strSampleSize; //基码 + CList 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: + CString m_strSampleSize; //基码Sample Size: + int m_iUnit; //= CONST_MM METRIC:mm;= CONST_INCH ENGLISH : 英寸; 默认mm + CString m_strGradeRulTable; //放码文件rul Grade Rule Table: + CString m_strAuthor; //作者Author:;; 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 diff --git a/datafile/dxf/dxflib/ReadAutoCAD.h b/datafile/dxf/dxflib/ReadAutoCAD.h new file mode 100644 index 0000000..291c50d --- /dev/null +++ b/datafile/dxf/dxflib/ReadAutoCAD.h @@ -0,0 +1,485 @@ +#if !defined (READAUTCAD_H) +#define READAUTCAD_H +#pragma once + +#include "PDSMath/StdAfx.h" +#include +//#include +#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 +{ +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 +{ +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: + //纸样名,号型名两个变量是为了防止客户使用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 +{ +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 +{ +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 +{ +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 <ypeInfor); + + //读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 + diff --git a/datafile/dxf/dxflib/ReadDxfFile.h b/datafile/dxf/dxflib/ReadDxfFile.h new file mode 100644 index 0000000..5ce7ca1 --- /dev/null +++ b/datafile/dxf/dxflib/ReadDxfFile.h @@ -0,0 +1,196 @@ +#if !defined (READDXFFILE_H) +#define READDXFFILE_H + +#include "PDSMath/StdAfx.h" +#include +//#include + +#include "ReadAutoCAD.h" +#include "ReadASTM.h" +#include "ReadTIIP.h" +////////////////////////////////////////////////////////////////////////// + +//款式信息 +class CStyleInfo : public CObject +{ +public: + CString m_strStyleName; + CString m_strBaseSizeName; + CList 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 diff --git a/datafile/dxf/dxflib/ReadTIIP.h b/datafile/dxf/dxflib/ReadTIIP.h new file mode 100644 index 0000000..988509d --- /dev/null +++ b/datafile/dxf/dxflib/ReadTIIP.h @@ -0,0 +1,309 @@ +#if !defined (READTIIP_H) +#define READTIIP_H +#pragma once + +#include "PDSMath/StdAfx.h" +#include +//#include +#include +#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 +{ +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: + CString m_strSampleSize; //基码Sample Size: + int m_iUnit; //= CONST_MM METRIC:mm;= CONST_INCH ENGLISH : 英寸; 默认mm + CString m_strAuthor; //作者Author:;; 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 diff --git a/datafile/dxf/dxflib/WriteASTM.h b/datafile/dxf/dxflib/WriteASTM.h new file mode 100644 index 0000000..3e7f219 --- /dev/null +++ b/datafile/dxf/dxflib/WriteASTM.h @@ -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 &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 \ No newline at end of file diff --git a/datafile/dxf/dxflib/WriteAutoCAD.h b/datafile/dxf/dxflib/WriteAutoCAD.h new file mode 100644 index 0000000..4ba6012 --- /dev/null +++ b/datafile/dxf/dxflib/WriteAutoCAD.h @@ -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 \ No newline at end of file diff --git a/datafile/dxf/dxflib/WriteDxfFile.h b/datafile/dxf/dxflib/WriteDxfFile.h new file mode 100644 index 0000000..9da562c --- /dev/null +++ b/datafile/dxf/dxflib/WriteDxfFile.h @@ -0,0 +1,343 @@ +#if !defined (WRITEDXFFILE_H) +#define WRITEDXFFILE_H + +#include "StdAfx.h" +#include +#include + +//点类型 +#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 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 +{ +public: + CPointIDataList& operator=(CPointIDataList& rhs); // 赋值 + + //获取指定索引值上的项 + //输入参数: + // iIndex 索引值,从0开始,不可越界 + //返回值: + CPointIData& operator[](int iIndex); +}; +////////////////////////////////////////////////////////////////////////// +class CCurveIData : public CObject +{ +public: + CPointIDataList m_listCtrlPoint; //控制点链 + CList 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 +{ +public: + CCurveIDataList& operator=(CCurveIDataList& rhs); // 赋值 + + //获取指定索引值上的项 + //输入参数: + // iIndex 索引值,从0开始,不可越界 + //返回值: + CCurveIData& operator[](int iIndex); + + //得到链表所有控制点, 不包含重复点 + //输出参数: + // listPointData 链表中所有控制点,控制点顺序按照链表顺序输出 + void GetCtrlPointIData(CPointIDataList &listPointData); + + //得到链表所有实际点, 不包含重复点 + //输出参数: + // listPoint 链表中所有实际点,实际点顺序按照链表顺序输出 + void GetActualPoint(CList &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 +{ +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 +{ +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; //剪口类型,输出的层类型 ,4,80,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 +{ +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: + CUIntArray m_arrLQuantity; //左片布料份数 Quantity: + //m_arrQuantity, m_arrLQuantity大小保持一致 + + BOOL m_bFlip; //翻转信息 =true 允许翻转 + double m_dRotation; //最大倾斜角 Rotation<0...360> + BOOL m_bFold; //折叠 Fold: =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 +{ +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 \ No newline at end of file diff --git a/datafile/dxf/dxflib/dl_attributes.h b/datafile/dxf/dxflib1/dl_attributes.h similarity index 100% rename from datafile/dxf/dxflib/dl_attributes.h rename to datafile/dxf/dxflib1/dl_attributes.h diff --git a/datafile/dxf/dxflib/dl_codes.h b/datafile/dxf/dxflib1/dl_codes.h similarity index 100% rename from datafile/dxf/dxflib/dl_codes.h rename to datafile/dxf/dxflib1/dl_codes.h diff --git a/datafile/dxf/dxflib/dl_creationadapter.h b/datafile/dxf/dxflib1/dl_creationadapter.h similarity index 100% rename from datafile/dxf/dxflib/dl_creationadapter.h rename to datafile/dxf/dxflib1/dl_creationadapter.h diff --git a/datafile/dxf/dxflib/dl_creationinterface.h b/datafile/dxf/dxflib1/dl_creationinterface.h similarity index 100% rename from datafile/dxf/dxflib/dl_creationinterface.h rename to datafile/dxf/dxflib1/dl_creationinterface.h diff --git a/datafile/dxf/dxflib/dl_dxf.cpp b/datafile/dxf/dxflib1/dl_dxf.cpp similarity index 100% rename from datafile/dxf/dxflib/dl_dxf.cpp rename to datafile/dxf/dxflib1/dl_dxf.cpp diff --git a/datafile/dxf/dxflib/dl_dxf.h b/datafile/dxf/dxflib1/dl_dxf.h similarity index 100% rename from datafile/dxf/dxflib/dl_dxf.h rename to datafile/dxf/dxflib1/dl_dxf.h diff --git a/datafile/dxf/dxflib/dl_entities.h b/datafile/dxf/dxflib1/dl_entities.h similarity index 100% rename from datafile/dxf/dxflib/dl_entities.h rename to datafile/dxf/dxflib1/dl_entities.h diff --git a/datafile/dxf/dxflib/dl_exception.h b/datafile/dxf/dxflib1/dl_exception.h similarity index 100% rename from datafile/dxf/dxflib/dl_exception.h rename to datafile/dxf/dxflib1/dl_exception.h diff --git a/datafile/dxf/dxflib/dl_extrusion.h b/datafile/dxf/dxflib1/dl_extrusion.h similarity index 100% rename from datafile/dxf/dxflib/dl_extrusion.h rename to datafile/dxf/dxflib1/dl_extrusion.h diff --git a/datafile/dxf/dxflib/dl_global.h b/datafile/dxf/dxflib1/dl_global.h similarity index 100% rename from datafile/dxf/dxflib/dl_global.h rename to datafile/dxf/dxflib1/dl_global.h diff --git a/datafile/dxf/dxflib/dl_writer.h b/datafile/dxf/dxflib1/dl_writer.h similarity index 100% rename from datafile/dxf/dxflib/dl_writer.h rename to datafile/dxf/dxflib1/dl_writer.h diff --git a/datafile/dxf/dxflib/dl_writer_ascii.cpp b/datafile/dxf/dxflib1/dl_writer_ascii.cpp similarity index 100% rename from datafile/dxf/dxflib/dl_writer_ascii.cpp rename to datafile/dxf/dxflib1/dl_writer_ascii.cpp diff --git a/datafile/dxf/dxflib/dl_writer_ascii.h b/datafile/dxf/dxflib1/dl_writer_ascii.h similarity index 100% rename from datafile/dxf/dxflib/dl_writer_ascii.h rename to datafile/dxf/dxflib1/dl_writer_ascii.h diff --git a/datafile/dxf/dxfreader.h b/datafile/dxf/dxfreader.h index 7152e50..370a686 100644 --- a/datafile/dxf/dxfreader.h +++ b/datafile/dxf/dxfreader.h @@ -3,8 +3,7 @@ #include #include -#include "dxflib/dl_dxf.h" -#include "dxflib/dl_creationadapter.h" +#include "dxflib/ReadDxfFile.h" #include #include diff --git a/datafile/hpgl/importhpgl.cpp b/datafile/hpgl/importhpgl.cpp index 4bd04d6..86038f1 100644 --- a/datafile/hpgl/importhpgl.cpp +++ b/datafile/hpgl/importhpgl.cpp @@ -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) { diff --git a/datafile/view/drawdata.cpp b/datafile/view/drawdata.cpp index 7852518..e819ad2 100644 --- a/datafile/view/drawdata.cpp +++ b/datafile/view/drawdata.cpp @@ -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"; } - //灏嗚矾寰勭敾鍦╬icture涓 - 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鐨勬鏂瑰舰锛岄噷闈㈡槸浜ゅ弶绾縓 + //娣诲姞姝f柟褰ath + 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; + } + + //灏嗚矾寰勭敾鍦╬icture涓 + 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) { //灏嗗浘鐗囩敾鍦╬icture涓 - 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: 绾挎涓嶻杞撮噸鍚 +// 1: 鏈変竴涓氦鐐(x) +bool lineIntersection(QPointF p1, QPointF p2, double y, QPointF* intersection) +{ + //-1鏄负浜嗛伩鍏峝ouble涔橀櫎鏃朵骇鐢熺殑璇樊 + 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)) + {// 绾挎涓嶻閲嶅悎锛岃繑鍥瀎alse锛屽洜涓鸿繖绉嶆儏鍐靛凡缁忚娣诲姞鍒板潡涓 + return false; + } + // else if (p1.y() == y) + // {// p1涓嶻閲嶅悎 + // intersection->setX(p1.x()); + // intersection->setY(y); + // return true; + // } + // else if (p2.y() == y) + // {// p2涓嶻閲嶅悎 + // 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; +} diff --git a/datafile/view/drawdata.h b/datafile/view/drawdata.h index 5fef97b..ffcdbf6 100644 --- a/datafile/view/drawdata.h +++ b/datafile/view/drawdata.h @@ -2,6 +2,7 @@ #define DRAWDATA_H #include +#include #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;//鐢ㄤ簬鏄剧ず鐨刾icture锛岀敾绗斾负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 diff --git a/datafile/view/mygraphicsitem.cpp b/datafile/view/mygraphicsitem.cpp index fb7349a..0126b3c 100644 --- a/datafile/view/mygraphicsitem.cpp +++ b/datafile/view/mygraphicsitem.cpp @@ -4,7 +4,6 @@ MyGraphicsItem::MyGraphicsItem() { m_point.setX(0); m_point.setY(0); - m_fileType = TYPE_FILE; //浣縤tem鍙互琚夋嫨 //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); - //鐢∕yGraphicsItem鐢诲浘缂╂斁鏃跺鏋滅瑪瀹戒笉涓1锛岀洿鎺ョ敾QPicture鏃剁嚎鏉′細寰堣交锛屾墍浠ョ敤m_drawPath缁樺埗锛宲ic灏变负鍘熺瑪瀹絧ic - //鏂囦欢绫诲瀷鐢╩_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(); } diff --git a/datafile/view/mygraphicsitem.h b/datafile/view/mygraphicsitem.h index 3d994b4..e4b6d5e 100644 --- a/datafile/view/mygraphicsitem.h +++ b/datafile/view/mygraphicsitem.h @@ -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: diff --git a/datafile/view/mygraphicsscene.cpp b/datafile/view/mygraphicsscene.cpp index 39dccc4..f28c983 100644 --- a/datafile/view/mygraphicsscene.cpp +++ b/datafile/view/mygraphicsscene.cpp @@ -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) { diff --git a/datafile/view/mygraphicsscene.h b/datafile/view/mygraphicsscene.h index d5758a3..8014cc1 100644 --- a/datafile/view/mygraphicsscene.h +++ b/datafile/view/mygraphicsscene.h @@ -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: diff --git a/datafile/view/mygraphicsview.cpp b/datafile/view/mygraphicsview.cpp index c0e875c..d4b62a2 100644 --- a/datafile/view/mygraphicsview.cpp +++ b/datafile/view/mygraphicsview.cpp @@ -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); } } diff --git a/datafile/view/mygraphicsview.h b/datafile/view/mygraphicsview.h index 5292c96..3e1d34a 100644 --- a/datafile/view/mygraphicsview.h +++ b/datafile/view/mygraphicsview.h @@ -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: diff --git a/machine/bmp/bwbmp.cpp b/machine/bmp/bwbmp.cpp index 83de46b..0b4dacb 100644 --- a/machine/bmp/bwbmp.cpp +++ b/machine/bmp/bwbmp.cpp @@ -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 compType(wsegnum); // 鏈潡浣嶅浘鍘嬬缉绫诲瀷, =0, 涓嶅帇缂; =1, 鎸夊瓧鑺傚帇缂╋紙鍒嗘鍘嬬缉锛; QVector compSegOffset(wsegnum); // 鍒嗘鏁版嵁璧峰浣嶇疆 diff --git a/machine/bmp/creatprintbmp.cpp b/machine/bmp/creatprintbmp.cpp index 285663a..33cd536 100644 --- a/machine/bmp/creatprintbmp.cpp +++ b/machine/bmp/creatprintbmp.cpp @@ -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); + //灏唒icture淇濆瓨涓哄涓搴︿负PIXMAPWIDTH鍍忕礌鐨刡mp + 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); - //灏唒icture淇濆瓨涓哄涓搴︿负PIXMAPWIDTH鍍忕礌鐨刡mp - 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) - { - //灏嗗浘鐗囩敾鍦╬icture涓 - QPainter painter; - painter.begin(&pic); - painter.setPen(pen); - painter.drawPixmap(0,0,m_mcPrintInfo->m_filesList[idx].m_pixmap); - painter.end(); - //灏唒ixmap淇濆瓨涓哄涓搴︿负PIXMAPWIDTH鍍忕礌鐨刡mp - 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); //灏唒icture淇濆瓨涓哄涓搴︿负PIXMAPWIDTH鍍忕礌鐨刡mp @@ -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); diff --git a/machine/bmp/creatprintbmp.h b/machine/bmp/creatprintbmp.h index 007e4cf..f6d5b1f 100644 --- a/machine/bmp/creatprintbmp.h +++ b/machine/bmp/creatprintbmp.h @@ -17,7 +17,6 @@ #include "datafile/view/drawdata.h" #define PIXMAPWIDTH 1200 -#define PENWIDTH 5 #define PRINTDIR "print" #define PRINTMCDIR "mc" diff --git a/machine/machine.cpp b/machine/machine.cpp index 8d3bd2e..5aa9b9d 100644 --- a/machine/machine.cpp +++ b/machine/machine.cpp @@ -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鍒癠INT16_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; diff --git a/machine/printinfo/mcfiles.h b/machine/printinfo/mcfiles.h index 634bb27..df22fed 100644 --- a/machine/printinfo/mcfiles.h +++ b/machine/printinfo/mcfiles.h @@ -45,8 +45,8 @@ public: s16 m_printNum;//鎵撳嵃浠芥暟 s16 m_startPoint;//鎵撳嵃璧峰鐐 s16 m_printState;//鎵撳嵃鐘舵 - QPicture m_pic;//鏂囦欢-鍙戦佺殑鍥剧墖-瀹為檯绗斿缁樺埗鐨刾ic - QPainterPath m_drawPath;//鏂囦欢-鏁版嵁缁樺浘璺緞-鐢∕yGraphicsItem鐢诲浘鏃跺鏋滅瑪瀹戒笉涓1锛岀洿鎺ョ敾QPicture鏃剁嚎鏉′細寰堣交锛屾墍浠ョ敤m_drawPath缁樺埗 + QPicture m_showPic;//鏂囦欢-鏄剧ず鐨勫浘鐗-1鍍忕礌缁樺埗鐨刾ic + QPicture m_sendPic;//鏂囦欢-鍙戦佺殑鍥剧墖-瀹為檯绗斿缁樺埗鐨刾ic 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;//褰撳墠鎵撳嵃鍧楁暟 diff --git a/mainwindow.cpp b/mainwindow.cpp index 9db5321..1ad6953 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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; //灏唒icture淇濆瓨涓哄涓搴︿负PIXMAPWIDTH鍍忕礌鐨刡mp - 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) { //灏嗗浘鐗囩敾鍦╬icture涓 - 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; //灏唒icture淇濆瓨涓哄涓搴︿负PIXMAPWIDTH鍍忕礌鐨刡mp - 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)); //璁板綍璺緞鍒癚Setting涓繚瀛 #if(1) - creatMarkerDat(m_curFilesInfo,m_printPath,filePath,-1,m_rotateAngle); + if(fileInfo.suffix().toUpper() == "DXF") + { + DxfHelper dxfHelper; + if(dxfHelper.generateDxf(filePath)) + { + dxfHelper.getDxfPaths(); // 鑾峰彇杞崲鍑烘潵鐨刣xf鎵鏈夌被鍨嬪浘褰㈢殑鐐归泦 + 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); } } diff --git a/mainwindow.h b/mainwindow.h index e4aa17d..558d21c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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); diff --git a/printinfodialog.cpp b/printinfodialog.cpp index f786dea..5b81c5b 100644 --- a/printinfodialog.cpp +++ b/printinfodialog.cpp @@ -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(); diff --git a/printviewwindow.cpp b/printviewwindow.cpp index db28182..7df4851 100644 --- a/printviewwindow.cpp +++ b/printviewwindow.cpp @@ -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)"); //濡傛灉鏄渶澶у寲鍙樹负姝e父澶у皬 if(this->windowState() == Qt::WindowMaximized) diff --git a/printviewwindow.h b/printviewwindow.h index 3e63ce3..4bd4cbd 100644 --- a/printviewwindow.h +++ b/printviewwindow.h @@ -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;}