214 lines
5.3 KiB
C++
214 lines
5.3 KiB
C++
#ifndef TLINETOPOLYLINE_2008_11_28_ZZG
|
|
#define TLINETOPOLYLINE_2008_11_28_ZZG
|
|
//#pragma once
|
|
//带凸度的点 类似于cad中vertix点
|
|
#include "TLineToPolyDlg.h"
|
|
class TBudgePoint3d : public AcGePoint3d
|
|
{
|
|
public:
|
|
TBudgePoint3d(){m_dBudge=0;}
|
|
~TBudgePoint3d(){}
|
|
TBudgePoint3d(const TBudgePoint3d&pt)
|
|
{
|
|
m_dBudge = pt.m_dBudge;
|
|
x = pt.x;
|
|
y = pt.y;
|
|
z = pt.z;
|
|
}
|
|
TBudgePoint3d(const AcGePoint3d&pt)
|
|
{
|
|
m_dBudge = 0;
|
|
x = pt.x;
|
|
y = pt.y;
|
|
z = pt.z;
|
|
}
|
|
TBudgePoint3d(const AcGePoint2d&pt)
|
|
{
|
|
m_dBudge = 0;
|
|
x = pt.x;
|
|
y = pt.y;
|
|
z = 0;
|
|
}
|
|
TBudgePoint3d& operator=(const AcGePoint3d&pt)
|
|
{
|
|
if (this == &pt)
|
|
{
|
|
return *this;
|
|
}
|
|
m_dBudge = 0;
|
|
x = pt.x;
|
|
y = pt.y;
|
|
z = pt.z;
|
|
return *this;
|
|
}
|
|
TBudgePoint3d& operator=(const AcGePoint2d&pt)
|
|
{
|
|
m_dBudge = 0;
|
|
x = pt.x;
|
|
y = pt.y;
|
|
z = 0;
|
|
return *this;
|
|
}
|
|
TBudgePoint3d& operator=(const TBudgePoint3d&pt)
|
|
{
|
|
if (this == &pt)
|
|
{
|
|
return *this;
|
|
}
|
|
m_dBudge = pt.m_dBudge;
|
|
x = pt.x;
|
|
y = pt.y;
|
|
z = pt.z;
|
|
return *this;
|
|
}
|
|
bool operator ==(const TBudgePoint3d&pt)const
|
|
{
|
|
if (Equal(x,pt.x,_DIST_SNAP)&&Equal(y,pt.y,_DIST_SNAP)&&Equal(z,pt.z,_DIST_SNAP))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public:
|
|
double m_dBudge;//该点的凸度
|
|
};
|
|
typedef AcArray<TBudgePoint3d> TBudgePoint3dArry;//带凸度的点组
|
|
//包装的线段数据结构
|
|
class TLineSegInfo
|
|
{
|
|
public:
|
|
TLineSegInfo()
|
|
{
|
|
m_idLineSeg = AcDbObjectId::kNull;
|
|
m_nLineColor = 256;
|
|
m_idLineLayer = AcDbObjectId::kNull;
|
|
m_idLineStyle = AcDbObjectId::kNull;
|
|
//弧线有用
|
|
m_dStartAng = 0;//弧度
|
|
m_dEndAng = 0;
|
|
m_vecNormal = AcGeVector3d(0,0,1);
|
|
m_dRadius = 0.0;
|
|
m_bPolyine = FALSE;//是否是polyline
|
|
m_bArc = FALSE;
|
|
m_dBugle = 0;
|
|
m_dMinusBugle = 0;
|
|
m_ptFitAry.setLogicalLength(0);
|
|
};
|
|
~TLineSegInfo(){};
|
|
TLineSegInfo(const TLineSegInfo &lineseg)
|
|
{
|
|
m_idLineSeg = lineseg.m_idLineSeg;
|
|
m_nLineColor = lineseg.m_nLineColor;
|
|
m_idLineLayer = lineseg.m_idLineLayer;
|
|
m_idLineStyle = lineseg.m_idLineStyle;
|
|
m_ptStart = lineseg.m_ptStart;//线段起点
|
|
m_ptEnd = lineseg.m_ptEnd;//线段终点
|
|
m_ptMid = lineseg.m_ptMid;//线段中点
|
|
m_dStartAng =lineseg.m_dStartAng;//弧度
|
|
m_dEndAng = lineseg.m_dEndAng;
|
|
m_vecNormal = lineseg.m_vecNormal;
|
|
m_dRadius =lineseg.m_dRadius;
|
|
m_bPolyine = lineseg.m_bPolyine;//是否是polyline
|
|
m_bArc = lineseg.m_bArc;
|
|
m_ptFitAry.setLogicalLength(0);
|
|
m_ptFitAry.append(lineseg.m_ptFitAry);
|
|
m_dBugle = lineseg.m_dBugle;
|
|
m_dMinusBugle = lineseg.m_dMinusBugle;
|
|
}
|
|
TLineSegInfo& operator=(const TLineSegInfo &lineseg)
|
|
{
|
|
if (this == &lineseg)
|
|
{
|
|
return *this;
|
|
}
|
|
m_idLineSeg = lineseg.m_idLineSeg;
|
|
m_nLineColor = lineseg.m_nLineColor;
|
|
m_idLineLayer = lineseg.m_idLineLayer;
|
|
m_idLineStyle = lineseg.m_idLineStyle;
|
|
m_ptStart = lineseg.m_ptStart;//线段起点
|
|
m_ptEnd = lineseg.m_ptEnd;//线段终点
|
|
m_ptMid = lineseg.m_ptMid;//线段中点
|
|
m_dStartAng =lineseg.m_dStartAng;//弧度
|
|
m_dEndAng = lineseg.m_dEndAng;
|
|
m_vecNormal = lineseg.m_vecNormal;
|
|
m_dRadius =lineseg.m_dRadius;
|
|
m_bPolyine = lineseg.m_bPolyine;//是否是polyline
|
|
m_bArc = lineseg.m_bArc;
|
|
m_ptFitAry.setLogicalLength(0);
|
|
m_ptFitAry.append(lineseg.m_ptFitAry);
|
|
m_dBugle = lineseg.m_dBugle;
|
|
m_dMinusBugle = lineseg.m_dMinusBugle;
|
|
return *this;
|
|
}
|
|
public:
|
|
AcDbObjectId m_idLineSeg;//线段实体id
|
|
AcDbObjectId m_idLineStyle;//线段线形
|
|
int m_nLineColor;//线段颜色
|
|
AcDbObjectId m_idLineLayer;//线段所在图层
|
|
// 线段
|
|
AcGePoint3d m_ptStart;//线段起点
|
|
AcGePoint3d m_ptEnd;//线段终点
|
|
//弧线有用
|
|
BOOL m_bArc;//是否为弧线段
|
|
AcGePoint3d m_ptMid;//线段中点
|
|
double m_dStartAng;//起点角度
|
|
double m_dEndAng;//终点角度
|
|
AcGeVector3d m_vecNormal;//弧线法线
|
|
double m_dRadius;//弧线半径
|
|
double m_dBugle;//凸度
|
|
double m_dMinusBugle;//反向凸度
|
|
//polyine
|
|
BOOL m_bPolyine;//是否是polyline
|
|
//polyline 有用
|
|
TBudgePoint3dArry m_ptFitAry;//polyline时 存的除首尾的点组
|
|
};
|
|
typedef CArray<TLineSegInfo,TLineSegInfo> LineSegAry;//线段数组
|
|
//线段转换为polyline的处理类
|
|
class TLineToPolyLine
|
|
{
|
|
public:
|
|
TLineToPolyLine(void);
|
|
public:
|
|
~TLineToPolyLine(void);
|
|
public:
|
|
//创建polyline
|
|
int CreatePolyLine(TLineToPolyDlg *pdlg);
|
|
private:
|
|
//搜索当前数据库中的线段 polyline,arc
|
|
//并把实体id存入线段实体数组中
|
|
void SearchIds();
|
|
//创建要合并的线段对象数组
|
|
void CreateLineSegs();
|
|
//寻找可以合并的线段
|
|
void FindFitSegs(LineSegAry&sourceSegAry);
|
|
BOOL FindSeg(TBudgePoint3d &pt,
|
|
CArray<TLineSegInfo,TLineSegInfo> &aryLineSegInfo,
|
|
AcArray<TBudgePoint3d> &ptAry,BOOL &bEndPt,BOOL &bReverse,
|
|
BOOL bPre,BOOL &bFindNext);
|
|
//把实体添加到数据库
|
|
AcDbObjectId AddToBlockTable(AcDbEntity *pEnt);
|
|
//计算弧线凸度
|
|
double GetBulge(const TLineSegInfo &LineSeg, bool SEbo);
|
|
//判断圆弧是凸向哪边 向量x积
|
|
double PtSide(AcGePoint3d pt1, AcGePoint3d pt2, AcGePoint3d pt3);
|
|
// 删除所有线段
|
|
void EraseAllLine();
|
|
//根据设置条件组合 要合并的线段id;
|
|
void CombinEntids();
|
|
//绘制一条polyline
|
|
void DrawPoly(LineSegAry&sourceSegAry);
|
|
//反向polyline 中 点的凸度
|
|
void ReverseLineSeg(TBudgePoint3dArry&ptFitAry);
|
|
public:
|
|
BOOL m_bDelete;//是否删除原线段
|
|
BOOL m_bLayer;//是否按同一图层合并
|
|
BOOL m_bLineStyle;//是否按同一线形合并
|
|
BOOL m_bColor;//是否按同一颜色合并
|
|
double m_dMerGeprecision;//合并精度
|
|
private:
|
|
AcDbObjectIdArray m_aryLineId;//线段实体id数组
|
|
int m_nCreatLineOrder;//形成polyline的规则 0-polyline长度优先 1-polyine闭合优先
|
|
CArray<TBudgePoint3dArry,TBudgePoint3dArry> m_ptAryAry;//存储polyline的点组的数组
|
|
CArray<TLineSegInfo,TLineSegInfo> m_aryLineSegInfo;//存储所有线段数据结构的数组
|
|
};
|
|
#endif |