//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : PointList 类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: PointList 定义 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #include "StdAfx.h" #include "PointList.h" #include "XGlobalFunc.h" #include "XPrivateGlobalFunc.h" #include "XGlobalCurveFunc.h" #include "XCurveInline.h" PointList::PointList(const XPoint & startPoint, const XPoint & 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 XPoint (startPoint)); center = startPoint + endPoint; center.Scale(0.5); return; } else { center = XArc(startPoint, endPoint, bulge).GetCenterPt(); curveType = CURVE_ARC; } } else curveType = CURVE_LINE; Append(new XPoint (startPoint)); Append(new XPoint (endPoint)); } PointList::~PointList() { } // Status: Insert point must between 0~max int PointList::Insert(const XPoint & pt, BOOL bExt) { if (curveType == CURVE_CIRCLE) { if ((pt & XCircle(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 (CT_std_angle(drt - curDrt) < _angSnap) { return RTERROR; } if (curDrt < drt) { DList::Insert(new XPoint(pt)); return RTNORM; } } Append(new XPoint(pt)); return RTNORM; } return RTERROR; } // arc and line int listLen = Length(); PointList &segPoints = *this; for (int j = 0; j < listLen-1; j++) { XPoint &pt1 = *segPoints[j]; XPoint &pt2 = *segPoints[j+1]; if (curveType == CURVE_LINE) { XLine lineSeg(pt1, pt2, LS_FINITE); if ((pt & lineSeg) == PR_INSIDE) { DList::Insert(new XPoint (pt)); return RTNORM; } } else { XArc arcSeg(center, ads_distance(center, pt1), ads_angle(center,pt1), ads_angle(center, pt2)); if ((pt & arcSeg) == PR_INSIDE) { DList::Insert(new XPoint (pt)); return RTNORM; } } } if (bExt) { ASSERT(listLen >= 2); if (curveType == CURVE_LINE) { XLine lineSeg(*Head(), *Tail()); if ((pt & lineSeg) == PR_EXTEND) { if (pt.Distance2d(*Head()) < pt.Distance2d(*Tail())) { (*this)[0]; DList::Insert(new XPoint(pt)); } else { DList::Append(new XPoint(pt)); } } } else { XArc 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]; DList::Insert(new XPoint(pt)); } else { DList::Append(new XPoint(pt)); } } } } return RTERROR; } int PointList::Update(const ads_name ref) { Entity entRef = ref; //entRef.GetGroups(); int listLen = Length(); PointList &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++) { XPoint pt2; if (i == listLen - 1) { pt2 = *pts[1]; } else { pt2 = *pts[i+1]; } XArc 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