- 积分
- 36673
- 明经币
- 个
- 注册时间
- 2010-7-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-12-21 01:33:18
|
显示全部楼层
本帖最后由 highflybird 于 2011-12-21 01:36 编辑
- //选择物体
- int ret;
- ads_point pt,pt1,pt2;
- ads_name ename;
- ret = acedEntSel(_T("\n请选择曲线类物体:"),ename,pt);
- if (RTNORM != ret)
- {
- acutPrintf(_T("\n选择无效,程序返回。"));
- return;
- }
- //判断是否曲线类物体
- Acad:;ErrorStatus es;
- AcDbEntity *pEnt = NULL;
- AcDbObjectId id;
- es = acdbGetObjectId(id,ename);
- es = acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead);
- if (es != Acad::eOk)
- {
- return;
- }
- if (!pEnt->isKindOf(AcDbCurve::desc()))
- {
- pEnt->close();
- acutPrintf(_T("\n选择物体不是曲线,程序返回。"));
- return ;
- }
- //输入偏移方向
- double offDist;
- ret = acedGetPoint(NULL,_T("\n点取偏移方向:"),pt1);
- if (RTNORM != ret)
- {
- acutPrintf(_T("\n点取无效,程序返回。"));
- return;
- }
- //输入偏移距离
- ret = acedGetDist(pt1,_T("\n偏移距离:"),&offDist);
- if (RTNORM != ret)
- {
- acutPrintf(_T("\n输入距离无效,程序返回。"));
- return;
- }
- //此段用语判断偏移的方向
- AcDbCurve * pCurve = (AcDbCurve *)(pEnt);
- AcDbVoidPtrArray Curves;
- AcGePoint3d pt3d1 = asPnt3d(pt1);
- AcGePoint3d pt3d2,pt3d3;
- AcGeVector3d vec,vec1;
- AcGeVector3d nrm;
- es = pCurve->getClosestPointTo(pt3d1,pt3d2);
- es = pCurve->getFirstDeriv(pt3d2,vec);
- pt3d3 = pt3d2 + vec;
- vec1 = pt3d1 -pt3d2;
- double area = vec.y * vec1.x - vec.x * vec1.y ;
- //如果是直线或者射线之类的物体,偏移距离需要反号
- if (pCurve->isKindOf(AcDbLine::desc()) || pCurve->isKindOf(AcDbXline::desc()) || pCurve->isKindOf(AcDbRay::desc()))
- {
- offDist = - offDist;
- }
- //如果是顺时针旋转,则偏移距离需要反号
- if (area > 0)
- {
- es = pCurve->getOffsetCurves(offDist,Curves);
- }
- else
- {
- es = pCurve->getOffsetCurves(-offDist,Curves);
- }
- pCurve->close();
- //现在已经得到偏移的曲线集了,剩下的的工作是添加到空间中去。
- pEnt = NULL;
- AcDbBlockTable *pBlockTable;
- acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
- AcDbBlockTableRecord *brec;
- resbuf tilemode;
- acedGetVar(_T("TILEMODE"),&tilemode);
- int tile = tilemode.resval.rint;
- if (tile == 1)
- pBlockTable->getAt(ACDB_MODEL_SPACE, brec,AcDb::kForWrite);
- else
- pBlockTable->getAt(ACDB_PAPER_SPACE, brec,AcDb::kForWrite);
- pBlockTable->close();
- AcDbObjectId entid;
- for (int i = 0;i< Curves.length();i++)
- {
- pEnt =(AcDbEntity *) Curves[ i ] ;
- brec->appendAcDbEntity(entid, pEnt);
- pEnt->close();
- }
- brec->close();
- acutPrintf(_T("\n偏移成功!"));
|
|