|
- static void AsdkConvertPolylineArc2Arc(void)
- {
- ads采用name ename;
- ads采用point pt;
- int retval;
- retval = acedEntSel(L"\nPick a LW polyline:", ename, pt);
- if(retval != RTNORM)
- return;
- AcDbPolyline *pPoly;
- AcDbObjectId id;
- Acad::ErrorStatus es;
- acdbGetObjectId(id, ename);
- es = acdbOpenObject((AcDbObject*&)pPoly, id, AcDb::kForRead);
- if (es != Acad::eOk)
- {
- acutPrintf(L"\nERROR: %s", acadErrorStatusText(es));
- return;
- }
- if (pPoly->isA() != AcDbPolyline::desc())
- {
- acutPrintf(L"\nLW polyline not selected.");
- pPoly->close();
- return;
- }
- for (unsigned int i=0; i<pPoly->numVerts()-1; i++)
- {
- double bulge;
- pPoly->getBulgeAt(i, bulge);
- if (bulge == 0.0) // line segment
- continue;
- AcGePoint2d startPt, endPt, centerPt, testPt;
- pPoly->getPointAt(i, startPt);
- pPoly->getPointAt(i+1, endPt);
- AcGeCircArc2d geArc;
- // easy AcDbPolyline method for creating an AcGeCircArc2d
- pPoly->getArcSegAt(i, geArc);
- double start = acutAngle(
- asDblArray(geArc.center()),
- asDblArray(startPt)
- );
- double end = acutAngle(
- asDblArray(geArc.center()),
- asDblArray(endPt)
- );
- AcGePoint3d center = AcGePoint3d(
- geArc.center().x,
- geArc.center().y,
- pPoly->elevation()
- );
- // if this polyline does not lie in WCS, get its ECS
- // and tranform the center point back to WCS
- if (pPoly->normal() != AcGeVector3d(0,0,1))
- {
- AcGeMatrix3d mat;
- pPoly->getEcs(mat);
- center = center.transformBy(mat);
- }
- AcDbArc* pArc;
- // Check the direction of the arc. If it's clockwise
- // (opposite the AutoCAD default)
- // reverse the start and end points for the AcDbArc.
- if (geArc.isClockWise())
- {
- pArc = new AcDbArc(
- center,
- pPoly->normal(),
- geArc.radius(),
- end,
- start
- );
- }
- else
- {
- pArc = new AcDbArc(
- center,
- pPoly->normal(),
- geArc.radius(),
- start,
- end
- );
- }
- AcCmColor yellow;
- yellow.setColorIndex(2);
- pArc->setColor(yellow);
- //set entity properties such as layer, linetype, color
- // User defined function to add entity to Model Space
- // ...
- postToModelSpace(pArc);
- pArc->close();
- }
- pPoly->close();
- }
- static void postToModelSpace(AcDbEntity* pEntity)
- {
- AcDbBlockTable *pBlockTable;
- AcDbBlockTableRecord *pSpaceRecord;
- AcDbDatabase *pDb
- = acdbHostApplicationServices()->workingDatabase();
- pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
- pBlockTable->getAt
- (
- ACDB采用MODEL采用SPACE,
- pSpaceRecord,
- AcDb::kForWrite
- );
- pSpaceRecord->appendAcDbEntity(pEntity);
- pBlockTable->close();
- pEntity->close();
- pSpaceRecord->close();
- }
复制代码 |
|