偏移曲线代码
C++开发|大少爷|2017-07-27 16:43
-
回答:
void CTestCommands::OffsetPolyline() { ads_name entName; ads_point pt; if(acedEntSel(_T("需要偏移的PL线:"),entName,pt) != RTNORM) { return; } AcDbObjectId objId; if(acdbGetObjectId(objId,entName) != Acad::eOk) return; McDbObjectPointer<McDbPolyline> spPolyline(objId,AcDb::kForRead); if(spPolyline.openStatus() != Acad::eOk) { acutPrintf(_T("n 请选择Polyline")); return; } ads_point tmpPt1; if(acedGetPoint(NULL,_T("n 点取偏移点:"),tmpPt1) != RTNORM) { return; } ads_point tmpPt2; if(acedGetPoint(tmpPt1,_T("n 点取偏移距离:"),tmpPt2) != RTNORM) { return; } McGePoint3d pt1 = asPnt3d(tmpPt1); McGePoint3d pt2 = asPnt3d(tmpPt2); double dDis = pt1.distanceTo(pt2); if(fabs(dDis) < 0.01) { acutPrintf(_T("n 偏移距离为太小")); return; } McGePoint3d ptRef = pt1; McDbVoidPtrArray offsetCurves; if(spPolyline->getOffsetCurvesEx(dDis,offsetCurves,ptRef) != Mcad::eOk) { acutPrintf(_T("n 未知原因,偏移失败")); return; } // 对偏移后的PL线,按偏移距离,把突出的角导圆角。 McGePoint3d startPt; spPolyline->getStartPoint(startPt); for(int i = 0 ; i < offsetCurves.length();i++) { McDbEntity* pEnt = (McDbEntity*)(offsetCurves[i]); ASSERT(pEnt != NULL); if(McDbPolyline::cast(pEnt) != NULL) { McDbPolyline* pNewPolyline = GetNewPolyline(startPt,McDbPolyline::cast(pEnt),dDis ); if(pNewPolyline != NULL) { MrxDbgUtils::addToCurrentSpace(pNewPolyline); pNewPolyline->close(); delete pEnt; pEnt = NULL; } } if(pEnt != NULL) { MrxDbgUtils::addToCurrentSpaceAndClose(pEnt); } } }