//-------------------------------------------------------------------------------------------------------+ // 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::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::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::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::Insert(new TADSGePoint3d(pt)); } else { TDPtrList::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::Insert(new TADSGePoint3d(pt)); } else { TDPtrList::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