#include "StdAfx.h" #include "SortedVertexList.h" #include "GePoly2D.h" SortedVertexList::SortedVertexList(const ADSGePoint3d & ptStart, const ADSGePoint3d & ptEnd, ads_real dBulge) : PointList(ptStart, ptEnd, dBulge) { } SortedVertexList::SortedVertexList(const GeCurveSegment &curve) : PointList(curve.GetStartPoint(), curve.GetEndPoint(), curve.GetBulge()) { } SortedVertexList::~SortedVertexList() { } void SortedVertexList::InsertBeforeLast(const ADSGePoint3d &ptSrc) { (*this)[Length() - 1]; ADSGePointList::Insert(new ADSGePoint3d(ptSrc)); } int SortedVertexList::AsPoly2D(GePoly2D &poly) { PointList &pts = *this; if (!pts) { return RTERROR; } poly.Reset(); int nListLen = Length(); if (curveType == CURVE_CIRCLE) { if (nListLen <= 2) // 只处理园,不处理圆弧 { ADSGePoint3d sPt = *pts[0]; GeCurveSegment cv; cv = GeCircle(center, ads_distance(center, sPt)); cv.AsPoly2D(poly); return RTNORM; } // pts[0]留作半径计算 for (int i = 1; i < nListLen; i++) { ADSGePoint3d pt2; if (i == nListLen - 1) { pt2 = *pts[1]; } else { pt2 = *pts[i + 1]; } GeArc arcSeg(center, ads_distance(center, *pts[i]), ads_angle(center, *pts[i]), ads_angle(center, pt2)); GeCurveSegment cv; cv = arcSeg; poly.Append(new ADSGePoint3d(cv.GetStartPoint())); poly.AppendBugle(cv.GetBulge()); if (i == nListLen - 1) { poly.Append(new ADSGePoint3d(cv.GetEndPoint())); poly.AppendBugle(0.0); } } } else { // 弧或线 for (int j = 0; j < nListLen - 1; j++) { ADSGePoint3d &pt1 = *pts[j]; ADSGePoint3d &pt2 = *pts[j + 1]; GeCurveSegment cv; if (curveType == CURVE_LINE) { GeLine lineSeg(pt1, pt2); cv = lineSeg; } else { GeArc arcSeg(center, ads_distance(center, pt1), ads_angle(center,pt1), ads_angle(center, pt2)); cv = arcSeg; } poly.Append(new ADSGePoint3d(cv.GetStartPoint())); poly.AppendBugle(cv.GetBulge()); if (j == nListLen - 2) { poly.Append(new ADSGePoint3d(cv.GetEndPoint())); poly.AppendBugle(0.0); } } } return RTNORM; }