TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
- void cmdTestOffsetSpline()
- {
- ads_point pt;
- ads_name ename;
- if (acedEntSel(NULL, ename, pt) != RTNORM)
- return;
- AcDbObjectId id;
- acdbGetObjectId(id, ename);
- AcDbEntityPointer pent(id, AcDb::kForRead);
- pent.openStatus();
- AcDbCurve* psp = AcDbCurve::cast(pent);
- if (psp == NULL) return;
- AcGeCurve3d* pGeCurve = NULL;
- Acad::ErrorStatus es = psp->getAcGeCurve(pGeCurve); //TB check ErrorStatus!
- pent->close();
- if (es || !pGeCurve) { //TB check ErrorStatus!
- acutPrintf(L"\ngetAcGeCurve(crv)=%s, crv=%x", acadErrorStatusText(es), pGeCurve);
- return;
- }
- double offsetdist = 100.0;
- AcGeVoidPointerArray arr;
- pGeCurve->getTrimmedOffset(offsetdist, AcGeVector3d::kZAxis, arr, AcGe::kExtend);
- delete pGeCurve;
- pGeCurve = NULL;
- AcAxDocLock lock;
- for (int i = 0; i < arr.length(); ++i) {
- AcGeCurve3d* pCurve = (AcGeCurve3d*)arr.at(i);
- if (!pCurve)
- continue;
- AcGe::EntityId type = pCurve->type();
- AcDbCurve* pNewcurve = NULL;
- es = AcDbCurve::createFromAcGeCurve(*pCurve, pNewcurve);
- if (!es) //TB check es! eInvalidInput is returned for splines!
- delete pCurve;
- else {
- if (type == AcGe::kCompositeCrv3d) {
- AcGeNurbCurve3d* pFinalNurb = NULL;
- AcGePoint3d ptNurbEnd, ptEnd, ptStart;
- AcGeCompositeCurve3d *ccrv = (AcGeCompositeCurve3d*)pCurve;
- AcGeVoidPointerArray curveList;
- ccrv->getCurveList(curveList);
- for (void* vp : curveList)
- {
- AcGeNurbCurve3d *pNurb = NULL, *pTmpNurb = NULL;
- AcGeCurve3d* crv = (AcGeCurve3d*)vp;
- type = crv->type();
- if (type != AcGe::kNurbCurve3d) {
- double epsilon = AcGeContext::gTol.equalPoint();
- pTmpNurb = pNurb = new AcGeNurbCurve3d(*crv, epsilon);
- }
- else
- pNurb = (AcGeNurbCurve3d*)crv;
- if (!pFinalNurb) {
- pFinalNurb = pNurb;
- if (!pTmpNurb)
- crv = NULL; // don't delete crv!
- }
- else {
- if (pNurb->hasStartPoint(ptStart) && (ptStart==ptNurbEnd)) {
- pFinalNurb->joinWith(*pNurb);
- if (pFinalNurb->hasEndPoint(ptEnd))
- ptNurbEnd = ptEnd;
- }
- }
- if (pFinalNurb->hasEndPoint(ptEnd))
- ptNurbEnd = ptEnd;
- if (crv)
- delete crv;
- }
- if (pFinalNurb) {
- AcDbCurve* segment=NULL;
- es = AcDbCurve::createFromAcGeCurve(*pFinalNurb, pNewcurve);
- delete pFinalNurb;
- }
- }
- }
- if (pNewcurve) {
- AcDbDatabase* pdb = acdbHostApplicationServices()->workingDatabase();
- pNewcurve->setDatabaseDefaults(pdb);
- pNewcurve->setColorIndex(1); {
- // append to database
- AcDbObjectId curid = pdb->currentSpaceId();
- AcDbBlockTableRecordPointer pbtr(curid, AcDb::kForWrite);
- pbtr.openStatus();
- AcDbObjectId newid;
- pbtr->appendAcDbEntity(newid, pNewcurve);
- }
- pNewcurve->close();
- }
- }
- }
复制代码 |
|