824 lines
18 KiB
C++
824 lines
18 KiB
C++
#include "stdafx.h"
|
|
#include "TLineToPolyLine.h"
|
|
#include "dbspline.h"
|
|
//线变复线命令函数
|
|
void MakeLineToPolyLine()
|
|
{
|
|
static BOOL bDelete = TRUE;
|
|
static BOOL bLayer = TRUE;
|
|
static BOOL bColor = TRUE;
|
|
static BOOL bLineStyle = TRUE;
|
|
static CString strMerGeprecision = _T("0.025");
|
|
CTemporaryResourceOverride Temp;
|
|
TLineToPolyDlg *pDlg = new TLineToPolyDlg();
|
|
pDlg->m_bLayer = bLayer;
|
|
pDlg->m_bLineStyle = bLineStyle;
|
|
pDlg->m_bColor = bColor;
|
|
pDlg->m_bDelete = bDelete;
|
|
pDlg->m_strMerGeprecision = strMerGeprecision;
|
|
pDlg->Create(TLineToPolyDlg::IDD,acedGetAcadFrame());
|
|
acedGetAcadFrame()->SetFocus();
|
|
pDlg->ShowWindow(SW_SHOW);
|
|
TLineToPolyLine line;
|
|
line.CreatePolyLine(pDlg);
|
|
bDelete = line.m_bDelete;
|
|
bColor = line.m_bColor;
|
|
bLayer = line.m_bLayer;
|
|
bLineStyle = line.m_bLineStyle;
|
|
strMerGeprecision.Format(_T("%.3lf"),line.m_dMerGeprecision);
|
|
pDlg->DestroyWindow();
|
|
delete pDlg;
|
|
}
|
|
|
|
TLineToPolyLine::TLineToPolyLine(void)
|
|
{
|
|
m_dMerGeprecision = 0.025;
|
|
m_aryLineId.setLogicalLength(0);
|
|
m_bColor = FALSE;
|
|
m_bLayer = FALSE;
|
|
m_bLineStyle = FALSE;
|
|
m_bDelete = TRUE;
|
|
}
|
|
|
|
TLineToPolyLine::~TLineToPolyLine(void)
|
|
{
|
|
|
|
}
|
|
int TLineToPolyLine::CreatePolyLine(TLineToPolyDlg *pdlg)
|
|
{
|
|
|
|
SearchIds();
|
|
CString str;
|
|
pdlg->GetDlgItemText(IDC_EDIT_PRECISION,str);
|
|
m_dMerGeprecision = _tstof(str);
|
|
m_bDelete = pdlg->m_bDelete;
|
|
m_bColor = pdlg->m_bColor;
|
|
m_bLayer = pdlg->m_bLayer;
|
|
m_bLineStyle = pdlg->m_bLineStyle;
|
|
CreateLineSegs();
|
|
CombinEntids();
|
|
if (m_bDelete)
|
|
{
|
|
EraseAllLine();
|
|
}
|
|
return 0;
|
|
}
|
|
void TLineToPolyLine::DrawPoly(LineSegAry&sourcesegary)
|
|
{
|
|
m_ptAryAry.RemoveAll();
|
|
int nColor;
|
|
AcDbObjectId idLayer,idLineStyle;
|
|
if (sourcesegary.GetSize()!=0)
|
|
{
|
|
nColor = sourcesegary[0].m_nLineColor;
|
|
idLayer = sourcesegary[0].m_idLineLayer;
|
|
idLineStyle = sourcesegary[0].m_idLineStyle;
|
|
}
|
|
FindFitSegs(sourcesegary);
|
|
if (m_ptAryAry.GetSize()!=0)
|
|
{
|
|
int i =0;
|
|
for (i = 0; i < m_ptAryAry.GetSize();i++)
|
|
{
|
|
TBudgePoint3dArry ptary;
|
|
ptary.append(m_ptAryAry.GetAt(i));
|
|
int nlen = ptary.length();
|
|
AcDbPolyline *pPolyLine = new AcDbPolyline(nlen);
|
|
if (nlen>2)
|
|
{
|
|
if (ptary[0]==ptary[nlen-1])
|
|
{
|
|
//pPolyLine->set
|
|
ptary.removeAt(nlen-1);
|
|
nlen = ptary.length();
|
|
pPolyLine->setClosed(Adesk::kTrue);
|
|
}
|
|
}
|
|
int j = 0;
|
|
for (j= 0;j < nlen;j++)
|
|
{
|
|
TBudgePoint3d pt3d = ptary.at(j);
|
|
AcGePoint2d pt2d;
|
|
pt2d.x = pt3d.x;
|
|
pt2d.y = pt3d.y;
|
|
double dBudge = pt3d.m_dBudge;
|
|
if (!Equal(dBudge,0,_DIST_SNAP))
|
|
{
|
|
pPolyLine->addVertexAt(j,pt2d,dBudge,0,0);
|
|
}
|
|
else
|
|
{
|
|
pPolyLine->addVertexAt(j,pt2d,0,0,0);
|
|
}
|
|
}
|
|
pPolyLine->setColorIndex(nColor);
|
|
pPolyLine->setLinetype(idLineStyle);
|
|
pPolyLine->setLayer(idLayer);
|
|
AcDbObjectId idPoly = AddToBlockTable(pPolyLine);
|
|
pPolyLine->close();
|
|
}
|
|
}
|
|
}
|
|
void TLineToPolyLine::CombinEntids()
|
|
{
|
|
LineSegAry sourceSegAry;
|
|
sourceSegAry.Append(m_aryLineSegInfo);
|
|
if (!m_bColor&&!m_bLayer&&!m_bLineStyle)
|
|
{
|
|
DrawPoly(sourceSegAry);
|
|
}
|
|
else if (!m_bColor&&!m_bLayer&&m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_idLineStyle == linesegTem.m_idLineStyle)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
else if (!m_bColor&&m_bLayer&&!m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_idLineLayer == linesegTem.m_idLineLayer)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
else if (!m_bColor&&m_bLayer&&m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_idLineLayer == linesegTem.m_idLineLayer
|
|
&&LineSeg.m_idLineStyle == linesegTem.m_idLineStyle)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
if (m_bColor&&!m_bLayer&&!m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_nLineColor == linesegTem.m_nLineColor)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
else if (m_bColor&&!m_bLayer&&m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_nLineColor == linesegTem.m_nLineColor
|
|
&&LineSeg.m_idLineStyle == linesegTem.m_idLineStyle)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
else if (m_bColor&&m_bLayer&&!m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_nLineColor == linesegTem.m_nLineColor
|
|
&&LineSeg.m_idLineLayer == linesegTem.m_idLineLayer)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
else if (m_bColor&&m_bLayer&&m_bLineStyle)
|
|
{
|
|
while(sourceSegAry.GetSize()!=0)
|
|
{
|
|
TLineSegInfo LineSeg = sourceSegAry[0];
|
|
LineSegAry SegAry;
|
|
SegAry.Add(LineSeg);
|
|
sourceSegAry.RemoveAt(0);
|
|
if (sourceSegAry.GetSize()>0)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<sourceSegAry.GetSize();i++)
|
|
{
|
|
TLineSegInfo linesegTem = sourceSegAry.GetAt(i);
|
|
if (LineSeg.m_nLineColor == linesegTem.m_nLineColor
|
|
&&LineSeg.m_idLineLayer == linesegTem.m_idLineLayer
|
|
&&LineSeg.m_idLineStyle == linesegTem.m_idLineStyle)
|
|
{
|
|
SegAry.Add(linesegTem);
|
|
sourceSegAry.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
DrawPoly(SegAry);
|
|
}
|
|
}
|
|
}
|
|
void TLineToPolyLine::EraseAllLine()
|
|
{
|
|
int i =0;
|
|
Acad::ErrorStatus es;
|
|
for (i=0;i<m_aryLineSegInfo.GetSize();i++)
|
|
{
|
|
AcDbObjectId idTem = m_aryLineSegInfo[i].m_idLineSeg;
|
|
AcDbEntity *pEnt = NULL;
|
|
es = acdbOpenObject(pEnt,idTem,AcDb::kForWrite);
|
|
pEnt->erase();
|
|
pEnt->close();
|
|
}
|
|
}
|
|
void TLineToPolyLine::SearchIds()
|
|
{
|
|
ads_name ssname;
|
|
struct resbuf *reb;
|
|
//构造过滤集
|
|
reb = acutBuildList(-4,_T("<OR"),RTDXF0, _T("LINE"),RTDXF0, _T("ARC"),
|
|
RTDXF0,_T("LWPOLYLINE"),RTDXF0,_T("POLYLINE"),-4,_T("OR>"),RTNONE);
|
|
ads_printf(_T("请选择要合并的线\n"));
|
|
int nRes = ads_ssget(NULL,NULL,NULL,reb,ssname);
|
|
if (nRes ==RTNORM)
|
|
{
|
|
long nLen ;
|
|
Acad::ErrorStatus es;
|
|
ads_sslength(ssname,&nLen);
|
|
int i = 0;
|
|
for (i = 0;i < nLen;i++ )
|
|
{
|
|
ads_name ent;
|
|
ads_ssname(ssname,i,ent);
|
|
AcDbObjectId idTem = AcDbObjectId::kNull;
|
|
es = acdbGetObjectId(idTem,ent);
|
|
if (es==Acad::eOk)
|
|
{
|
|
m_aryLineId.append(idTem);
|
|
}
|
|
}
|
|
ads_ssfree(ssname);
|
|
acutRelRb(reb);
|
|
}
|
|
}
|
|
void TLineToPolyLine::CreateLineSegs()
|
|
{
|
|
Acad::ErrorStatus es;
|
|
int i = 0;
|
|
for (i=0;i<m_aryLineId.length();i++)
|
|
{
|
|
AcDbObjectId idTem = m_aryLineId[i];
|
|
AcDbEntity *pEnt = NULL;
|
|
es = acdbOpenObject(pEnt,idTem,AcDb::kForRead);
|
|
if (es ==Acad::eOk)
|
|
{
|
|
CString strEntName = pEnt->isA()->name();
|
|
TLineSegInfo LineSegInfo;
|
|
if (strEntName == _T("AcDbLine"))
|
|
{
|
|
AcDbLine *pline = (AcDbLine *)pEnt;
|
|
LineSegInfo.m_idLineSeg = idTem;
|
|
LineSegInfo.m_nLineColor = pline->colorIndex();
|
|
LineSegInfo.m_idLineLayer = pline->layerId();
|
|
LineSegInfo.m_idLineStyle = pline->linetypeId();
|
|
LineSegInfo.m_ptEnd = pline->endPoint();
|
|
LineSegInfo.m_ptStart = pline->startPoint();
|
|
m_aryLineSegInfo.Add(LineSegInfo);
|
|
}
|
|
else if (strEntName == _T("AcDbArc"))
|
|
{
|
|
AcDbArc *pline = (AcDbArc *)pEnt;
|
|
LineSegInfo.m_idLineSeg = idTem;
|
|
LineSegInfo.m_nLineColor = pline->colorIndex();
|
|
LineSegInfo.m_idLineLayer = pline->layerId();
|
|
LineSegInfo.m_idLineStyle = pline->linetypeId();
|
|
LineSegInfo.m_bArc = TRUE;
|
|
LineSegInfo.m_ptMid = pline->center();
|
|
LineSegInfo.m_dStartAng = pline->startAngle();
|
|
LineSegInfo.m_dEndAng = pline->endAngle();
|
|
LineSegInfo.m_vecNormal = pline->normal();
|
|
pline->getStartPoint(LineSegInfo.m_ptStart);
|
|
pline->getEndPoint(LineSegInfo.m_ptEnd);
|
|
LineSegInfo.m_dBugle = 0;
|
|
LineSegInfo.m_dMinusBugle =0;
|
|
m_aryLineSegInfo.Add(LineSegInfo);
|
|
}
|
|
else if (strEntName == _T("AcDbPolyline"))
|
|
{
|
|
AcDbPolyline *pline = (AcDbPolyline *)pEnt;
|
|
LineSegInfo.m_idLineSeg = idTem;
|
|
LineSegInfo.m_nLineColor = pline->colorIndex();
|
|
LineSegInfo.m_idLineLayer = pline->layerId();
|
|
LineSegInfo.m_idLineStyle = pline->linetypeId();
|
|
LineSegInfo.m_bPolyine = TRUE;
|
|
pline->getStartPoint(LineSegInfo.m_ptStart);
|
|
pline->getEndPoint(LineSegInfo.m_ptEnd);
|
|
int nNum = pline->numVerts();
|
|
pline->getBulgeAt(0,LineSegInfo.m_dBugle);
|
|
pline->getBulgeAt(nNum-1,LineSegInfo.m_dMinusBugle);
|
|
int j =0;
|
|
for (j=1;j<nNum-1;j++)
|
|
{
|
|
TBudgePoint3d ptTem;
|
|
AcGePoint2d pt2d;
|
|
double dBulge = 0;
|
|
pline->getPointAt(j,pt2d);
|
|
pline->getBulgeAt(j,dBulge);
|
|
ptTem = pt2d;
|
|
ptTem.m_dBudge = dBulge;
|
|
LineSegInfo.m_ptFitAry.append(ptTem);
|
|
}
|
|
if (LineSegInfo.m_ptStart!=LineSegInfo.m_ptEnd)
|
|
{
|
|
m_aryLineSegInfo.Add(LineSegInfo);
|
|
}
|
|
|
|
}
|
|
else if (strEntName == _T("AcDb2dPolyline"))
|
|
{
|
|
//AcDb2dPolyline *p2dline = (AcDb2dPolyline*)pEnt;
|
|
pEnt->upgradeOpen();
|
|
AcDbPolyline *pline = new AcDbPolyline;//pEnt;
|
|
es = pline->convertFrom(pEnt);//调用此函数后 pent自动释放
|
|
if (es == Acad::eOk)
|
|
{
|
|
LineSegInfo.m_idLineSeg = idTem;
|
|
LineSegInfo.m_nLineColor = pline->colorIndex();
|
|
LineSegInfo.m_idLineLayer = pline->layerId();
|
|
LineSegInfo.m_idLineStyle = pline->linetypeId();
|
|
LineSegInfo.m_bPolyine = TRUE;
|
|
pline->getStartPoint(LineSegInfo.m_ptStart);
|
|
pline->getEndPoint(LineSegInfo.m_ptEnd);
|
|
int nNum = pline->numVerts();
|
|
pline->getBulgeAt(0,LineSegInfo.m_dBugle);
|
|
pline->getBulgeAt(nNum-1,LineSegInfo.m_dMinusBugle);
|
|
int j =0;
|
|
for (j=1;j<nNum-1;j++)
|
|
{
|
|
TBudgePoint3d ptTem;
|
|
AcGePoint2d pt2d;
|
|
double dBulge = 0;
|
|
pline->getPointAt(j,pt2d);
|
|
pline->getBulgeAt(j,dBulge);
|
|
ptTem = pt2d;
|
|
ptTem.m_dBudge = dBulge;
|
|
LineSegInfo.m_ptFitAry.append(ptTem);
|
|
}
|
|
if (LineSegInfo.m_ptStart!=LineSegInfo.m_ptEnd)
|
|
{
|
|
m_aryLineSegInfo.Add(LineSegInfo);
|
|
}
|
|
pline->close();
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
|
|
void TLineToPolyLine::FindFitSegs(LineSegAry&sourceSegAry)
|
|
{
|
|
|
|
while (sourceSegAry.GetSize()!=0)
|
|
{
|
|
BOOL bReverse = FALSE;
|
|
BOOL bEndPt = FALSE;
|
|
TLineSegInfo LineSeg = sourceSegAry.GetAt(0);
|
|
sourceSegAry.RemoveAt(0);
|
|
TBudgePoint3d ptPre = LineSeg.m_ptStart;
|
|
TBudgePoint3d ptNext = LineSeg.m_ptEnd;
|
|
AcArray<TBudgePoint3d> ptAryPre,ptAryNext;
|
|
if (LineSeg.m_bArc)
|
|
{
|
|
ptPre.m_dBudge = GetBulge(LineSeg,TRUE);
|
|
}
|
|
else
|
|
{
|
|
ptPre.m_dBudge = LineSeg.m_dBugle;
|
|
}
|
|
ptAryPre.append(ptPre);
|
|
BOOL bFindNext = FALSE;
|
|
FindSeg(ptPre,sourceSegAry,ptAryPre,bEndPt,bReverse,TRUE,bFindNext);
|
|
ptNext.m_dBudge = LineSeg.m_dMinusBugle;
|
|
if (LineSeg.m_ptFitAry.length()!=0)
|
|
{
|
|
ptAryNext.append(LineSeg.m_ptFitAry);
|
|
}
|
|
ptAryNext.append(ptNext);
|
|
bReverse = FALSE;
|
|
bEndPt = TRUE;
|
|
bFindNext = FALSE;
|
|
FindSeg(ptNext,sourceSegAry,ptAryNext,bEndPt,bReverse,FALSE,bFindNext);
|
|
if (ptAryNext.length()==1)
|
|
{
|
|
ptAryNext[0].m_dBudge = 0;
|
|
}
|
|
else if (ptAryNext.length()>1)
|
|
{
|
|
if (bFindNext)
|
|
{
|
|
int i =0;
|
|
for (i=0;i<ptAryNext.length()-1;i++)
|
|
{
|
|
ptAryNext[i].m_dBudge = ptAryNext[i+1].m_dBudge;
|
|
double d = ptAryNext[i].m_dBudge;
|
|
if (i == ptAryNext.length()-2)
|
|
{
|
|
ptAryNext[i+1].m_dBudge = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ptAryPre.reverse();
|
|
if (ptAryNext.length()!=0)
|
|
{
|
|
ptAryPre.append(ptAryNext);
|
|
}
|
|
m_ptAryAry.Add(ptAryPre);
|
|
}
|
|
}
|
|
|
|
BOOL TLineToPolyLine::FindSeg(TBudgePoint3d &pt,
|
|
CArray<TLineSegInfo,TLineSegInfo> &aryLineSegInfo
|
|
,AcArray<TBudgePoint3d> &ptAry,BOOL &bEndPt,
|
|
BOOL &bReverse,BOOL bPre,BOOL &bFindNext)
|
|
{
|
|
//static BOOL bFindNext = FALSE;
|
|
BOOL bFind = FALSE;
|
|
int i =0;
|
|
for (i =0;i<aryLineSegInfo.GetSize();i++)
|
|
{
|
|
TLineSegInfo LineSeg = aryLineSegInfo.GetAt(i);
|
|
double dDisStart = pt.distanceTo(LineSeg.m_ptStart);
|
|
double dDisEnd = pt.distanceTo(LineSeg.m_ptEnd);
|
|
if (LessEqual(dDisStart,m_dMerGeprecision))
|
|
{
|
|
bFindNext = TRUE;
|
|
if (!bEndPt)
|
|
{
|
|
if (!bReverse)
|
|
{
|
|
bReverse = TRUE;
|
|
}
|
|
else
|
|
{
|
|
bReverse = FALSE;
|
|
}
|
|
}
|
|
if (!bEndPt&&bPre&&LineSeg.m_bPolyine)
|
|
{
|
|
double dBugle = LineSeg.m_dBugle;
|
|
double dMinusBugle = LineSeg.m_dMinusBugle;
|
|
LineSeg.m_dBugle = pt.m_dBudge;
|
|
int nLen = LineSeg.m_ptFitAry.length();
|
|
LineSeg.m_dMinusBugle = LineSeg.m_ptFitAry.at(nLen-1).m_dBudge;
|
|
int i =0;
|
|
for (i = 0;i<nLen;i++)
|
|
{
|
|
if (i == nLen - 1)
|
|
{
|
|
LineSeg.m_ptFitAry[nLen-1-i].m_dBudge = dBugle;
|
|
}
|
|
else
|
|
{
|
|
LineSeg.m_ptFitAry[nLen-1-i].m_dBudge = LineSeg.m_ptFitAry[nLen-2-i].m_dBudge;
|
|
}
|
|
|
|
}
|
|
}
|
|
pt = LineSeg.m_ptEnd;
|
|
if (LineSeg.m_bArc)
|
|
{
|
|
if (bReverse)
|
|
{
|
|
pt.m_dBudge = GetBulge(LineSeg,FALSE);
|
|
}
|
|
else
|
|
{
|
|
pt.m_dBudge = GetBulge(LineSeg,TRUE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (bReverse)
|
|
{
|
|
pt.m_dBudge = -LineSeg.m_dMinusBugle;
|
|
|
|
}
|
|
else
|
|
{
|
|
pt.m_dBudge = LineSeg.m_dMinusBugle;
|
|
}
|
|
}
|
|
if (LineSeg.m_ptFitAry.length()!=0)
|
|
{
|
|
if (bReverse)
|
|
{
|
|
ReverseLineSeg(LineSeg.m_ptFitAry);
|
|
}
|
|
if (!bPre)
|
|
{
|
|
int nLen = LineSeg.m_ptFitAry.length();
|
|
if (nLen!=0)
|
|
{
|
|
double dTem = LineSeg.m_ptFitAry[nLen-1].m_dBudge;
|
|
pt.m_dBudge = dTem;
|
|
}
|
|
int i =0;
|
|
for (i = 0;i<nLen;i++)
|
|
{
|
|
if (i == nLen - 1)
|
|
{
|
|
LineSeg.m_ptFitAry[nLen-1-i].m_dBudge = LineSeg.m_dBugle;
|
|
}
|
|
else
|
|
{
|
|
LineSeg.m_ptFitAry[nLen-1-i].m_dBudge = LineSeg.m_ptFitAry[nLen-2-i].m_dBudge;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
ptAry.append(LineSeg.m_ptFitAry);
|
|
}
|
|
ptAry.append(pt);
|
|
aryLineSegInfo.RemoveAt(i);
|
|
bEndPt = TRUE;
|
|
bFind = TRUE;
|
|
break;
|
|
}
|
|
else if (LessEqual(dDisEnd,m_dMerGeprecision))
|
|
{
|
|
bFindNext = TRUE;
|
|
pt = LineSeg.m_ptStart;
|
|
if (bEndPt)
|
|
{
|
|
if (!bReverse)
|
|
{
|
|
bReverse = TRUE;
|
|
}
|
|
else
|
|
{
|
|
bReverse = FALSE;
|
|
}
|
|
}
|
|
bEndPt = FALSE;
|
|
if (LineSeg.m_bArc)
|
|
{
|
|
if (bReverse)
|
|
{
|
|
pt.m_dBudge = GetBulge(LineSeg,FALSE);
|
|
|
|
}
|
|
else
|
|
{
|
|
pt.m_dBudge = GetBulge(LineSeg,TRUE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//pt.m_dBudge = LineSeg.m_dBugle;
|
|
if (bReverse)
|
|
{
|
|
pt.m_dBudge = -LineSeg.m_dBugle;;
|
|
|
|
}
|
|
else
|
|
{
|
|
pt.m_dBudge = LineSeg.m_dBugle;;
|
|
}
|
|
}
|
|
if (LineSeg.m_ptFitAry.length()!=0)
|
|
{
|
|
LineSeg.m_ptFitAry.reverse();
|
|
if (bReverse)
|
|
{
|
|
ReverseLineSeg(LineSeg.m_ptFitAry);
|
|
}
|
|
ptAry.append(LineSeg.m_ptFitAry);
|
|
}
|
|
ptAry.append(pt);
|
|
aryLineSegInfo.RemoveAt(i);
|
|
bFind = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
if (bFind)
|
|
{
|
|
FindSeg(pt,aryLineSegInfo,ptAry,bEndPt,bReverse,bPre,bFindNext);
|
|
}
|
|
return bFindNext;
|
|
}
|
|
|
|
AcDbObjectId TLineToPolyLine::AddToBlockTable(AcDbEntity *pEnt)
|
|
{
|
|
AcDbObjectId idTem;
|
|
AcDbDatabase *pDb = acdbCurDwg();
|
|
Acad::ErrorStatus es;
|
|
if (pDb)
|
|
{
|
|
AcDbBlockTable *pTable = NULL;
|
|
AcDbBlockTableRecord *pTblRecd = NULL;
|
|
es = pDb->getBlockTable(pTable,AcDb::kForRead);
|
|
if (es == Acad::eOk)
|
|
{
|
|
es = pTable->getAt(ACDB_MODEL_SPACE,pTblRecd,AcDb::kForWrite);
|
|
if (es == Acad::eOk)
|
|
{
|
|
es = pTblRecd->appendAcDbEntity(idTem,pEnt);
|
|
}
|
|
pTable->close();
|
|
pTblRecd->close();
|
|
}
|
|
}
|
|
return idTem;
|
|
}
|
|
|
|
double TLineToPolyLine::GetBulge(const TLineSegInfo &LineSeg, bool SEbo)
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
Acad::ErrorStatus es;
|
|
es = acdbOpenObject(pEnt,LineSeg.m_idLineSeg,AcDb::kForRead);
|
|
if (es != Acad::eOk)
|
|
{
|
|
return 0;
|
|
}
|
|
CString strName;
|
|
strName = pEnt->isA()->name();
|
|
if (strName != _T("AcDbArc"))
|
|
{
|
|
pEnt->close();
|
|
return 0;
|
|
}
|
|
AcDbArc *pArc = (AcDbArc*)pEnt;
|
|
double dBulge = 0;
|
|
AcGePoint3d pts,pte;
|
|
pArc->getStartPoint(pts);
|
|
pArc->getEndPoint(pte);
|
|
double dDis = pts.distanceTo(pte);
|
|
double dAngle = pArc->endAngle()-pArc->startAngle();
|
|
if (!GreatEqual(dAngle,0))
|
|
{
|
|
dAngle = PI*2 + dAngle;
|
|
}
|
|
if (GreatEqual(dAngle,PI))
|
|
{
|
|
double dR = pArc->radius();
|
|
if (!LessEqual(dR - dDis/2,0))
|
|
{
|
|
dBulge = pArc->radius()+sqrt(pow(pArc->radius(),2)-pow(dDis/2,2));
|
|
}
|
|
else
|
|
{
|
|
dBulge = pArc->radius();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
double dR = pArc->radius();
|
|
if (!LessEqual(dR - dDis/2,0))
|
|
{
|
|
dBulge = pArc->radius()-sqrt(pow(pArc->radius(),2)-pow(dDis/2,2));
|
|
}
|
|
else
|
|
{
|
|
dBulge = pArc->radius();
|
|
}
|
|
}
|
|
double dDisa(0),dParam(0);
|
|
pArc->getEndParam(dParam);
|
|
pArc->getDistAtParam(dParam,dDisa);
|
|
AcGePoint3d ptTem ;
|
|
pArc->getPointAtDist(dDisa/2,ptTem);
|
|
double dTem = pArc->radius();
|
|
//取中点
|
|
double TempDouble = 0;
|
|
if (SEbo == true)
|
|
{
|
|
//判断方向
|
|
TempDouble = PtSide(pts, ptTem, pte);
|
|
}
|
|
else
|
|
{
|
|
TempDouble = PtSide(pte, ptTem, pts);
|
|
}
|
|
if (TempDouble > 0)
|
|
{
|
|
//判断圆弧是凸向哪边
|
|
pEnt->close();
|
|
return -dBulge / (dDis / 2);
|
|
}
|
|
else
|
|
{
|
|
pEnt->close();
|
|
return dBulge / (dDis / 2);
|
|
}
|
|
|
|
}
|
|
double TLineToPolyLine::PtSide(AcGePoint3d pt1, AcGePoint3d pt2, AcGePoint3d pt3)
|
|
{
|
|
AcGeVector3d vect1 = pt2 - pt1;
|
|
AcGeVector3d vect2 = pt3 - pt1;
|
|
return vect2.x*vect1.y - vect1.x*vect2.y;
|
|
}
|
|
|
|
void TLineToPolyLine::ReverseLineSeg(TBudgePoint3dArry&ptFitAry)
|
|
{
|
|
int i = 0;
|
|
for (i = 0;i<ptFitAry.length();i++)
|
|
{
|
|
ptFitAry[i].m_dBudge = -ptFitAry[i].m_dBudge;
|
|
}
|
|
}
|