259 lines
5.8 KiB
C++
259 lines
5.8 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPointList 类
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TPointList 定义
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPointList.h"
|
|
#include "TchGlobalFunc.h"
|
|
#include "TchPrivateGlobalFunc.h"
|
|
#include "TchGlobalCurveFunc.h"
|
|
#include "TGGeCurveInline.h"
|
|
|
|
TPointList::TPointList(const TADSGePoint3d & startPoint, const TADSGePoint3d & endPoint, ads_real bulge)
|
|
{
|
|
if (fabs(bulge) > 1E-6)
|
|
{ // Arc or circle
|
|
if (fabs(2*PI - bulge) < 1E-6)
|
|
{// Circle
|
|
curveType = CURVE_CIRCLE;
|
|
Append(new TADSGePoint3d (startPoint));
|
|
|
|
center = startPoint + endPoint;
|
|
center.Scale(0.5);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
center = TGGeArc(startPoint, endPoint, bulge).GetCenterPt();
|
|
curveType = CURVE_ARC;
|
|
}
|
|
}
|
|
else curveType = CURVE_LINE;
|
|
Append(new TADSGePoint3d (startPoint));
|
|
Append(new TADSGePoint3d (endPoint));
|
|
}
|
|
|
|
TPointList::~TPointList()
|
|
{
|
|
|
|
}
|
|
|
|
// Status: Insert point must between 0~max
|
|
int TPointList::Insert(const TADSGePoint3d & pt, BOOL bExt)
|
|
{
|
|
if (curveType == CURVE_CIRCLE)
|
|
{
|
|
if ((pt & TGGeCircle(center, ads_distance(center, *(*this)[0]))) == PR_ONCIRCLE)
|
|
{
|
|
int listLen = Length();
|
|
ads_real curDrt = ads_angle(center, pt);
|
|
for (int i = 1; i < listLen; i++)
|
|
{
|
|
ads_real drt = ads_angle(center, *(*this)[i]);
|
|
|
|
if (AngleRangeTo2PI(drt - curDrt) < _angSnap)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
if (curDrt < drt)
|
|
{
|
|
TDPtrList<TADSGePoint3d>::Insert(new TADSGePoint3d(pt));
|
|
return RTNORM;
|
|
}
|
|
}
|
|
Append(new TADSGePoint3d(pt));
|
|
return RTNORM;
|
|
}
|
|
return RTERROR;
|
|
}
|
|
|
|
// arc and line
|
|
int listLen = Length();
|
|
TPointList &segPoints = *this;
|
|
for (int j = 0; j < listLen-1; j++)
|
|
{
|
|
TADSGePoint3d &pt1 = *segPoints[j];
|
|
TADSGePoint3d &pt2 = *segPoints[j+1];
|
|
if (curveType == CURVE_LINE)
|
|
{
|
|
TGGeLine lineSeg(pt1, pt2, LS_FINITE);
|
|
if ((pt & lineSeg) == PR_INSIDE)
|
|
{
|
|
TDPtrList<TADSGePoint3d>::Insert(new TADSGePoint3d (pt));
|
|
return RTNORM;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TGGeArc arcSeg(center, ads_distance(center, pt1), ads_angle(center,pt1), ads_angle(center, pt2));
|
|
if ((pt & arcSeg) == PR_INSIDE)
|
|
{
|
|
TDPtrList<TADSGePoint3d>::Insert(new TADSGePoint3d (pt));
|
|
return RTNORM;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bExt)
|
|
{
|
|
ASSERT(listLen >= 2);
|
|
if (curveType == CURVE_LINE)
|
|
{
|
|
TGGeLine lineSeg(*Head(), *Tail());
|
|
if ((pt & lineSeg) == PR_EXTEND)
|
|
{
|
|
if (pt.Distance2d(*Head()) < pt.Distance2d(*Tail()))
|
|
{
|
|
(*this)[0];
|
|
TDPtrList<TADSGePoint3d>::Insert(new TADSGePoint3d(pt));
|
|
}
|
|
else
|
|
{
|
|
TDPtrList<TADSGePoint3d>::Append(new TADSGePoint3d(pt));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TGGeArc arcSeg(center, ads_distance(center, *Head()), ads_angle(center, *Head()), ads_angle(center, *Tail()));
|
|
// 没有考虑在端点,改正2001/9/13
|
|
if (fabs(pt.Distance2d(arcSeg.GetCenterPt()) - arcSeg.GetRadius()) < _DIST_SNAP &&
|
|
pt.Distance2d(*Head()) > _DIST_SNAP && pt.Distance2d(*Tail()) > _DIST_SNAP)
|
|
{ //在弧外
|
|
if (pt.Distance2d(*Head()) < pt.Distance2d(*Tail()))
|
|
{
|
|
(*this)[0];
|
|
TDPtrList<TADSGePoint3d>::Insert(new TADSGePoint3d(pt));
|
|
}
|
|
else
|
|
{
|
|
TDPtrList<TADSGePoint3d>::Append(new TADSGePoint3d(pt));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return RTERROR;
|
|
}
|
|
|
|
int TPointList::Update(const ads_name ref)
|
|
{
|
|
TEntitySet entRef = ref;
|
|
//entRef.GetGroups();
|
|
int listLen = Length();
|
|
TPointList &pts = *this;
|
|
if (curveType == CURVE_CIRCLE)
|
|
{
|
|
if (listLen <= 2)
|
|
{// circle, but not cut to arcs
|
|
return RTERROR;
|
|
}
|
|
TCHAR lay[80] = _T("0");
|
|
entRef.GetData(8, lay);
|
|
for (int i = 1; i < listLen; i++)
|
|
{
|
|
TADSGePoint3d pt2;
|
|
if (i == listLen - 1)
|
|
{
|
|
pt2 = *pts[1];
|
|
}
|
|
else
|
|
{
|
|
pt2 = *pts[i+1];
|
|
}
|
|
TGGeArc arcSeg(center, ads_distance(center, *pts[i]), ads_angle(center, *pts[i]), ads_angle(center, pt2));
|
|
arcSeg.Make(lay);
|
|
}
|
|
ads_entdel(ref);
|
|
}
|
|
else
|
|
{
|
|
for (int j = 0; j<listLen-1; j++)
|
|
{ // arc and line
|
|
TADSGePoint3d &pt1 = *pts[j];
|
|
TADSGePoint3d &pt2 = *pts[j+1];
|
|
if (curveType == CURVE_LINE)
|
|
{
|
|
TGGeLine lineSeg(pt1, pt2);
|
|
if (j == 0)
|
|
{
|
|
lineSeg.Modify(&entRef);
|
|
}
|
|
else
|
|
{
|
|
lineSeg.MakeEntity(&entRef);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TGGeArc arcSeg(center, ads_distance(center, pt1), ads_angle(center,pt1), ads_angle(center, pt2));
|
|
if (j == 0)
|
|
{
|
|
arcSeg.Modify(&entRef);
|
|
}
|
|
else
|
|
{
|
|
arcSeg.MakeEntity(&entRef);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return RTNORM;
|
|
|
|
}
|
|
|
|
// 化作Poly2D
|
|
void TPointList::AsPoly2D(TGGePoly2D &poly) const
|
|
{
|
|
int listLen = Length();
|
|
const TPointList &pts = *this;
|
|
if (curveType == CURVE_CIRCLE)
|
|
{
|
|
if (listLen <= 2)
|
|
{ //圆分解为两段弧
|
|
TGGeCurveSegment segCir;
|
|
segCir = TGGeCircle(center, ads_distance(center, pts[0]));
|
|
segCir.AsPoly2D(poly);
|
|
}
|
|
else
|
|
{
|
|
//圆分解为多段弧
|
|
for (int i = 1; i < listLen; i++)
|
|
{
|
|
TADSGePoint3d pt2;
|
|
if (i == listLen-1) pt2 = pts[1];
|
|
else pt2 = pts[i+1];
|
|
TGGeArc arcSeg(center, ads_distance(center, pts[i]), ads_angle(center, pts[i]), ads_angle(center, pt2));
|
|
poly.AppendNode(pts[i], arcSeg.Bulge());
|
|
}
|
|
}
|
|
poly.SetFlag(1);
|
|
}
|
|
else
|
|
{
|
|
for (int j = 0; j<listLen-1; j++)
|
|
{ // arc and line
|
|
const TADSGePoint3d &pt1 = pts[j];
|
|
const TADSGePoint3d &pt2 = pts[j+1];
|
|
if (curveType == CURVE_LINE)
|
|
{
|
|
poly.AppendNode(pt1);
|
|
}
|
|
else
|
|
{
|
|
TGGeArc arcSeg(center, ads_distance(center, pt1), ads_angle(center,pt1), ads_angle(center, pt2));
|
|
poly.AppendNode(pt1, arcSeg.Bulge());
|
|
}
|
|
if (j == listLen - 2)
|
|
{
|
|
poly.AppendNode(pt2);
|
|
poly.SetFlag(0);
|
|
}
|
|
}
|
|
}
|
|
} |