- UID
- 675164
- 积分
- 224
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-4-19
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2016-7-15 13:30:27
|
显示全部楼层
算HATCH周长的ARX代码
 - // Perimeter calculation of a hatch using ObjectARX
- static void ADS_HatchTest(void)
- {
- ads_name en;
- ads_point pt;
- if( acedEntSel(
- ACRX_T("\nSelect a hatch :"),
- en,
- pt
- ) != RTNORM )
- {
- return;
- }
-
- AcDbObjectId entId = AcDbObjectId::kNull;
- Acad::ErrorStatus es;
- es = acdbGetObjectId(entId, en);
- if(es != Acad::eOk)
- return;
-
- HatchPerimeter(entId);
- }
-
- static void HatchPerimeter(AcDbObjectId entId)
- {
- Acad::ErrorStatus es;
- AcDbEntity *pEnt;
- es = acdbOpenAcDbEntity(
- pEnt,
- entId,
- AcDb::kForRead
- );
- if( es != Acad::eOk )
- return;
-
- if( pEnt->isA() != AcDbHatch::desc() )
- {
- acutPrintf(ACRX_T("\n Please select a hatch."));
- pEnt->close();
- return;
- }
-
- AcDbHatch* pHatch = AcDbHatch::cast(pEnt);
-
- int nLoops = pHatch->numLoops();
- double totalExternalPerimeter =0.0;
- double totalInternalPerimeter =0.0;
-
- for(int i=0; i < nLoops; i++)
- {
- double loopLength = 0.0;
- long loopType;
-
- if( pHatch->loopTypeAt( i )
- & AcDbHatch::kPolyline )
- {
- AcGePoint2dArray vertices;
- AcGeDoubleArray bulges;
- pHatch->getLoopAt(
- i,
- loopType,
- vertices,
- bulges
- );
- int nVertices = vertices.length();
-
- AcDbPolyline testPoly(nVertices);
-
- for( int vx=0; vx < nVertices; vx++)
- {
- double bulge = 0.0;
- if(bulges.length() < nVertices)
- bulge = 0.0;
- else
- bulge = bulges[vx];
- testPoly.addVertexAt(
- vx,
- vertices[vx],
- bulge
- );
- }
-
- AcGeLineSeg3d ls;
- AcGeCircArc3d as;
- double d = 0.0, p1 = 0.0, p2 = 1.0;
-
- for(int ver = 0; ver < nVertices; ver++)
- {
- es = testPoly.getBulgeAt( i, d );
- if( es != Acad::eOk )
- break;
-
- if( d <= 1e-5 )
- {
- es = testPoly.getLineSegAt(ver, ls);
- if( es != Acad::eOk )
- break;
- loopLength += ls.length();
- }
- else
- {
- AcGePoint2d v1;
- AcGePoint2d v2;
- v1.set(
- vertices[ver].x,
- vertices[ver].y
- );
-
- if (ver == (nVertices - 1))
- {
- v2.set(
- vertices[0].x,
- vertices[0].y
- );
- }
- else
- {
- v2.set(
- vertices[ver+1].x,
- vertices[ver+1].y
- );
- }
-
- if (v1.isEqualTo(v2, AcGeContext::gTol)
- == Adesk::kFalse)
- {
- es = testPoly.getArcSegAt( i, as );
- if( es != Acad::eOk )
- break;
-
- p1 = as.paramOf(as.startPoint());
- p2 = as.paramOf(as.endPoint());
-
- loopLength += as.length( p1, p2 );
- }
- }
- }
- }
- else
- {
- AcGePoint2dArray vertices;
- AcGeDoubleArray bulges;
- AcGeVoidPointerArray edgePtrs;
- AcGeIntArray edgeTypes;
-
- pHatch->getLoopAt(i, loopType,edgePtrs, edgeTypes );
- AcGeCompositeCurve2d compCurve( edgePtrs );
-
- AcGeInterval interval;
- compCurve.getInterval( interval );
-
- loopLength
- = compCurve.length(
- interval.lowerBound(),
- interval.upperBound()
- );
- }
-
- if( nLoops > 1 && !(loopType & AcDbHatch::kExternal ))
- totalInternalPerimeter += loopLength;
- else
- totalExternalPerimeter += loopLength;
- }
-
- acutPrintf(
- ACRX_T("\nExternal Perimeter : %lf"),
- totalExternalPerimeter
- );
-
- acutPrintf(
- ACRX_T("\nInternal Perimeter : %lf"),
- totalInternalPerimeter
- );
-
- pEnt->close();
- }
-
|
|